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
impl MessageWindow
Sourcepub fn new(max_turns: usize, paired_protect: bool) -> Self
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.
Sourcepub fn try_new(
max_turns: usize,
paired_protect: bool,
) -> Result<Self, WindowError>
pub fn try_new( max_turns: usize, paired_protect: bool, ) -> Result<Self, WindowError>
Try to create; returns Err if max_turns < 1.
pub fn max_turns(&self) -> usize
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn evicted_count(&self) -> usize
Sourcepub fn messages_owned(&self) -> Vec<Value>
pub fn messages_owned(&self) -> Vec<Value>
Cloned owned snapshot.
pub fn clear(&mut self)
Sourcepub fn add(&mut self, message: Value) -> Result<(), WindowError>
pub fn add(&mut self, message: Value) -> Result<(), WindowError>
Append a message and evict-to-fit.
Sourcepub fn extend(
&mut self,
messages: impl IntoIterator<Item = Value>,
) -> Result<(), WindowError>
pub fn extend( &mut self, messages: impl IntoIterator<Item = Value>, ) -> Result<(), WindowError>
Add multiple messages in order.
Auto Trait Implementations§
impl Freeze for MessageWindow
impl RefUnwindSafe for MessageWindow
impl Send for MessageWindow
impl Sync for MessageWindow
impl Unpin for MessageWindow
impl UnsafeUnpin for MessageWindow
impl UnwindSafe for MessageWindow
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more