pub struct CompiledGraph<S: State> { /* private fields */ }Expand description
A compiled, executable graph.
CompiledGraph is the result of compiling a StateGraph. It provides methods to execute the graph with different invocation patterns.
Implementations§
Source§impl<S: State> CompiledGraph<S>
impl<S: State> CompiledGraph<S>
Sourcepub async fn invoke(&mut self, input: S, config: Config) -> Result<S>
pub async fn invoke(&mut self, input: S, config: Config) -> Result<S>
Execute the graph with the given input
This runs the graph to completion and returns the final state.
§Arguments
input- Initial stateconfig- Execution configuration
§Returns
The final state after graph execution
§Example
let app = graph.compile(None)?;
let result = app.invoke(
MyState { count: 0 },
Config::default()
).await?;
println!("Final count: {}", result.count);Sourcepub async fn stream(
&mut self,
input: S,
config: Config,
mode: StreamMode,
) -> Result<Pin<Box<dyn Stream<Item = Result<StreamEvent>> + Send>>>
pub async fn stream( &mut self, input: S, config: Config, mode: StreamMode, ) -> Result<Pin<Box<dyn Stream<Item = Result<StreamEvent>> + Send>>>
Stream execution events
Returns a stream of events as the graph executes, allowing real-time observation of progress.
§Arguments
input- Initial stateconfig- Execution configurationmode- Type of events to stream
Sourcepub async fn get_state(
&self,
config: &Config,
) -> Result<Option<StateSnapshot<S>>>
pub async fn get_state( &self, config: &Config, ) -> Result<Option<StateSnapshot<S>>>
Get the current state for a given configuration
This retrieves the most recent checkpoint for the thread.
Sourcepub async fn get_state_history(
&self,
config: &Config,
limit: Option<usize>,
) -> Result<Vec<StateSnapshot<S>>>
pub async fn get_state_history( &self, config: &Config, limit: Option<usize>, ) -> Result<Vec<StateSnapshot<S>>>
Get the state history for a thread
Returns past checkpoints in reverse chronological order.
Sourcepub async fn update_state(
&mut self,
config: Config,
values: S,
) -> Result<Config>
pub async fn update_state( &mut self, config: Config, values: S, ) -> Result<Config>
Update the state for a thread
This allows modifying the checkpoint state, useful for human-in-the-loop patterns.
Auto Trait Implementations§
impl<S> Freeze for CompiledGraph<S>
impl<S> !RefUnwindSafe 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>
impl<S> !UnwindSafe for CompiledGraph<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more