ComfyUI Runner
Overview
Run ComfyUI workflows on the local server (default 127.0.0.1:8188) using API-format JSON and return output images.
Editing the workflow before running
The run script only takes
--workflow <path>. You must
inspect and edit the workflow JSON before running, using your best knowledge of the ComfyUI API format. Do not assume fixed node IDs,
class_type names, or
_meta.title values — the user may have updated the default workflow or supplied a custom one.
For every run (including the default workflow):
- 1. Read the workflow JSON (default:
skills/comfyui/assets/default-workflow.json, or the path/file the user gave). - Identify prompt-related nodes by inspecting the graph: look for nodes that hold the main text prompt — e.g.
PrimitiveStringMultiline, CLIPTextEncode (positive text), or any node with _meta.title or class_type suggesting "Prompt" / "positive" / "text". Update the corresponding input (e.g. inputs.value, or the text input to the encoder) to the image prompt you derived from the user (subject, style, lighting, quality). If the user didn’t ask for a custom image, you can leave the existing prompt or tweak only if needed. - Optionally identify style/prefix nodes — e.g.
StringConcatenate, or a second string input that acts as style. Set them if the user asked for a specific style or to clear a default prefix. - Optionally set a new seed — find sampler-like nodes (e.g.
KSampler, BasicGuider, or any node with a seed input) and set seed to a new random integer so each run can differ. - Write the modified workflow to a temp file (e.g.
skills/comfyui/assets/tmp-workflow.json). Use ~/ComfyUI/venv/bin/python for any inline Python; do not use bare python. - Run:
comfyui_run.py --workflow <path-to-edited-json>.
If the workflow structure is unclear or you can’t find prompt/sampler nodes, run the file as-is and only change what you can reliably identify. Same approach for arbitrary user-supplied JSON: inspect first, edit at your best knowledge, then run.
Run script (single responsibility)
CODEBLOCK0
The script only queues the workflow and polls until done. It prints JSON with prompt_id and output images. All prompt/style/seed changes are done by you in the JSON beforehand.
If the server isn’t reachable
If the run script fails with a connection error (e.g. connection refused or timeout to 127.0.0.1:8188), ComfyUI may not be installed or not running.
Check: Does ~/ComfyUI exist and contain main.py?
- - If not installed: Install ComfyUI (e.g. clone the repo, create a venv, install dependencies, then start the server). Example:
git clone https://github.com/comfyanonymous/ComfyUI.git ~/ComfyUI
cd ~/ComfyUI
python3 -m venv venv
~/ComfyUI/venv/bin/pip install -r requirements.txt
Then start the server (see below). Tell the user they may need to install model weights into
~/ComfyUI/models/ depending on the workflow.
- - If installed but not running: Start the ComfyUI server so the API is available on port 8188. Example:
~/ComfyUI/venv/bin/python ~/ComfyUI/main.py --listen 127.0.0.1
Run in the background or in a separate terminal so it keeps running. Then retry the workflow run.
Use ~ (or the user’s home) for paths so it works on their machine.
Model weights from URLs
When the user pastes or sends a
list of model weight URLs (one per line, or comma-separated), download those files into the ComfyUI installation so the workflow can use them later.
- 1. Normalize the list — one URL per line; strip empty lines and comments (lines starting with
#). - Run the download script with the ComfyUI base path (default
~/ComfyUI). The script uses pget for parallel downloads when available; if pget is not in PATH, it installs it to ~/.local/bin automatically (no sudo). If pget cannot be installed (e.g. unsupported OS/arch), it falls back to a built-in download. Use the ComfyUI venv Python so the script runs correctly:
~/ComfyUI/venv/bin/python skills/comfyui/scripts/download_weights.py --base ~/ComfyUI
Pass URLs as arguments, or pipe a file/list on stdin:
echo "https://example.com/model.safetensors" | ~/ComfyUI/venv/bin/python skills/comfyui/scripts/download_weights.py --base ~/ComfyUI
Or save the user’s list to a temp file and run:
~/ComfyUI/venv/bin/python skills/comfyui/scripts/download_weights.py --base ~/ComfyUI < /tmp/weight_urls.txt
To force the built-in download (no pget): add
--no-pget.
- 3. Subfolder: The script infers the ComfyUI models subfolder from the URL/filename (e.g.
vae, clip, loras, checkpoints, text_encoders, controlnet, upscale_models). The user can optionally specify a subfolder per line as url subfolder (e.g. https://.../model.safetensors vae). You can also pass a default with --subfolder loras so all URLs in that run go to models/loras/. - Existing files: By default the script skips URLs that already exist on disk; use
--overwrite to replace. - Paths: Files are written under
~/ComfyUI/models/<subfolder>/. Tell the user where each file was saved and that they can run the workflow once the ComfyUI server is (re)started if needed.
Supported subfolders (under ComfyUI/models/): checkpoints, clip, clip_vision, controlnet, diffusion_models, embeddings, loras, text_encoders, unet, vae, vae_approx, upscale_models, and others. Use --subfolder <name> when the auto-inference is wrong.
After run
Outputs are saved under
ComfyUI/output/. Use the
images list from the script output to locate the files (filename + subfolder).
⚠️ Always send the output to the user
After a successful ComfyUI run,
you must deliver the generated image(s) to the user. Do not reply with only the filename in text or with NO_REPLY.
- 1. Parse the script output JSON for
images (each has filename, subfolder, type). - Build the full path:
ComfyUI/output/ + subfolder + filename (e.g. ComfyUI/output/z-image_00007_.png). - Send the image to the user via the channel they're on (e.g. use the message/send tool with the image
path so the user receives the file). Include a short caption if helpful (e.g. "Here you go." or "Tokyo street scene.").
Every successful run must result in the user receiving the image. Never leave them with only a filename or no delivery.
Resources
scripts/
- -
comfyui_run.py: Queue a workflow, poll until completion, print prompt_id and images. No args — you edit the JSON before running. - INLINECODE68 : Download model weight URLs into
~/ComfyUI/models/<subfolder>/. Uses pget when available (installs to ~/.local/bin if missing); fallback to built-in download. Input: URLs as args or one per line on stdin. Options: --base, --subfolder, --overwrite, --no-pget. Infers subfolder from URL/filename when not given.
assets/
- -
default-workflow.json: Default workflow. Copy and edit (prompt, style, seed) then run with the edited path; or run as-is for a generic run.
ComfyUI 运行器
概述
使用API格式的JSON在本地服务器(默认127.0.0.1:8188)上运行ComfyUI工作流,并返回输出图像。
运行前编辑工作流
运行脚本仅接受--workflow <路径>参数。在运行前,您必须
检查并编辑工作流JSON,并充分利用您对ComfyUI API格式的了解。不要假设固定的节点ID、class
type名称或meta.title值——用户可能已更新默认工作流或提供了自定义工作流。
每次运行(包括默认工作流)时:
- 1. 读取工作流JSON(默认路径:skills/comfyui/assets/default-workflow.json,或用户提供的路径/文件)。
- 通过检查图表识别提示相关节点:查找包含主要文本提示的节点——例如PrimitiveStringMultiline、CLIPTextEncode(正向文本),或任何meta.title或classtype暗示提示/正向/文本的节点。将相应的输入(例如inputs.value或编码器的文本输入)更新为您从用户那里推导出的图像提示(主题、风格、光照、质量)。如果用户没有要求自定义图像,您可以保留现有提示,或仅在需要时进行调整。
- 可选地识别风格/前缀节点——例如StringConcatenate,或作为风格的第二个字符串输入。如果用户要求特定风格或清除默认前缀,则进行设置。
- 可选地设置新种子——找到采样器类节点(例如KSampler、BasicGuider或任何具有seed输入的节点),并将seed设置为新的随机整数,以便每次运行可以不同。
- 将修改后的工作流写入临时文件(例如skills/comfyui/assets/tmp-workflow.json)。对于任何内联Python代码,使用~/ComfyUI/venv/bin/python;不要使用裸python。
- 运行:comfyui_run.py --workflow <编辑后JSON的路径>。
如果工作流结构不清晰或无法找到提示/采样器节点,则按原样运行文件,仅更改您能可靠识别的部分。对于用户提供的任意JSON也采用相同方法:先检查,根据您的最佳知识进行编辑,然后运行。
运行脚本(单一职责)
bash
~/ComfyUI/venv/bin/python skills/comfyui/scripts/comfyui_run.py \
--workflow <工作流JSON路径>
该脚本仅将工作流加入队列并轮询直至完成。它输出包含prompt_id和输出images的JSON。所有提示/风格/种子的更改都由您事先在JSON中完成。
如果服务器无法访问
如果运行脚本因连接错误(例如连接被拒绝或超时到127.0.0.1:8188)而失败,则ComfyUI可能未安装或未运行。
检查: ~/ComfyUI是否存在并包含main.py?
- - 如果未安装: 安装ComfyUI(例如克隆仓库、创建虚拟环境、安装依赖项,然后启动服务器)。示例:
bash
git clone https://github.com/comfyanonymous/ComfyUI.git ~/ComfyUI
cd ~/ComfyUI
python3 -m venv venv
~/ComfyUI/venv/bin/pip install -r requirements.txt
然后启动服务器(见下文)。告知用户可能需要根据工作流将模型权重安装到~/ComfyUI/models/中。
- - 如果已安装但未运行: 启动ComfyUI服务器,使API在端口8188上可用。示例:
bash
~/ComfyUI/venv/bin/python ~/ComfyUI/main.py --listen 127.0.0.1
在后台或单独的终端中运行,使其保持运行。然后重试工作流运行。
使用~(或用户的主目录)作为路径,以便在其机器上正常工作。
来自URL的模型权重
当用户粘贴或发送
模型权重URL列表(每行一个,或逗号分隔)时,将这些文件下载到ComfyUI安装目录中,以便工作流后续使用。
- 1. 规范化列表——每行一个URL;去除空行和注释(以#开头的行)。
- 运行下载脚本,使用ComfyUI基础路径(默认~/ComfyUI)。该脚本在可用时使用pget进行并行下载;如果pget不在PATH中,它会自动安装到~/.local/bin(无需sudo)。如果无法安装pget(例如不支持的OS/架构),则回退到内置下载。使用ComfyUI虚拟环境的Python以确保脚本正确运行:
bash
~/ComfyUI/venv/bin/python skills/comfyui/scripts/download_weights.py --base ~/ComfyUI
将URL作为参数传递,或通过stdin传递文件/列表:
bash
echo https://example.com/model.safetensors | ~/ComfyUI/venv/bin/python skills/comfyui/scripts/download_weights.py --base ~/ComfyUI
或将用户的列表保存到临时文件并运行:
bash
~/ComfyUI/venv/bin/python skills/comfyui/scripts/downloadweights.py --base ~/ComfyUI < /tmp/weighturls.txt
要强制使用内置下载(不使用pget):添加--no-pget。
- 3. 子文件夹: 脚本从URL/文件名推断ComfyUI模型子文件夹(例如vae、clip、loras、checkpoints、textencoders、controlnet、upscalemodels)。用户可以选择每行指定子文件夹,格式为url subfolder(例如https://.../model.safetensors vae)。您也可以使用--subfolder loras传递默认子文件夹,使该次运行的所有URL都进入models/loras/。
- 现有文件: 默认情况下,脚本跳过磁盘上已存在的URL;使用--overwrite替换。
- 路径: 文件写入~/ComfyUI/models/<子文件夹>/。告知用户每个文件的保存位置,以及如果需要,可以在ComfyUI服务器(重新)启动后运行工作流。
支持的子文件夹(位于ComfyUI/models/下):checkpoints、clip、clipvision、controlnet、diffusionmodels、embeddings、loras、textencoders、unet、vae、vaeapprox、upscale_models等。当自动推断错误时,使用--subfolder <名称>。
运行后
输出保存在ComfyUI/output/下。使用脚本输出中的images列表来定位文件(文件名+子文件夹)。
⚠️ 始终将输出发送给用户
成功运行ComfyUI后,
您必须将生成的图像交付给用户。不要仅回复文本中的文件名或回复NO_REPLY。
- 1. 解析脚本输出的JSON中的images(每个包含filename、subfolder、type)。
- 构建完整路径:ComfyUI/output/ + 子文件夹 + 文件名(例如ComfyUI/output/z-image00007.png)。
- 通过用户所在的渠道将图像发送给用户(例如使用消息/发送工具,附带图像path,以便用户接收文件)。如果有助于理解,可附带简短说明(例如给您。或东京街景。)。
每次成功运行都必须让用户收到图像。切勿仅留下文件名或不交付。
资源
scripts/
- - comfyuirun.py:将工作流加入队列,轮询直至完成,输出promptid和images。无参数——您在运行前编辑JSON。
- downloadweights.py:将模型权重URL下载到~/ComfyUI/models/<子文件夹>/。在可用时使用pget(如果缺失则安装到~/.local/bin);回退到内置下载。输入:URL作为参数或每行一个通过stdin输入。选项:--base、--subfolder、--overwrite、--no-pget。未指定时从URL/文件名推断子文件夹。
assets/
- - default-workflow.json:默认工作流。复制并编辑(提示、风格、种子),然后使用编辑后的路径运行;或按原样运行进行通用运行。