Available on crate feature
graph only.Expand description
Running one graph as a node of another.
A subgraph keeps its own channels, its own edges and its own interrupt gates,
and exchanges named channels with its parent. Nesting through
AgentNode instead would force the state through the
Agent boundary as Content, and a pause inside would arrive as an event the
parent reports rather than a pause the parent honours.
§Channels are checked when the parent compiles
Both schemas are known before anything runs, so a mapping that names a channel
neither side declares is a compile error
naming the channel and the side. A mismatch cannot reach a run and surface as
an absent value.
§Example
use adk_graph::edge::{END, START};
use adk_graph::graph::StateGraph;
use adk_graph::node::NodeOutput;
use adk_graph::subgraph::SubgraphNode;
use serde_json::json;
use std::sync::Arc;
// The inner graph knows nothing about its parent.
let inner = StateGraph::with_channels(&["text", "length"])
.add_node_fn("measure", |ctx| async move {
let text = ctx.get("text").and_then(|v| v.as_str()).unwrap_or("");
Ok(NodeOutput::new().with_update("length", json!(text.len())))
})
.add_edge(START, "measure")
.add_edge("measure", END)
.compile()?;
let outer = StateGraph::with_channels(&["document", "size"])
.add_node(
SubgraphNode::new("measure_doc", Arc::new(inner))
.with_input("document", "text")
.with_output("length", "size"),
)
.add_edge(START, "measure_doc")
.add_edge("measure_doc", END)
.compile()?;Structs§
- Subgraph
Node - One graph running as a node of another.
Enums§
- Channel
Side - Which side of a subgraph mapping a channel name belongs to.