pub struct ContextCompressor { /* private fields */ }Implementations§
Source§impl ContextCompressor
impl ContextCompressor
pub fn new(config: ContextCompressionConfig, context_window: usize) -> Self
Sourcepub fn with_memory(self, memory: Arc<dyn Memory>) -> Self
pub fn with_memory(self, memory: Arc<dyn Memory>) -> Self
Attach a memory handle so compression summaries are persisted before old messages are discarded. Without this, compressed facts are lost.
Sourcepub fn set_context_window(&mut self, window: usize)
pub fn set_context_window(&mut self, window: usize)
Update the context window size (e.g. after error-driven probing).
Sourcepub async fn compress_if_needed(
&self,
history: &mut Vec<ChatMessage>,
model_provider: &dyn ModelProvider,
model: &str,
temperature: Option<f64>,
) -> Result<CompressionResult>
pub async fn compress_if_needed( &self, history: &mut Vec<ChatMessage>, model_provider: &dyn ModelProvider, model: &str, temperature: Option<f64>, ) -> Result<CompressionResult>
Main entry point. Compresses history in-place if over threshold.
temperature is forwarded verbatim to the summarizer LLM call.
Pass None to let the provider decide (required for models that
reject temperature, e.g. claude-opus-4-7).
Sourcepub async fn compress_on_error(
&mut self,
history: &mut Vec<ChatMessage>,
model_provider: &dyn ModelProvider,
model: &str,
temperature: Option<f64>,
error_msg: &str,
) -> Result<bool>
pub async fn compress_on_error( &mut self, history: &mut Vec<ChatMessage>, model_provider: &dyn ModelProvider, model: &str, temperature: Option<f64>, error_msg: &str, ) -> Result<bool>
Reactive compression triggered by a context_length_exceeded error. Parses the actual limit from the error, steps down probe tiers, and re-compresses.
Auto Trait Implementations§
impl Freeze for ContextCompressor
impl !RefUnwindSafe for ContextCompressor
impl Send for ContextCompressor
impl Sync for ContextCompressor
impl Unpin for ContextCompressor
impl UnsafeUnpin for ContextCompressor
impl !UnwindSafe for ContextCompressor
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more