pub struct Checkpoint {
pub id: String,
pub system_prompt: String,
pub provider: String,
pub model_id: String,
pub messages: Vec<LlmMessage>,
pub custom_messages: Vec<Value>,
pub turn_count: usize,
pub usage: Usage,
pub cost: Cost,
pub created_at: u64,
pub metadata: HashMap<String, Value>,
pub state: Option<Value>,
/* private fields */
}Expand description
A serializable snapshot of agent conversation state.
Captures everything needed to restore an agent to a previous point: messages, system prompt, model info, turn count, accumulated usage/cost, and arbitrary metadata.
Fields§
§id: StringUnique identifier for this checkpoint.
system_prompt: StringSystem prompt at the time of the checkpoint.
provider: StringModel provider name.
model_id: StringModel identifier.
messages: Vec<LlmMessage>Conversation messages (LLM messages only).
custom_messages: Vec<Value>Serialized custom messages (envelopes with type and data fields).
turn_count: usizeNumber of completed turns at the time of checkpointing.
usage: UsageAccumulated token usage.
cost: CostAccumulated cost.
created_at: u64Unix timestamp when the checkpoint was created.
metadata: HashMap<String, Value>Arbitrary metadata for application-specific use.
state: Option<Value>Serialized session state snapshot (SessionState.data).
Implementations§
Source§impl Checkpoint
impl Checkpoint
Sourcepub fn new(
id: impl Into<String>,
system_prompt: impl Into<String>,
provider: impl Into<String>,
model_id: impl Into<String>,
messages: &[AgentMessage],
) -> Self
pub fn new( id: impl Into<String>, system_prompt: impl Into<String>, provider: impl Into<String>, model_id: impl Into<String>, messages: &[AgentMessage], ) -> Self
Create a new checkpoint from the current agent state.
Serializes CustomMessage variants that support serialization (i.e.
type_name() and to_json() return Some). Custom messages that
cannot be serialized are skipped with a warning.
Use with_turn_count(), with_usage(), and with_cost() to set
additional fields.
Sourcepub fn with_state(self, state: Value) -> Self
pub fn with_state(self, state: Value) -> Self
Set the session state snapshot.
Sourcepub const fn with_turn_count(self, turn_count: usize) -> Self
pub const fn with_turn_count(self, turn_count: usize) -> Self
Set the turn count.
Sourcepub fn with_usage(self, usage: Usage) -> Self
pub fn with_usage(self, usage: Usage) -> Self
Set the accumulated usage.
Sourcepub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
pub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
Add metadata to this checkpoint.
Sourcepub fn restore_messages(
&self,
registry: Option<&CustomMessageRegistry>,
) -> Vec<AgentMessage>
pub fn restore_messages( &self, registry: Option<&CustomMessageRegistry>, ) -> Vec<AgentMessage>
Restore all messages as AgentMessage values, preserving their
original interleaved order.
If registry is None, custom messages are silently skipped.
Deserialization failures are logged as warnings but do not cause errors.
For checkpoints created before ordering support, falls back to legacy behavior (LLM messages first, then custom messages appended).
Trait Implementations§
Source§impl Clone for Checkpoint
impl Clone for Checkpoint
Source§fn clone(&self) -> Checkpoint
fn clone(&self) -> Checkpoint
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more