pub struct CompiledGraph<S: StateSchema> { /* private fields */ }Expand description
CompiledGraph - Ready-to-execute graph
Created from StateGraph.compile(). Handles:
- State management and updates
- Edge routing (fixed and conditional)
- Execution with recursion limits
- Checkpointing for persistence
Implementations§
Source§impl<S: StateSchema> CompiledGraph<S>
impl<S: StateSchema> CompiledGraph<S>
Sourcepub fn with_checkpointer<C: Checkpointer<S> + 'static>(
self,
checkpointer: C,
) -> Self
pub fn with_checkpointer<C: Checkpointer<S> + 'static>( self, checkpointer: C, ) -> Self
Attach a checkpointer to this graph for state persistence.
Sourcepub fn with_recursion_limit(self, limit: usize) -> Self
pub fn with_recursion_limit(self, limit: usize) -> Self
Set the maximum recursion depth before execution aborts.
Sourcepub fn with_interrupt_before(self, nodes: Vec<String>) -> Self
pub fn with_interrupt_before(self, nodes: Vec<String>) -> Self
Set the node names before which execution should be interrupted.
Sourcepub fn with_interrupt_after(self, nodes: Vec<String>) -> Self
pub fn with_interrupt_after(self, nodes: Vec<String>) -> Self
Set the node names after which execution should be interrupted.
Sourcepub fn node_names(&self) -> Vec<String>
pub fn node_names(&self) -> Vec<String>
Return the names of all static nodes registered in the graph.
Sourcepub fn entry_point(&self) -> &str
pub fn entry_point(&self) -> &str
Return the entry point node name.
Sourcepub fn recursion_limit(&self) -> usize
pub fn recursion_limit(&self) -> usize
Return the configured recursion limit.
Sourcepub fn interrupt_before(&self) -> &[String]
pub fn interrupt_before(&self) -> &[String]
Return the nodes that interrupt execution before running.
Sourcepub fn interrupt_after(&self) -> &[String]
pub fn interrupt_after(&self) -> &[String]
Return the nodes that interrupt execution after running.
Sourcepub async fn last_checkpoint_state(&self) -> Option<(S, usize)>
pub async fn last_checkpoint_state(&self) -> Option<(S, usize)>
Get the last checkpoint state (for interrupt recovery), together with the recursion budget consumed up to that checkpoint.
H5: 不再用 list() 的 HashMap 乱序 + ids.last() 猜“最近“;直接由
checkpointer 的 last() 按 (timestamp, seq) 返回真正最近的 checkpoint。
Sourcepub async fn create_resume_execution(
&self,
interrupted_node: &str,
) -> Option<GraphExecution<S>>
pub async fn create_resume_execution( &self, interrupted_node: &str, ) -> Option<GraphExecution<S>>
Create a resume execution context (from the last checkpoint) interrupted_node may be “node_name” or “after_node_name”
Sourcepub fn submit_task(&self, description: impl Into<String>)
pub fn submit_task(&self, description: impl Into<String>)
Submit a new task for dynamic planning mid-execution
Sourcepub async fn inject_node(
&self,
name: &str,
node: Arc<dyn GraphNode<S>>,
) -> GraphResult<()>
pub async fn inject_node( &self, name: &str, node: Arc<dyn GraphNode<S>>, ) -> GraphResult<()>
Inject a runtime node directly
Sourcepub async fn inject_edge(&self, source: &str, target: &str) -> GraphResult<()>
pub async fn inject_edge(&self, source: &str, target: &str) -> GraphResult<()>
Inject a runtime edge directly
Sourcepub async fn inject_subgraph<SubS: StateSchema + 'static>(
&self,
name: &str,
subgraph: CompiledGraph<SubS>,
input_mapper: impl Fn(&S) -> SubS + Send + Sync + 'static,
output_mapper: impl Fn(&SubS, &mut S) + Send + Sync + 'static,
) -> GraphResult<()>
pub async fn inject_subgraph<SubS: StateSchema + 'static>( &self, name: &str, subgraph: CompiledGraph<SubS>, input_mapper: impl Fn(&S) -> SubS + Send + Sync + 'static, output_mapper: impl Fn(&SubS, &mut S) + Send + Sync + 'static, ) -> GraphResult<()>
Inject a subgraph as a runtime node
Source§impl<S: StateSchema> CompiledGraph<S>
impl<S: StateSchema> CompiledGraph<S>
Sourcepub async fn invoke(&self, input: S) -> GraphResult<GraphInvocation<S>>
pub async fn invoke(&self, input: S) -> GraphResult<GraphInvocation<S>>
Run the graph from its entry point with the given input state.
Sourcepub async fn invoke_with_execution(
&self,
execution: GraphExecution<S>,
) -> GraphResult<GraphInvocation<S>>
pub async fn invoke_with_execution( &self, execution: GraphExecution<S>, ) -> GraphResult<GraphInvocation<S>>
Continue execution from a saved GraphExecution (e.g. after an interrupt).
Sourcepub async fn resume(
&self,
execution: GraphExecution<S>,
) -> GraphResult<GraphInvocation<S>>
pub async fn resume( &self, execution: GraphExecution<S>, ) -> GraphResult<GraphInvocation<S>>
Resume execution from the given execution context.
Sourcepub async fn invoke_from_node(
&self,
start_node: String,
input: S,
) -> GraphResult<GraphInvocation<S>>
pub async fn invoke_from_node( &self, start_node: String, input: S, ) -> GraphResult<GraphInvocation<S>>
Run the graph starting from the given node with the given input state.
Source§impl<S: StateSchema> CompiledGraph<S>
impl<S: StateSchema> CompiledGraph<S>
Sourcepub async fn invoke_parallel(
&self,
input: S,
) -> GraphResult<ParallelInvocation<S>>
pub async fn invoke_parallel( &self, input: S, ) -> GraphResult<ParallelInvocation<S>>
Run the graph while capturing parallel fan-out branches into a ParallelInvocation.
Sourcepub async fn invoke_dynamic(
&self,
input: S,
planner: &dyn DynamicPlanner<S>,
) -> GraphResult<GraphInvocation<S>>
pub async fn invoke_dynamic( &self, input: S, planner: &dyn DynamicPlanner<S>, ) -> GraphResult<GraphInvocation<S>>
Execute the graph with dynamic task injection support.
After each node completes, checks the task_inbox for newly submitted tasks.
If tasks are found, uses the provided planner to convert them into new
nodes/edges and injects them into the runtime registries before continuing.
Source§impl<S: StateSchema + Send + Sync + 'static> CompiledGraph<S>
impl<S: StateSchema + Send + Sync + 'static> CompiledGraph<S>
Sourcepub fn stream(
&self,
input: S,
) -> Pin<Box<dyn Stream<Item = Result<StreamEvent<S>, GraphError>> + Send>>
pub fn stream( &self, input: S, ) -> Pin<Box<dyn Stream<Item = Result<StreamEvent<S>, GraphError>> + Send>>
Stream graph execution as a true async stream.
Each StreamEvent is emitted as soon as it occurs (node entry,
node completion, state update), enabling real-time consumption.
This is the preferred streaming API. For the old all-at-once
behavior, use stream_collected().
Sourcepub async fn stream_collected(
&self,
input: S,
) -> GraphResult<Vec<StreamEvent<S>>>
pub async fn stream_collected( &self, input: S, ) -> GraphResult<Vec<StreamEvent<S>>>
Collect all stream events into a Vec (backward-compatible API).
This is the old stream() behavior. Prefer stream() for
real-time consumption.
Source§impl<S: StateSchema> CompiledGraph<S>
impl<S: StateSchema> CompiledGraph<S>
Sourcepub fn validate(&self) -> GraphResult<()>
pub fn validate(&self) -> GraphResult<()>
Validate the graph structure: node references, duplicate edges,
unreachable nodes, and cycles with no path to END.
Source§impl<S: StateSchema> CompiledGraph<S>
impl<S: StateSchema> CompiledGraph<S>
Sourcepub fn visualize_ascii(&self) -> String
pub fn visualize_ascii(&self) -> String
Visualize the graph structure in ASCII format
Sourcepub fn visualize_mermaid(&self) -> String
pub fn visualize_mermaid(&self) -> String
Visualize the graph structure in Mermaid format
Sourcepub fn visualize_json(&self) -> Value
pub fn visualize_json(&self) -> Value
Visualize the graph structure as JSON
Sourcepub fn to_definition(&self) -> GraphDefinition
pub fn to_definition(&self) -> GraphDefinition
Convert the graph into a portable GraphDefinition.
Trait Implementations§
Source§impl<S: Clone + StateSchema> Clone for CompiledGraph<S>
impl<S: Clone + StateSchema> Clone for CompiledGraph<S>
Source§fn clone(&self) -> CompiledGraph<S>
fn clone(&self) -> CompiledGraph<S>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more