Skip to main content

MessageWindow

Struct MessageWindow 

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

Sliding window over LLM conversation messages.

max_turns controls how many messages are kept. When adding a new message causes overflow, the oldest is evicted first. With paired_protect = true (the default), evicting a tool_use message also evicts any tool_result messages that reference its IDs.

Implementations§

Source§

impl MessageWindow

Source

pub fn new(max_turns: usize, paired_protect: bool) -> Self

Create a new window with max_turns capacity.

paired_protect = true guards Anthropic tool-use / tool-result pairs.

Source

pub fn try_new( max_turns: usize, paired_protect: bool, ) -> Result<Self, WindowError>

Try to create; returns Err if max_turns < 1.

Source

pub fn max_turns(&self) -> usize

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn evicted_count(&self) -> usize

Source

pub fn messages(&self) -> Vec<&Value>

Ordered slice of current messages (oldest → newest).

Source

pub fn messages_owned(&self) -> Vec<Value>

Cloned owned snapshot.

Source

pub fn clear(&mut self)

Source

pub fn add(&mut self, message: Value) -> Result<(), WindowError>

Append a message and evict-to-fit.

Source

pub fn extend( &mut self, messages: impl IntoIterator<Item = Value>, ) -> Result<(), WindowError>

Add multiple messages in order.

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