pub struct Session { /* private fields */ }Expand description
A conversation session with full history
Uses Arc<Vec
Implementations§
Source§impl Session
impl Session
Sourcepub fn messages_mut(&mut self) -> &mut Vec<Message>
pub fn messages_mut(&mut self) -> &mut Vec<Message>
Get mutable access to messages (triggers CoW if Arc is shared)
Sourcepub fn created_at(&self) -> SystemTime
pub fn created_at(&self) -> SystemTime
Get creation time
Sourcepub fn updated_at(&self) -> SystemTime
pub fn updated_at(&self) -> SystemTime
Get last update time
Sourcepub fn push(&mut self, message: Message)
pub fn push(&mut self, message: Message)
Add a message to the session
Updates the timestamp. For adding multiple messages, prefer push_batch.
Sourcepub fn push_batch(&mut self, messages: Vec<Message>)
pub fn push_batch(&mut self, messages: Vec<Message>)
Add multiple messages in one operation (single timestamp update)
More efficient than multiple push calls when adding many messages.
Sourcepub fn touch(&mut self)
pub fn touch(&mut self)
Explicitly update the timestamp
Call this after bulk operations that don’t update timestamps automatically.
Sourcepub fn has_pending_boundary(&self) -> bool
pub fn has_pending_boundary(&self) -> bool
Whether the conversation has a pending turn boundary.
Returns true if the last message is User or ToolResults, meaning
the conversation is waiting for an assistant turn and run_pending can
resume without a new user message.
Sourcepub fn total_tokens(&self) -> u64
pub fn total_tokens(&self) -> u64
Count total tokens used.
Sourcepub fn total_usage(&self) -> Usage
pub fn total_usage(&self) -> Usage
Get total usage statistics for the session.
Sourcepub fn record_usage(&mut self, turn_usage: Usage)
pub fn record_usage(&mut self, turn_usage: Usage)
Update cumulative usage after an LLM call.
Sourcepub fn set_system_prompt(&mut self, prompt: String)
pub fn set_system_prompt(&mut self, prompt: String)
Set a system prompt (adds or replaces System message at start)
Sourcepub fn append_system_context_blocks(
&mut self,
appends: &[PendingSystemContextAppend],
)
pub fn append_system_context_blocks( &mut self, appends: &[PendingSystemContextAppend], )
Append one or more runtime system-context blocks to the canonical system prompt.
Sourcepub fn last_assistant_text(&self) -> Option<String>
pub fn last_assistant_text(&self) -> Option<String>
Get the last assistant message text content.
Sourcepub fn tool_call_count(&self) -> usize
pub fn tool_call_count(&self) -> usize
Count tool calls made
Sourcepub fn set_metadata(&mut self, key: &str, value: Value)
pub fn set_metadata(&mut self, key: &str, value: Value)
Set a metadata value
Sourcepub fn remove_metadata(&mut self, key: &str)
pub fn remove_metadata(&mut self, key: &str)
Remove a metadata value.
Sourcepub fn set_session_metadata(
&mut self,
metadata: SessionMetadata,
) -> Result<(), Error>
pub fn set_session_metadata( &mut self, metadata: SessionMetadata, ) -> Result<(), Error>
Store SessionMetadata in the session metadata map.
Sourcepub fn session_metadata(&self) -> Option<SessionMetadata>
pub fn session_metadata(&self) -> Option<SessionMetadata>
Load SessionMetadata from the session metadata map.
Sourcepub fn set_system_context_state(
&mut self,
state: SessionSystemContextState,
) -> Result<(), Error>
pub fn set_system_context_state( &mut self, state: SessionSystemContextState, ) -> Result<(), Error>
Store durable system-context control state in the session metadata map.
Sourcepub fn system_context_state(&self) -> Option<SessionSystemContextState>
pub fn system_context_state(&self) -> Option<SessionSystemContextState>
Load durable system-context control state from the session metadata map.
Sourcepub fn set_deferred_turn_state(
&mut self,
state: SessionDeferredTurnState,
) -> Result<(), Error>
pub fn set_deferred_turn_state( &mut self, state: SessionDeferredTurnState, ) -> Result<(), Error>
Store durable deferred-turn control state in the session metadata map.
Sourcepub fn deferred_turn_state(&self) -> Option<SessionDeferredTurnState>
pub fn deferred_turn_state(&self) -> Option<SessionDeferredTurnState>
Load durable deferred-turn control state from the session metadata map.
Sourcepub fn set_build_state(&mut self, state: SessionBuildState) -> Result<(), Error>
pub fn set_build_state(&mut self, state: SessionBuildState) -> Result<(), Error>
Store recoverable build-only session state in the session metadata map.
Sourcepub fn build_state(&self) -> Option<SessionBuildState>
pub fn build_state(&self) -> Option<SessionBuildState>
Load recoverable build-only session state from the session metadata map.
Sourcepub fn set_tool_visibility_state(
&mut self,
state: SessionToolVisibilityState,
) -> Result<(), Error>
pub fn set_tool_visibility_state( &mut self, state: SessionToolVisibilityState, ) -> Result<(), Error>
Store durable tool-visibility control state in the session metadata map.
Sourcepub fn tool_visibility_state(&self) -> Option<SessionToolVisibilityState>
pub fn tool_visibility_state(&self) -> Option<SessionToolVisibilityState>
Load durable tool-visibility control state from the session metadata map.
Store typed mob operator authority inside canonical build-state metadata.
Load typed mob operator authority from canonical build-state metadata.