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
impl CompiledStateGraph
Sourcepub fn node_names(&self) -> Vec<String>
pub fn node_names(&self) -> Vec<String>
Get the node names in this graph.
Sourcepub fn channel_names(&self) -> Vec<String>
pub fn channel_names(&self) -> Vec<String>
Get the channel names in this graph.
Sourcepub fn checkpointer(&self) -> Option<&Arc<dyn BaseCheckpointSaver>>
pub fn checkpointer(&self) -> Option<&Arc<dyn BaseCheckpointSaver>>
Get the checkpointer, if any.
Sourcepub fn get_next_nodes(&self, state: &HashMap<String, JsonValue>) -> Vec<String>
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.
Sourcepub fn get_state(
&self,
config: &RunnableConfig,
) -> Result<StateSnapshot, GraphError>
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);Sourcepub fn update_state(
&self,
config: &RunnableConfig,
values: &JsonValue,
) -> Result<RunnableConfig, GraphError>
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 includethread_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)");Sourcepub fn get_state_history(
&self,
config: &RunnableConfig,
) -> Result<Vec<StateSnapshot>, GraphError>
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
impl CompiledStateGraph
Sourcepub fn astream(
&self,
input: &JsonValue,
config: &RunnableConfig,
stream_modes: Vec<StreamMode>,
) -> ReceiverStream<StreamPart>
pub fn astream( &self, input: &JsonValue, config: &RunnableConfig, stream_modes: Vec<StreamMode>, ) -> ReceiverStream<StreamPart>
Public streaming API: returns a ReceiverStream of StreamParts.