Skip to main content

Module subgraph

Module subgraph 

Source
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§

ConditionalSubgraph
Conditional subgraph - executes one of several subgraphs based on state
LoopSubgraph
Loop subgraph - executes a subgraph repeatedly until a condition is met
ParallelSubgraphs
Parallel subgraph executor - runs multiple subgraphs concurrently
RetrySubgraph
Retry subgraph - retries a subgraph on failure
StateMapping
State mapping configuration between parent and child graphs
SubgraphExecutionInfo
Subgraph execution result with detailed info
SubgraphLibrary
Subgraph library for reusable components
SubgraphNode
A node that executes a subgraph

Enums§

MergeStrategy
Strategy for merging parallel subgraph results

Traits§

GraphBuilderSubgraphExt
Extension trait for GraphBuilder to add subgraph nodes