TL;DR
Generating complex ComfyUI workflows using Large Language Models (LLMs) typically fails due to structural brittleness and a lack of expert design knowledge. This paper introduces a knowledge-centric framework that distills hierarchical representations from real-world workflows (knowledge inversion) and trains an agent to reason from abstract strategies down to executable node graphs, drastically improving workflow execution success rates.
What Problem Does This Paper Address?
ComfyUI has become the go-to node-based interface for complex AI image generation and editing pipelines. However, creating these workflows requires expert-level understanding of how different modules—like ControlNets, upscalers, and face detailers—interact.
Existing LLM approaches try to generate the underlying JSON graph configuration directly from text prompts. This direct text-to-JSON mapping is incredibly brittle; a single misconnected link or incorrect parameter index causes the entire workflow to crash. Furthermore, LLMs lack the "experiential knowledge" required to plan high-level strategies before worrying about JSON syntax, often falling back on rigid, oversimplified templates.
Methods
The authors propose a three-step paradigm: Invert, Inject, and Infer.
- Knowledge Inversion: To extract expert knowledge from unannotated workflows collected from the web, they use a bottom-up abstraction process. They strip raw workflows into Full Pseudo-code, abstract away parameters to create a Skeleton Pseudo-code (topology only), use an LLM to infer the Strategy Reasoning behind the layout, summarize it into a High-level Strategy, and finally deduce the original Task Instruction.
- Knowledge Injection: They use Supervised Fine-Tuning (SFT) on a Qwen3-14B model to teach it the transitions between these layers—specifically, mapping a user task to a high-level strategy, and mapping that strategy to a structured skeleton pseudo-code.
- Knowledge Inference: At runtime, the agent reverses the inversion process. A High-Level Structure Planner creates the strategy, a Pseudo-code Generator outputs the graph skeleton, a Parameter Filler adds specific configurations, and a rule-based compiler reconstructs the final ComfyUI JSON. Self-refinement loops are added to catch and fix errors iteratively.
Datasets
- Curated ComfyUI Dataset: The authors scraped over 10,000 raw ComfyUI workflows from the internet. After a multi-stage structural deduplication and filtering process (removing overly simple or excessively complex graphs), they curated a high-quality dataset of 912 workflows (882 for training, 30 for testing).
- External Benchmarks: To evaluate out-of-domain generalization, they tested their framework on FlowBench (30 tasks) and a subset of ComfyBench (20 tasks from the Creative and Complex categories).
Key Insights and Ideas
- JSON is the wrong abstraction level for LLM generation: Generating raw graph connections directly from natural language leads to a combinatorial explosion of possibilities and syntax errors. Decomposing the task into strategy $\rightarrow$ topology $\rightarrow$ parameters makes the problem manageable.
- SFT beats End-to-End Scaling: A smaller 14B model trained with this hierarchical knowledge structure consistently outperformed a larger 32B model trained to map text directly to pseudo-code (Q2P). Structure and reasoning data matter more than raw parameter count.
- Learning from Unlabeled Data via Inversion: Expert workflows are abundant online, but they don't come with design diaries explaining why a node was placed. Reversing the generation process allows the authors to automatically generate high-quality chain-of-thought training data from raw files.
Key Results
The proposed framework significantly outperformed baseline methods (including GPT-5 with RAG and specialized agents like ComfyAgent):
- Valid Node Diversity (VND): Reached a score of 152 on the test set, compared to just 40 for ComfyAgent and 42 for RAG, proving that the model generates diverse, custom layouts rather than relying on repetitive templates.
- Execution Success (Pass Rate): Achieved an average 86.9% pass rate across test categories, vastly outperforming ComfyAgent (36.4%) and GPT-5 + RAG (48.1%).
- Task Fulfillment (Resolve Rate): Jumped to 61.1%, doubling the performance of prior state-of-the-art methods at successfully executing and delivering the user's requested visual outcome.
Limitations and Future Work
- The "Rare Node" Problem: When a task requires highly specialized or rare custom nodes, the model tends to substitute them with more common, generic nodes. This breaks functional dependencies and causes execution errors.
- Future Directions: The authors suggest expanding the diversity of the training dataset to cover rare nodes and incorporating reinforcement learning methods (like GRPO) to further optimize local preference and structural robustness.
Summary updated