Overview
ComfyUI workflows are node-based graphs that define image generation pipelines. Each workflow is a JSON structure containing nodes, their connections, and configuration. The workflow system supports both static and dynamic execution with advanced features like caching and subgraph expansion.Workflow JSON Format
Workflows are represented as JSON objects with a specific structure:Node Structure
Each node in the workflow contains:Unique identifier for the node
The class type of the node (e.g., “CheckpointLoaderSimple”, “KSampler”)
Input connections and values for the node
Output definitions with types and connected links
Configuration values for node parameters
Dynamic Prompt System
ComfyUI uses aDynamicPrompt class to manage workflow execution:
Ephemeral Nodes: Nodes can dynamically create additional nodes during execution. These ephemeral nodes are tracked separately but execute as part of the same workflow.
Adding Ephemeral Nodes
Fromexecution.py:566:
Workflow Execution
Execution Flow
Workflow execution follows these stages:Validation
The workflow is validated using
validate_prompt() to check for:- Missing node types
- Invalid connections
- Missing required inputs
- Type mismatches
Node Execution
Nodes execute in dependency order. Each node:
- Retrieves input data from connected nodes
- Executes its FUNCTION method
- Stores outputs in cache
- Updates execution state
Execution List
TheExecutionList class manages execution order:
Output Nodes
Nodes are marked as output nodes using theOUTPUT_NODE class attribute:
execution.py:1049-1051:
Subgraph Expansion
Nodes can dynamically expand into subgraphs during execution:- Generate dynamic workflows based on input
- Implement control flow (loops, conditionals)
- Create reusable node groups
Execution Blocking
Nodes can block execution with messages:ExecutionBlocker, execution halts and sends an error message to the client:
Workflow Metadata
Version
The
version field tracks workflow format compatibilityRevision
Incremental counter for workflow changes
Node IDs
last_node_id tracks the highest node ID usedLink IDs
last_link_id tracks the highest link ID usedBest Practices
Workflow Organization
Workflow Organization
- Group related nodes together visually
- Use reroute nodes for cleaner connections
- Name nodes descriptively in the
_meta.titlefield
Error Handling
Error Handling
- Always validate inputs before execution
- Use ExecutionBlocker for recoverable errors
- Check for required vs optional inputs
Performance
Performance
- Minimize redundant nodes
- Leverage caching for repeated operations
- Use batch processing where possible
Reusability
Reusability
- Create subgraph blueprints for common patterns
- Use widget values for parameterization
- Document expected input/output types
See Also
Nodes
Learn about the node system and node types
Execution
Deep dive into the execution engine
Models
Understanding model loading and management