pub struct Conversation { /* private fields */ }Expand description
Manages the full conversation history.
Implementations§
Source§impl Conversation
impl Conversation
pub fn new() -> Self
Sourcepub fn with_system_prompt(system_prompt: &str) -> Self
pub fn with_system_prompt(system_prompt: &str) -> Self
Create a new conversation with a system prompt.
Sourcepub fn add_system(&mut self, content: &str)
pub fn add_system(&mut self, content: &str)
Add a system message.
Sourcepub fn add_assistant(&mut self, content: &str, tool_calls: Vec<ToolCall>)
pub fn add_assistant(&mut self, content: &str, tool_calls: Vec<ToolCall>)
Add an assistant message (model output).
Sourcepub fn add_tool_result(&mut self, call: ToolCall, result: ToolResult)
pub fn add_tool_result(&mut self, call: ToolCall, result: ToolResult)
Add a tool result message.
Sourcepub fn to_chat_messages(&self) -> Vec<ChatMessage>
pub fn to_chat_messages(&self) -> Vec<ChatMessage>
Convert conversation to ChatMessage slice for the llama-cpp-v3 template engine.
pub fn is_empty(&self) -> bool
Sourcepub fn compact(&mut self, summary: &str, keep_recent: usize)
pub fn compact(&mut self, summary: &str, keep_recent: usize)
Compact the conversation by summarizing older messages.
Keeps the system prompt and the last keep_recent messages,
replacing everything in between with a summary message.
Sourcepub fn find_safe_cut_point(&self, target_idx: usize) -> usize
pub fn find_safe_cut_point(&self, target_idx: usize) -> usize
Find a safe cut point at or before target_idx.
A safe cut point is a turn boundary where we don’t split an assistant
message from its following tool-result messages. We walk backward from
target_idx to find the start of a complete turn.
Sourcepub fn serialize_range(&self, from: usize, to: usize) -> String
pub fn serialize_range(&self, from: usize, to: usize) -> String
Serialize messages in a range to a human-readable string for summarization by the model.
Sourcepub fn compactable_count(&self, keep_recent: usize) -> usize
pub fn compactable_count(&self, keep_recent: usize) -> usize
Count of messages that would be compacted (everything between system
prompt and the last keep_recent messages).