pub trait ContextStrategy: Send + Sync {
// Required methods
fn token_estimate(&self, messages: &[ProviderMessage]) -> usize;
fn should_compact(&self, messages: &[ProviderMessage], limit: usize) -> bool;
fn compact(&self, messages: Vec<ProviderMessage>) -> Vec<ProviderMessage>;
}Expand description
Strategy for managing context window size.
Implementations: NoCompaction (passthrough), SlidingWindow
(drop oldest messages), Summarization (future).
Required Methods§
Sourcefn token_estimate(&self, messages: &[ProviderMessage]) -> usize
fn token_estimate(&self, messages: &[ProviderMessage]) -> usize
Estimate token count for a message list.
Sourcefn 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.
Sourcefn compact(&self, messages: Vec<ProviderMessage>) -> Vec<ProviderMessage>
fn compact(&self, messages: Vec<ProviderMessage>) -> Vec<ProviderMessage>
Compact the message list. Returns a shorter list.