pub struct AgentState {
pub thread_id: ThreadId,
pub turn_count: usize,
pub total_usage: TokenUsage,
pub metadata: HashMap<String, Value>,
pub created_at: OffsetDateTime,
pub guardrail_retries: usize,
pub accumulated_cost_usd: Option<f64>,
}Expand description
Snapshot of agent state for checkpointing
Fields§
§thread_id: ThreadId§turn_count: usize§total_usage: TokenUsage§metadata: HashMap<String, Value>§created_at: OffsetDateTime§guardrail_retries: usizeNumber of consecutive on_llm_response guardrail rejections
(RetryWithFeedback) across the thread’s turns.
Persisted so the loop’s consecutive-rejection cap also binds
host-driven single-turn orchestration, where each run_turn rebuilds
its in-memory context from this state. Reset to zero whenever the
hook accepts a response. Additive and wire-compatible: absent in
older snapshots, defaulting to zero.
accumulated_cost_usd: Option<f64>Estimated USD cost accumulated across the thread’s LLM calls.
Each call’s usage is priced at the provider/model that served it and
added here, so a thread that rotates models keeps the true sum
instead of repricing its whole history at the newest model’s rates.
None means no priced usage has been tracked yet: a fresh thread
before its first priced call, a thread whose models have no pricing
metadata, or a snapshot predating this field. Legacy snapshots are
seeded once (best-effort) by repricing the aggregate usage at the
rates current when the thread next runs, then accumulate normally.
Additive and wire-compatible via #[serde(default)].
Implementations§
Source§impl AgentState
impl AgentState
pub fn new(thread_id: ThreadId) -> AgentState
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