ComfyGPT: A Self-Optimizing Multi-Agent System for Comprehensive ComfyUI Workflow Generation

Oucheng Huang, Yuhang Ma, Zeng Zhao, Mingrui Wu, Jiayi Ji, Rongsheng Zhang, Zhipeng Hu, Xiaoshuai Sun, Rongrong JiarXiv 2025 · DOI

Abstract

ComfyUI has emerged as a premier modular platform for advanced generative AI pipelines, yet its steep learning curve and the technical complexity of its node-based interface limit accessibility. We introduce ComfyGPT, a multi-agent framework designed to automate the generation of ComfyUI workflows from natural language instructions. ComfyGPT addresses the limitations of standard Large Language Models (LLMs)—such as context window constraints and node hallucinations—by abstracting workflows into simplified logic diagrams and utilizing a self-optimizing reinforcement learning loop. Our system achieves an 86.0% pass accuracy on the comprehensive FlowBench benchmark, significantly outperforming existing state-of-the-art methods.

Introduction

The landscape of generative AI has shifted toward modularity, with ComfyUI providing a powerful visual interface for chaining models like Stable Diffusion, ControlNet, and IP-Adapter. However, creating these workflows requires deep technical knowledge of node inputs, outputs, and compatibility. For an LLM, generating these workflows is challenging because they are stored as verbose, high-dimensional JSON files that exceed context limits. Furthermore, the rapid evolution of the open-source node ecosystem leads to frequent hallucinations where models propose non-existent or deprecated nodes.

ComfyGPT translates high-level instructions into complex generative workflows such as virtual try-on, inpainting, and style transfer.

The ComfyGPT Framework

To bridge the gap between human intent and executable code, ComfyGPT employs a specialized multi-agent architecture that decomposes the generation process into four distinct stages:

  1. ReformatAgent: This agent addresses the "JSON bloat" problem by translating raw ComfyUI JSON files into a streamlined "logic diagram" format. By focusing exclusively on node types and their interconnections, it reduces the token count significantly, allowing the system to handle complex topologies within standard LLM context windows.
  2. FlowAgent: Serving as the core reasoning engine, the FlowAgent generates the logic diagram based on the user's prompt. It is powered by Qwen2.5-14B and undergoes a two-stage training process: Supervised Fine-Tuning (SFT) followed by Group Relative Policy Optimization (GRPO).
  3. RefineAgent: To ensure the generated nodes are valid within the current ecosystem, the RefineAgent performs a Retrieval-Augmented Generation (RAG) check. It queries a database of over 6,000 verified nodes, correcting any naming discrepancies or outdated references via semantic similarity.
  4. ExecuteAgent: The final agent converts the refined logic diagram back into a standard ComfyUI JSON format and manages the execution on the server.
The ComfyGPT architecture features a multi-agent execution pipeline and a training loop optimized via GRPO and RAG to ensure node validity and execution success.

Self-Optimization via Reinforcement Learning

A key innovation in ComfyGPT is the use of GRPO (Group Relative Policy Optimization). Traditional LLMs often struggle with the strict syntax of domain-specific languages. By implementing a reward model that penalizes the generation of non-existent nodes and rewards successful execution, the FlowAgent learns to adhere strictly to the known node vocabulary. This reinforcement learning stage is critical for reducing the "hallucination rate" that plagues general-purpose models like GPT-4o when applied to ComfyUI.

Evaluation and Results

The authors introduced FlowBench, a benchmark comprising 1,000 diverse workflows across categories such as 3D generation, video synthesis, and image editing.

  • Execution Success: ComfyGPT achieved an 86.0% Pass Accuracy on FlowBench. In comparison, GPT-4o achieved only 12.4% under few-shot prompting, and previous specialized agents like ComfyAgent reached 56.0% on the smaller ComfyBench.
  • Ablation Insights: The abstraction provided by the Reformat/Execute agents contributed to a 17% increase in accuracy, highlighting that the representation of the data is as vital as the model's underlying logic.

Conclusion

ComfyGPT represents a significant step toward democratizing advanced generative AI. By combining structural abstraction, multi-agent coordination, and reinforcement learning, it transforms ComfyUI from a specialist tool into an accessible platform for natural language-driven creativity. Future work will focus on improving node diversity and integrating human-in-the-loop hyperparameter tuning to further refine artistic control.

Summary updated

BibTeX
@misc{huang2025comfygpt,
  author = {Oucheng Huang and Yuhang Ma and Zeng Zhao and Mingrui Wu and Jiayi Ji and Rongsheng Zhang and Zhipeng Hu and Xiaoshuai Sun and Rongrong Ji},
  title = {{ComfyGPT: A Self-Optimizing Multi-Agent System for Comprehensive ComfyUI Workflow Generation}},
  year = {2025},
  eprint = {2503.17671},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.17671},
}
Figure