Expand description
Subgraph Support for LangGraph
Subgraphs allow nesting compiled graphs within nodes of a parent graph. This enables composition of complex workflows from simpler components.
§Example
ⓘ
use lc_langgraph::{StateGraph, CompiledGraph, SubgraphNode, START, END};
// Create subgraph
let subgraph = GraphBuilder::<AgentState>::new()
.add_node_fn("process", |state| Ok(StateUpdate::full(state.clone())))
.add_node_fn("output", |state| {
let mut s = state.clone();
s.set_output("done");
Ok(StateUpdate::full(s))
})
.add_edge(START, "process")
.add_edge("process", "output")
.add_edge("output", END)
.compile()?;
// Add as subgraph node in parent graph
let parent = GraphBuilder::<AgentState>::new()
.add_subgraph("subworkflow", subgraph,
|parent_state| parent_state.clone(), // input mapper
|sub_state, parent_state| *parent_state = sub_state.clone() // output mapper
)
.add_edge(START, "subworkflow")
.add_edge("subworkflow", END)
.compile()?;Structs§
- Subgraph
Builder - Builder for creating subgraph nodes with fluent API
- Subgraph
Node - Subgraph Node - A node that executes a nested compiled graph