pub struct AgentState {
pub messages: Vec<Message>,
pub iteration: usize,
pub stop_reason: Option<StopReason>,
pub tool_results: Vec<ToolResult>,
pub total_tokens: usize,
pub input_tokens: usize,
pub output_tokens: usize,
}Expand description
Agent execution state
Tracks the full lifecycle of an agent conversation including messages, token usage, tool results, and iteration progress.
Derives Serialize/Deserialize for session persistence and
cross-process state transfer (e.g. oxios supervisor serialization).
Fields§
§messages: Vec<Message>Conversation message history (user, assistant, and tool-result messages).
iteration: usizeCurrent agent loop iteration (incremented after each assistant turn).
stop_reason: Option<StopReason>The reason the last turn stopped, if any.
tool_results: Vec<ToolResult>Accumulated results from tool executions in the current conversation.
total_tokens: usizeCumulative token count (input + output) across all turns.
input_tokens: usizeCumulative prompt / input tokens across all turns.
output_tokens: usizeCumulative completion / output tokens across all turns.
Implementations§
Source§impl AgentState
impl AgentState
Sourcepub fn add_user_message(&mut self, content: String)
pub fn add_user_message(&mut self, content: String)
Add a user message
Sourcepub fn add_assistant_message(&mut self, content: String)
pub fn add_assistant_message(&mut self, content: String)
Add an assistant message
Sourcepub fn add_tool_result(&mut self, tool_call_id: String, content: String)
pub fn add_tool_result(&mut self, tool_call_id: String, content: String)
Add a tool result message to both the message history and the tool results list.
Sourcepub fn increment_iteration(&mut self)
pub fn increment_iteration(&mut self)
Increment the iteration counter after an assistant turn completes.
Sourcepub fn set_stop_reason(&mut self, reason: StopReason)
pub fn set_stop_reason(&mut self, reason: StopReason)
Record the reason the last turn stopped.
Sourcepub fn record_usage(&mut self, input: usize, output: usize)
pub fn record_usage(&mut self, input: usize, output: usize)
Accumulate token usage from a completed LLM call.
Sourcepub fn replace_messages(&mut self, messages: Vec<Message>)
pub fn replace_messages(&mut self, messages: Vec<Message>)
Replace the entire message history (used after context compaction).
Sourcepub fn estimate_tokens(&self) -> usize
pub fn estimate_tokens(&self) -> usize
Rough token-count estimate based on the serialized message JSON length.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Returns true if the agent has signaled a stop reason.
Trait Implementations§
Source§impl Clone for AgentState
impl Clone for AgentState
Source§fn clone(&self) -> AgentState
fn clone(&self) -> AgentState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more