pub struct LlmCompressor { /* private fields */ }Expand description
Summarizes old messages using an LLM provider.
Makes exactly one LLM call per compression event. If the call fails, falls back to rule-based pruning (remove oldest non-system messages).
§Example
use traitclaw_core::context_managers::LlmCompressor;
let compressor = LlmCompressor::new(provider);Implementations§
Source§impl LlmCompressor
impl LlmCompressor
Sourcepub fn with_prompt(self, prompt: impl Into<String>) -> Self
pub fn with_prompt(self, prompt: impl Into<String>) -> Self
Set a custom summarization prompt template.
Sourcepub fn with_threshold(self, threshold: f64) -> Self
pub fn with_threshold(self, threshold: f64) -> Self
Set the compression threshold (0.0–1.0).
Sourcepub fn with_keep_recent(self, count: usize) -> Self
pub fn with_keep_recent(self, count: usize) -> Self
Set the number of recent messages to keep verbatim.
Trait Implementations§
Source§impl ContextManager for LlmCompressor
impl ContextManager for LlmCompressor
Source§fn prepare<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 mut Vec<Message>,
context_window: usize,
state: &'life2 mut AgentState,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn prepare<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
messages: &'life1 mut Vec<Message>,
context_window: usize,
state: &'life2 mut AgentState,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Prepare the message list by pruning or compressing if necessary. Read more
Auto Trait Implementations§
impl Freeze for LlmCompressor
impl !RefUnwindSafe for LlmCompressor
impl Send for LlmCompressor
impl Sync for LlmCompressor
impl Unpin for LlmCompressor
impl UnsafeUnpin for LlmCompressor
impl !UnwindSafe for LlmCompressor
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