Expand description
Subgraphs / Nested Workflows
Enables composing graphs within graphs for modular, reusable workflow components.
§Features
- Nest graphs as nodes within parent graphs
- State mapping between parent and child graphs
- Parallel subgraph execution
- Isolated or shared state modes
- Subgraph libraries for reusable components
§Example
ⓘ
use cortexai_crew::subgraph::{SubgraphNode, StateMapping};
// Create a reusable research subgraph
let research_graph = GraphBuilder::new("research")
.add_node("search", search_node)
.add_node("analyze", analyze_node)
.add_edge("search", "analyze")
.set_entry("search")
.build()?;
// Create a reusable writing subgraph
let writing_graph = GraphBuilder::new("writing")
.add_node("draft", draft_node)
.add_node("edit", edit_node)
.add_edge("draft", "edit")
.set_entry("draft")
.build()?;
// Compose into a parent graph
let main_graph = GraphBuilder::new("main")
.add_node("init", init_node)
.add_subgraph("research", research_graph, StateMapping::default())
.add_subgraph("writing", writing_graph, StateMapping::default())
.add_edge("init", "research")
.add_edge("research", "writing")
.set_entry("init")
.build()?;Structs§
- Conditional
Subgraph - Conditional subgraph - executes one of several subgraphs based on state
- Loop
Subgraph - Loop subgraph - executes a subgraph repeatedly until a condition is met
- Parallel
Subgraphs - Parallel subgraph executor - runs multiple subgraphs concurrently
- Retry
Subgraph - Retry subgraph - retries a subgraph on failure
- State
Mapping - State mapping configuration between parent and child graphs
- Subgraph
Execution Info - Subgraph execution result with detailed info
- Subgraph
Library - Subgraph library for reusable components
- Subgraph
Node - A node that executes a subgraph
Enums§
- Merge
Strategy - Strategy for merging parallel subgraph results
Traits§
- Graph
Builder Subgraph Ext - Extension trait for GraphBuilder to add subgraph nodes