Skip to main content
The 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:
Compilation:
  • 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)

Benefits:
  • Pure Python
  • Rich ecosystem
  • Extensive algorithms
  • Easy debugging

Rustworkx (Performance)

Benefits:
  • Rust-based performance
  • Faster graph operations
  • Lower memory usage
  • Better for large graphs
Requires: pip install rustworkx

Topological Execution

The workflow executes in topological layers:
Parallel execution within layers using ThreadPoolExecutor.

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
  1. Clear Dependencies: Only add edges for true dependencies
  2. Maximize Parallelism: Let independent nodes run concurrently
  3. Compilation: Always compile before running
  4. Entry/Exit Points: Let auto-detection work unless specific control needed
  5. Backend Choice: Use Rustworkx for large graphs (>100 nodes)
Graph compilation is cached - manually recompile if graph structure changes after initial compilation

Error Handling

Visualization

With Graphviz installed: