pub struct ChatSession {
pub session_id: Uuid,
pub system: Option<String>,
pub messages: Vec<Message>,
pub cache_strategy: CacheStrategy,
}Expand description
Conversation state.
Fields§
§session_id: Uuid§system: Option<String>Optional system prompt.
messages: Vec<Message>Message history in normalized form.
cache_strategy: CacheStrategyCache-injection strategy.
Implementations§
Source§impl ChatSession
impl ChatSession
pub fn new() -> Self
pub fn with_system(self, system: impl Into<String>) -> Self
pub fn with_cache_strategy(self, strategy: CacheStrategy) -> Self
Sourcepub fn push_assistant(&mut self, response: NormalizedResponse)
pub fn push_assistant(&mut self, response: NormalizedResponse)
Append the assistant’s response content blocks verbatim.
Sourcepub fn push_tool_results(&mut self, results: Vec<ToolResultMessage>)
pub fn push_tool_results(&mut self, results: Vec<ToolResultMessage>)
Append tool results as a single user message containing
ContentBlock::ToolResult blocks. Providers translate the exact
shape at the wire layer.
Sourcepub fn append_to_last_user(&mut self, text: impl Into<String>)
pub fn append_to_last_user(&mut self, text: impl Into<String>)
Append text to the tail of the most recent user message as a new
ContentBlock::Text block. Used for mid-turn injections (stream
rules) that must NOT create a bare user message after tool results
(provider alternation rules — spec D7). Falls back to pushing a new
user message when no user message exists; that only happens with an
empty, system-only, or assistant-only history, where a user message
is alternation-safe.
Caller contract: intended for mid-turn injection while the tail message is a user message (before any assistant commit). If the tail is an assistant message, the text lands on an older user message mid-history.
pub fn is_empty(&self) -> bool
Sourcepub fn compress(
&mut self,
target_tokens: u32,
compressor: &dyn HistoryCompressor,
tokenizer: &dyn Tokenizer,
) -> u32
pub fn compress( &mut self, target_tokens: u32, compressor: &dyn HistoryCompressor, tokenizer: &dyn Tokenizer, ) -> u32
Compress history in place to fit within target_tokens using the
provided compressor and tokenizer. Returns the token count after
compression (may still exceed target_tokens if no further moves
were safe).
Sourcepub fn save(&self, path: &Path) -> Result<(), ClassifiedError>
pub fn save(&self, path: &Path) -> Result<(), ClassifiedError>
Persist the session to disk as JSON (supports /resume).
Sourcepub fn load(path: &Path) -> Result<Self, ClassifiedError>
pub fn load(path: &Path) -> Result<Self, ClassifiedError>
Load a session from disk.
Trait Implementations§
Source§impl Clone for ChatSession
impl Clone for ChatSession
Source§fn clone(&self) -> ChatSession
fn clone(&self) -> ChatSession
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more