GraphWorkflow orchestrates agents using a Directed Acyclic Graph (DAG) structure, enabling complex workflows with dependencies, parallel branches, and convergence points. Ideal for sophisticated pipelines with intricate task relationships.
When to Use
- Complex dependencies: Tasks with intricate dependency graphs
- Parallel branches: Multiple independent paths that converge
- Pipeline optimization: Maximize parallelism while respecting dependencies
- Software builds: Compile, test, and deploy pipelines
- Data processing: ETL workflows with multiple stages
Key Features
- DAG-based execution with topological sorting
- Automatic parallelization of independent nodes
- Support for NetworkX and Rustworkx backends
- Fan-out and fan-in patterns
- Entry and exit point management
- Graph visualization (with Graphviz)
- Auto-compilation for performance
- Graph validation and cycle detection
Basic Example
Creating from Spec
Simplified workflow creation:Advanced Edge Patterns
Fan-Out Pattern
One node distributes to multiple nodes:Fan-In Pattern
Multiple nodes converge to one:Parallel Chain Pattern
Full mesh connection:Tuple-Based Patterns
Simplified edge definitions:Key Parameters
str
Name for the workflow
str
Description of the workflow’s purpose
Dict[str, Node]
Dictionary of nodes (agents)
List[Edge]
List of edges (dependencies)
List[str]
Node IDs with no predecessors (auto-detected if not set)
List[str]
Node IDs with no successors (auto-detected if not set)
int
default:"1"
Maximum execution loops
bool
default:"True"
Automatically compile on initialization
str
default:"networkx"
Graph backend (“networkx” or “rustworkx”)
bool
default:"False"
Enable verbose logging
Methods
add_node()
Add an agent to the graph:add_nodes()
Add multiple agents concurrently:add_edge()
Add a dependency between nodes:compile()
Pre-compute expensive operations:- Auto-sets entry/exit points
- Computes topological layers
- Caches for performance
- Validates graph structure
run()
Execute the workflow:Use Cases
Software Build Pipeline
Data Science Pipeline
Content Creation Workflow
Entry and Exit Points
Auto-Detection
Manual Setting
Backend Selection
NetworkX (Default)
- Pure Python
- Rich ecosystem
- Extensive algorithms
- Easy debugging
Rustworkx (Performance)
- Rust-based performance
- Faster graph operations
- Lower memory usage
- Better for large graphs
pip install rustworkx
Topological Execution
The workflow executes in topological layers:Graph Validation
Cycle Detection
Dependency Validation
Performance Optimization
Compilation Caching
Concurrent Node Addition
Best Practices
Graph Design: Keep graphs acyclic - use multiple workflows for iterative processes
- Clear Dependencies: Only add edges for true dependencies
- Maximize Parallelism: Let independent nodes run concurrently
- Compilation: Always compile before running
- Entry/Exit Points: Let auto-detection work unless specific control needed
- Backend Choice: Use Rustworkx for large graphs (>100 nodes)
Error Handling
Visualization
With Graphviz installed:Related Architectures
- Agent Rearrange - Simpler flow patterns
- Sequential Workflow - Linear execution
- Concurrent Workflow - Pure parallel
- Hierarchical Swarm - Director coordination