Skip to main content

Conversation

Struct Conversation 

Source
pub struct Conversation { /* private fields */ }
Expand description

Manages the full conversation history.

Implementations§

Source§

impl Conversation

Source

pub fn new() -> Self

Source

pub fn with_system_prompt(system_prompt: &str) -> Self

Create a new conversation with a system prompt.

Source

pub fn add_system(&mut self, content: &str)

Add a system message.

Source

pub fn add_user(&mut self, content: &str)

Add a user message.

Source

pub fn add_assistant(&mut self, content: &str, tool_calls: Vec<ToolCall>)

Add an assistant message (model output).

Source

pub fn add_tool_result(&mut self, call: ToolCall, result: ToolResult)

Add a tool result message.

Source

pub fn to_chat_messages(&self) -> Vec<ChatMessage>

Convert conversation to ChatMessage slice for the llama-cpp-v3 template engine.

Source

pub fn messages(&self) -> &[Message]

Get all messages.

Source

pub fn clear(&mut self)

Clear all messages.

Source

pub fn len(&self) -> usize

Number of messages in the conversation.

Source

pub fn is_empty(&self) -> bool

Source

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.

Source

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.

Source

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.

Source

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).

Trait Implementations§

Source§

impl Default for Conversation

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.