pub struct GraphState {
pub conversation: Conversation,
pub variables: HashMap<String, String>,
pub last_result: Option<String>,
pub last_error: Option<String>,
pub should_terminate: bool,
pub metadata: HashMap<String, String>,
pub parsed_decision: Option<GraphDecision>,
pub active_paradigm: Option<String>,
pub iteration_count: usize,
pub token_budget_remaining: u32,
pub interrupt_points: Vec<InterruptPoint>,
}Expand description
The state that flows through the StateGraph during execution.
State is passed from node to node via the edges. Each node can read from and write to this state. The state is serializable for checkpoint persistence.
P2-2 extension: added fields for AgentLoop integration —
parsed_decision enables edge routing based on structured decisions
(not unreliable string pattern matching), active_paradigm tracks
the current paradigm for tool filtering, and iteration_count
enables IterationExceeds edge conditions for loop safety.
Fields§
§conversation: ConversationThe current conversation.
variables: HashMap<String, String>State variables (key-value pairs accessible by nodes).
last_result: Option<String>The last action result (output from the most recently executed node).
last_error: Option<String>Error message (if the last node failed).
should_terminate: boolWhether the graph execution should terminate.
metadata: HashMap<String, String>Metadata.
parsed_decision: Option<GraphDecision>The parsed decision from the most recent LLM inference.
After each LlmInfer node, the GraphActionExecutor parses the LLM
response into a GraphDecision and stores it here. Edge conditions
(HasToolCalls, IsFinalAnswer, RequestsDelegation) evaluate against
this field instead of raw string content, making routing reliable
and consistent with the AgentLoop’s decision parsing.
Cleared when a SwitchParadigm node is executed (new inference needed).
active_paradigm: Option<String>The active paradigm for tool filtering and system prompts.
When set, subsequent LlmInfer nodes (with include_tool_definitions = true)
use the paradigm’s tool_filter to build tool definitions. Paradigm-specific
system prompts are also injected into the conversation.
Set by SwitchParadigm nodes, or initialized from the AgentLoop’s active paradigm when the graph starts executing.
iteration_count: usizeThe current iteration count in the graph walk.
Incremented each time the executor processes a node. Enables IterationExceeds edge conditions for loop safety (e.g., “route to error_handler if iterations > 20”).
token_budget_remaining: u32Remaining token budget (in tokens).
Decremented after each LLM inference. When it reaches 0, the graph should terminate (budget exhaustion).
interrupt_points: Vec<InterruptPoint>Accumulated interrupt points during execution.
When a HumanApproval node is encountered (with interrupt: true),
the executor records the interrupt point here. These are also
included in GraphExecutionResult.interrupt_checkpoints.
Implementations§
Source§impl GraphState
impl GraphState
Sourcepub fn with_budget(budget: u32) -> Self
pub fn with_budget(budget: u32) -> Self
Create a graph state with a token budget.