ComfyUI Workflows — Agent Usage Guide
⚠️ READ-ONLY WARNING: The scripts in this skill (comfy_run.py, comfy_api.py) are
production-validated and must not be modified. They handle 33+ workflow JSONs with complex LiteGraph→API
conversion, subgraph expansion, bypass resolution, and multi-format output downloading. Any modification risks
breaking all workflows. Only read and use the scripts — never edit them.
Requirements
Before using this skill, ensure your environment meets these requirements:
| Requirement | Details |
|---|
| Python | 3.10 or higher |
| pip packages |
websocket-client,
requests |
|
ComfyUI server | Must be running before executing workflows |
|
Token | Required if ComfyUI has authentication enabled |
Install Python dependencies:
CODEBLOCK0
Configuration Options
| Variable | Description | Default |
|---|
| INLINECODE4 | ComfyUI server address | INLINECODE5 |
| INLINECODE6 |
Additional workflow directories | (none) |
Credentials
| Credential | Required | Source |
|---|
| ComfyUI Token | Only if auth enabled | ComfyUI settings page |
Personal Configuration Required
Before using this skill, ensure these items are configured for your environment:
| Item | Description | Where to Configure |
|---|
| INLINECODE7 | Your ComfyUI server address | INLINECODE8 or COMFY_HOST env |
| ComfyUI server |
Must be running before executing workflows | Start manually |
| Model paths | Your local model directories |
MODELS_INVENTORY.md (for reference) |
| Token | ComfyUI authentication token | Get from ComfyUI settings |
| Workflow files | Your own workflow JSON files |
workflows/ directory (see note below) |
Quick Setup
1. Start ComfyUI
Start your ComfyUI server manually before executing any workflows. The skill expects ComfyUI to be running at the configured host.
2. Configure Connection
Create scripts/config.json:
CODEBLOCK1
Or set environment variables:
CODEBLOCK2
3. Install Dependencies
CODEBLOCK3
4. Add Your Workflows
Place workflow JSON files in workflows/ directory, organized by category:
CODEBLOCK4
Shell Variables (use in all commands)
CODEBLOCK5
End-to-End Workflow (Steps 0–5)
Step 0 — Ensure ComfyUI Is Running
Start ComfyUI manually. Verify it's accessible at http://127.0.0.1:8188.
Step 1 — List Available Workflows
CODEBLOCK6
Step 2 — Inspect the Workflow
CODEBLOCK7
Step 3 — Prepare Inputs
CODEBLOCK8
Step 4 — Execute
CODEBLOCK9
Step 5 — Collect Outputs
Outputs are saved to the -o directory with auto-generated prefixes.
CLI Reference
CODEBLOCK10
Troubleshooting
| Problem | Fix |
|---|
| INLINECODE16 | Use --list to see available workflows |
| INLINECODE18 |
Run
--inspect to check required inputs |
|
Cannot reach ComfyUI | Ensure ComfyUI is running at configured host |
|
Image file not found | Use absolute paths, verify with
ls -la |
| GPU out of memory | Reduce resolution or steps |
Knowledge Cache Pattern
INLINECODE23 and WORKFLOWS_SUMMARY.md serve as the agent's persistent knowledge base for the user's actual ComfyUI setup. Use them to cache learned information across sessions:
⚠️ DO NOT REFERENCE THE EXAMPLE CONTENT: The default content in these files describes sanitized example workflows that will NOT work. Agents MUST update them with the user's actual data before relying on them. Using outdated example data will cause workflow failures.
Initial Setup (First Time)
When the user first provides their own workflow files:
- 1. Clean the example content — Remove the sanitized example entries from both files
- Populate with user's data — Run
--inspect on each workflow, document findings in INLINECODE26 - Inventory models — Scan user's model directories, update
MODELS_INVENTORY.md with their actual models
Ongoing Maintenance
- - After using a new workflow → Add its documentation to INLINECODE28
- After downloading models → Update
MODELS_INVENTORY.md status - When learning model-specific quirks → Document tips/tricks in the relevant section
Session Workflow
CODEBLOCK11
This pattern lets the agent skip repeated discovery and work efficiently with cached knowledge.
Reference Documents
| Document | Purpose |
|---|
| INLINECODE30 | Knowledge cache — user's installed models, status, paths |
| INLINECODE31 |
Knowledge cache — workflow capabilities, settings, tips |
|
references/prompting-guide.md | Prompt anatomy, model-specific strategies |
|
references/maintenance.md | Code structure, debugging |
|
references/architecture.md | Design principles |
ComfyUI 工作流 — 代理使用指南
⚠️ 只读警告:此技能中的脚本(comfyrun.py、comfyapi.py)已通过生产验证,严禁修改。它们处理 33 个以上的工作流 JSON,涉及复杂的 LiteGraph→API 转换、子图扩展、旁路解析和多格式输出下载。任何修改都可能导致所有工作流失效。仅可读取和使用这些脚本 — 切勿编辑。
环境要求
使用此技能前,请确保环境满足以下要求:
| 要求 | 详情 |
|---|
| Python | 3.10 或更高版本 |
| pip 包 |
websocket-client、requests |
|
ComfyUI 服务器 | 执行工作流前必须已启动 |
|
令牌 | 如果 ComfyUI 启用了身份验证则需要 |
安装 Python 依赖:
bash
pip install websocket-client requests
配置选项
| 变量 | 描述 | 默认值 |
|---|
| COMFYHOST | ComfyUI 服务器地址 | 127.0.0.1:8188 |
| COMFYWORKFLOW_DIRS |
额外工作流目录 | (无) |
凭据
| 凭据 | 是否必需 | 来源 |
|---|
| ComfyUI 令牌 | 仅启用身份验证时需要 | ComfyUI 设置页面 |
需要个人配置
使用此技能前,请确保已为您的环境配置以下项目:
| 项目 | 描述 | 配置位置 |
|---|
| comfyhost | 您的 ComfyUI 服务器地址 | scripts/config.json 或 COMFYHOST 环境变量 |
| ComfyUI 服务器 |
执行工作流前必须已启动 | 手动启动 |
| 模型路径 | 您的本地模型目录 | MODELS_INVENTORY.md(供参考) |
| 令牌 | ComfyUI 身份验证令牌 | 从 ComfyUI 设置获取 |
| 工作流文件 | 您自己的工作流 JSON 文件 | workflows/ 目录(见下方说明) |
快速设置
1. 启动 ComfyUI
在执行任何工作流之前,请手动启动您的 ComfyUI 服务器。此技能期望 ComfyUI 在配置的主机上运行。
2. 配置连接
创建 scripts/config.json:
json
{
comfy_host: 127.0.0.1:8188,
workflow_dirs: []
}
或设置环境变量:
bash
export COMFY_HOST=127.0.0.1:8188
3. 安装依赖
bash
pip install websocket-client requests
4. 添加工作流
将工作流 JSON 文件放入 workflows/ 目录,按类别组织:
workflows/
├── 图像-文本/
│ ├── workflow1.json
│ └── workflow2.json
├── 图像-编辑/
│ └── ...
└── 视频/
└── ...
Shell 变量(用于所有命令)
bash
VENV=python3 # 或您的虚拟环境路径
SCRIPT=/path/to/comfyui-workflow-skill/scripts/comfy_run.py
端到端工作流(步骤 0–5)
步骤 0 — 确保 ComfyUI 正在运行
手动启动 ComfyUI。验证可通过 http://127.0.0.1:8188 访问。
步骤 1 — 列出可用工作流
bash
$VENV $SCRIPT --list
步骤 2 — 检查工作流
bash
$VENV $SCRIPT -w workflow_name --inspect
步骤 3 — 准备输入
bash
--prompt 您的提示词 # 文本提示词
--image /path/to/image.jpg # 图像输入
--audio /path/to/audio.wav # 音频输入
--video /path/to/video.mp4 # 视频输入
--width 1024 --height 1024 # 分辨率
--steps 50 --cfg 4.0 --seed 42 # 采样器设置
--override {node_id: {key: value}} # 高级覆盖
步骤 4 — 执行
bash
$VENV $SCRIPT -w workflow_name --prompt ... -o /tmp
步骤 5 — 收集输出
输出保存到 -o 目录,带有自动生成的前缀。
CLI 参考
用法: comfy_run.py [-w WORKFLOW] [选项]
模式:
--list 列出所有可用工作流
--inspect 人类可读的输入/输出检查
--inspect-json 机器可读的 JSON 检查
--dry-run 打印 API JSON 但不执行
--queue 提交到队列并立即返回
--status [IDs...] 检查队列状态
输入自定义:
--prompt, -p TEXT 正向提示词
--negative, -n TEXT 负向提示词
--image, -i PATH [...] 输入图像
--audio, -a PATH [...] 输入音频文件
--video, -v PATH [...] 输入视频文件
生成设置:
--width, -W INT 输出宽度
--height, -H INT 输出高度
--steps INT 采样步数
--cfg FLOAT CFG 尺度
--seed INT 随机种子
高级:
--override JSON 节点输入覆盖
--config PATH YAML/JSON 配置文件
--server HOST:PORT ComfyUI 服务器
--output-dir, -o PATH 输出目录
--output-prefix TEXT 输出文件名前缀
--no-ensure 跳过自动启动 ComfyUI
--no-validate 跳过输入验证
故障排除
| 问题 | 解决方法 |
|---|
| 工作流未找到 | 使用 --list 查看可用工作流 |
| 未生成输出 |
运行 --inspect 检查所需输入 |
| 无法连接 ComfyUI | 确保 ComfyUI 在配置的主机上运行 |
| 图像文件未找到 | 使用绝对路径,用 ls -la 验证 |
| GPU 内存不足 | 降低分辨率或步数 |
知识缓存模式
MODELSINVENTORY.md 和 WORKFLOWSSUMMARY.md 作为代理关于用户实际 ComfyUI 设置的持久知识库。使用它们在会话间缓存已学习的信息:
⚠️ 请勿引用示例内容:这些文件中的默认内容描述的是经过清理的示例工作流,这些工作流将无法使用。代理必须在使用前用用户的实际数据更新它们。使用过时的示例数据将导致工作流失败。
初始设置(首次使用)
当用户首次提供自己的工作流文件时:
- 1. 清理示例内容 — 从两个文件中删除经过清理的示例条目
- 填充用户数据 — 对每个工作流运行 --inspect,将发现记录到 WORKFLOWSSUMMARY.md
- 盘点模型 — 扫描用户的模型目录,用实际模型更新 MODELSINVENTORY.md
持续维护
- - 使用新工作流后 → 将其文档添加到 WORKFLOWSSUMMARY.md
- 下载模型后 → 更新 MODELSINVENTORY.md 状态
- 了解模型特定特性时 → 在相关部分记录技巧/窍门
会话工作流
- 1. 读取 MODELSINVENTORY.md → 了解可用模型
- 读取 WORKFLOWSSUMMARY.md → 了解工作流能力
- 选择合适的工作流,无需重新检查
- 如果发现新工作流 → 记录以供后续会话使用
此模式让代理跳过重复的发现过程,利用缓存的知识高效工作。
参考文档
| 文档 | 用途 |
|---|
| MODELSINVENTORY.md | 知识缓存 — 用户已安装的模型、状态、路径 |
| WORKFLOWSSUMMARY.md |
知识缓存 — 工作流能力、设置、技巧 |
| references/prompting-guide.md | 提示词结构、模型特定策略 |
| references/maintenance.md | 代码结构、调试 |
| references/architecture.md | 设计原则 |