CompiledStateGraph<TState>
Models & Types · AiDotNet.Agentic.Graph
An executable, validated state graph produced by Compile. Runs nodes
according to the graph’s edges, threading the state from one node to the next until it reaches the end.
For Beginners
This is the “compiled program” form of your graph. You give it a starting state and it walks the nodes you wired up, handing each node the latest state, until it reaches the end — then returns the final state.
How It Works
Execution starts at the entry node. After a node runs, the next node is chosen by: its conditional
router (if any), else its fixed edge, else the run ends. Cycles are allowed and bounded by
MaxSteps. Use InvokeAsync for the final state or
StreamAsync to observe each step.
Methods
| Method | Summary |
|---|---|
IAsyncEnumerable<GraphStepUpdate<TState>> ReplayAsync(IGraphCheckpointer<TState> checkpointer, string threadId, CancellationToken cancellationToken) |
Deterministically replays a recorded run from its checkpoint history WITHOUT executing any nodes, yielding the same (node, state) sequence the original run produced. |
IAsyncEnumerable<GraphStepUpdate<TState>> StreamAsync(TState initialState, GraphRunOptions options, CancellationToken cancellationToken) |
Runs the graph and yields an update after each node executes, ending when flow reaches the end node. |
Task<GraphRunResult<TState>> RunAsync(TState initialState, IGraphCheckpointer<TState> checkpointer, string threadId, Func<TState, TState> applyOnResume, GraphRunOptions options, CancellationToken cancellationToken) |
Runs the graph with human-in-the-loop interrupts under a thread id. |
Task<TState> GetRecordedStateAsync(IGraphCheckpointer<TState> checkpointer, string threadId, CancellationToken cancellationToken) |
Returns the final recorded state for a thread (read from checkpoints, no execution). |
Task<TState> InvokeAsync(TState initialState, GraphRunOptions options, CancellationToken cancellationToken) |
Runs the graph from the supplied initial state and returns the final state. |
Task<TState> InvokeAsync(TState initialState, IGraphCheckpointer<TState> checkpointer, string threadId, GraphRunOptions options, CancellationToken cancellationToken) |
Runs the graph with durable checkpointing under a thread id, resuming automatically from the latest saved checkpoint if one exists for that thread (otherwise starting fresh from initialState). |
Task<TState> ResumeFromAsync(IGraphCheckpointer<TState> checkpointer, string threadId, string checkpointId, GraphRunOptions options, CancellationToken cancellationToken) |
Resumes (replays) a thread from a specific past checkpoint — the basis for time-travel — continuing execution from that checkpoint’s next node and state, and saving new checkpoints as it goes. |