Skip to main content

CompiledGraph

Struct CompiledGraph 

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

Source

pub fn with_checkpointer<C: Checkpointer<S> + 'static>( self, checkpointer: C, ) -> Self

Attach a checkpointer to this graph for state persistence.

Source

pub fn with_recursion_limit(self, limit: usize) -> Self

Set the maximum recursion depth before execution aborts.

Source

pub fn with_interrupt_before(self, nodes: Vec<String>) -> Self

Set the node names before which execution should be interrupted.

Source

pub fn with_interrupt_after(self, nodes: Vec<String>) -> Self

Set the node names after which execution should be interrupted.

Source

pub fn node_names(&self) -> Vec<String>

Return the names of all static nodes registered in the graph.

Source

pub fn get_edges(&self) -> &[GraphEdge]

Return the graph’s fixed edges.

Source

pub fn entry_point(&self) -> &str

Return the entry point node name.

Source

pub fn recursion_limit(&self) -> usize

Return the configured recursion limit.

Source

pub fn interrupt_before(&self) -> &[String]

Return the nodes that interrupt execution before running.

Source

pub fn interrupt_after(&self) -> &[String]

Return the nodes that interrupt execution after running.

Source

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: no longer guesses “most recent” from list()’s HashMap order + ids.last(); instead the checkpointer’s last() returns the truly newest checkpoint by (timestamp, seq).

Source

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”

Source

pub fn submit_task(&self, description: impl Into<String>)

Submit a new task for dynamic planning mid-execution

Source

pub async fn inject_node( &self, name: &str, node: Arc<dyn GraphNode<S>>, ) -> GraphResult<()>

Inject a runtime node directly

Source

pub async fn inject_edge(&self, source: &str, target: &str) -> GraphResult<()>

Inject a runtime edge directly

Source

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>

Source

pub async fn invoke(&self, input: S) -> GraphResult<GraphInvocation<S>>

Run the graph from its entry point with the given input state.

Source

pub async fn invoke_with_execution( &self, execution: GraphExecution<S>, ) -> GraphResult<GraphInvocation<S>>

Continue execution from a saved GraphExecution (e.g. after an interrupt).

Source

pub async fn resume( &self, execution: GraphExecution<S>, ) -> GraphResult<GraphInvocation<S>>

Resume execution from the given execution context.

Source

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>

Source

pub async fn invoke_parallel( &self, input: S, ) -> GraphResult<ParallelInvocation<S>>

Run the graph while capturing parallel fan-out branches into a ParallelInvocation.

Source

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>

Source

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().

Source

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>

Source

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>

Source

pub fn visualize_ascii(&self) -> String

Visualize the graph structure in ASCII format

Source

pub fn visualize_mermaid(&self) -> String

Visualize the graph structure in Mermaid format

Source

pub fn visualize_json(&self) -> Value

Visualize the graph structure as JSON

Source

pub fn to_definition(&self) -> GraphDefinition

Convert the graph into a portable GraphDefinition.

Trait Implementations§

Source§

impl<S: Clone + StateSchema> Clone for CompiledGraph<S>

Source§

fn clone(&self) -> CompiledGraph<S>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: StateSchema> Debug for CompiledGraph<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for CompiledGraph<S>

§

impl<S> !UnwindSafe for CompiledGraph<S>

§

impl<S> Freeze for CompiledGraph<S>

§

impl<S> Send for CompiledGraph<S>

§

impl<S> Sync for CompiledGraph<S>

§

impl<S> Unpin for CompiledGraph<S>

§

impl<S> UnsafeUnpin for CompiledGraph<S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.