pub struct SlidingWindow { /* private fields */ }Expand description
Sliding window context strategy.
When context exceeds the limit, drops the oldest messages (keeping the first message, which is typically the initial user message).
Implementations§
Source§impl SlidingWindow
impl SlidingWindow
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new sliding window strategy.
chars_per_token controls the token estimation granularity
(default: 4 chars per token).
Sourcepub fn with_ratio(chars_per_token: usize) -> Self
pub fn with_ratio(chars_per_token: usize) -> Self
Create with a custom chars-per-token ratio.
Trait Implementations§
Source§impl ContextStrategy for SlidingWindow
impl ContextStrategy for SlidingWindow
Source§fn token_estimate(&self, messages: &[ProviderMessage]) -> usize
fn token_estimate(&self, messages: &[ProviderMessage]) -> usize
Estimate token count for a message list.
Source§fn should_compact(&self, messages: &[ProviderMessage], limit: usize) -> bool
fn should_compact(&self, messages: &[ProviderMessage], limit: usize) -> bool
Whether compaction should run given the current messages and limit.
Source§fn compact(&self, messages: Vec<ProviderMessage>) -> Vec<ProviderMessage>
fn compact(&self, messages: Vec<ProviderMessage>) -> Vec<ProviderMessage>
Compact the message list. Returns a shorter list.
Auto Trait Implementations§
impl Freeze for SlidingWindow
impl RefUnwindSafe for SlidingWindow
impl Send for SlidingWindow
impl Sync for SlidingWindow
impl Unpin for SlidingWindow
impl UnsafeUnpin for SlidingWindow
impl UnwindSafe for SlidingWindow
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