Skip to main content

CompiledStateGraph

Struct CompiledStateGraph 

Source
pub struct CompiledStateGraph { /* private fields */ }
Expand description

A compiled, executable state graph.

This is the result of StateGraph::compile() and implements Runnable. In the full Pregel engine (Phase 6), this will execute in BSP super-steps. Currently it provides a simplified sequential execution model.

Implementations§

Source§

impl CompiledStateGraph

Source

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

Get the node names in this graph.

Source

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

Get the channel names in this graph.

Source

pub fn has_node(&self, name: &str) -> bool

Check if a node exists.

Source

pub fn name(&self) -> &str

Get the graph name.

Source

pub fn checkpointer(&self) -> Option<&Arc<dyn BaseCheckpointSaver>>

Get the checkpointer, if any.

Source

pub fn store(&self) -> Option<&Arc<dyn BaseStore>>

Get the store, if any.

Source

pub fn get_next_nodes(&self, state: &HashMap<String, JsonValue>) -> Vec<String>

Determine which nodes should execute next given the current state.

This is the “plan” phase of the BSP cycle.

Source

pub fn get_state( &self, config: &RunnableConfig, ) -> Result<StateSnapshot, GraphError>

Get the current state of the graph from the checkpointer.

Returns a StateSnapshot containing the current channel values, the names of nodes that will execute next, pending tasks, and any unresolved interrupts.

Requires a checkpointer to be configured.

§Example
let snapshot = compiled.get_state(&config)?;
println!("next: {:?}", snapshot.next);
println!("values: {}", snapshot.values);
Source

pub fn update_state( &self, config: &RunnableConfig, values: &JsonValue, ) -> Result<RunnableConfig, GraphError>

Manually update the graph state.

Applies the given values to the current checkpoint’s channels and saves a new checkpoint. This allows updating custom state fields (like name, birthday) outside of normal node execution.

Requires a checkpointer to be configured.

§Arguments
  • config - The runnable config (must include thread_id)
  • values - A JSON object of channel updates, e.g. {"name": "LangGraph"}
§Example
compiled.update_state(&config, json!({"name": "LangGraph (library)"}))?;
let snapshot = compiled.get_state(&config)?;
assert_eq!(snapshot.values["name"], "LangGraph (library)");
Source

pub fn get_state_history( &self, config: &RunnableConfig, ) -> Result<Vec<StateSnapshot>, GraphError>

Get the state history (all checkpoints) for a thread.

Returns a list of StateSnapshot in reverse chronological order (newest first). Each snapshot contains the checkpoint’s channel values, which node would execute next, and metadata.

This enables “time travel” — reviewing past states and resuming from any checkpoint.

§Example
let history = compiled.get_state_history(&config)?;
for snapshot in &history {
    println!("messages: {}, next: {:?}", snapshot.values["messages"].as_array().map(|a| a.len()), snapshot.next);
}
Source§

impl CompiledStateGraph

Source

pub fn astream( &self, input: &JsonValue, config: &RunnableConfig, stream_modes: Vec<StreamMode>, ) -> ReceiverStream<StreamPart>

Public streaming API: returns a ReceiverStream of StreamParts.

Trait Implementations§

Source§

impl Clone for CompiledStateGraph

Source§

fn clone(&self) -> Self

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 Runnable for CompiledStateGraph

Source§

fn invoke( &self, input: &JsonValue, config: &RunnableConfig, ) -> Result<JsonValue, RunnableError>

Execute synchronously.
Source§

fn ainvoke<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, input: &'life1 JsonValue, config: &'life2 RunnableConfig, ) -> Pin<Box<dyn Future<Output = Result<JsonValue, RunnableError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Execute asynchronously.
Source§

fn name(&self) -> &str

Human-readable name for tracing/debugging.

Auto Trait Implementations§

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 = Infallible

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.