pub struct SmartCompressionConfig {
pub trigger_threshold: f32,
pub emergency_threshold: f32,
pub preserve_recent: usize,
pub preserve: PreserveConfig,
pub level: CompressionLevel,
}Expand description
Configuration for smart context compression.
Fields§
§trigger_threshold: f32Trigger compression at this fraction of context window (default: 0.7).
emergency_threshold: f32Emergency compaction threshold (default: 0.9).
preserve_recent: usizeNumber of recent messages to always keep verbatim.
preserve: PreserveConfigTypes of content to preserve during compression.
level: CompressionLevelCompression level (trade-off between quality and size).
Implementations§
Source§impl SmartCompressionConfig
impl SmartCompressionConfig
Sourcepub const COMPACTION_RESERVE: f32 = 0.2
pub const COMPACTION_RESERVE: f32 = 0.2
Reserve 20% of context for the compaction process itself.
Sourcepub fn effective_trigger(&self) -> f32
pub fn effective_trigger(&self) -> f32
Returns the effective trigger threshold accounting for compaction reserve.
The actual trigger is lower than trigger_threshold to leave room
for the fast LLM to see both URLs and original content during compaction.
Sourcepub fn extract_preserved(&self, messages: &[Message]) -> PreservedContent
pub fn extract_preserved(&self, messages: &[Message]) -> PreservedContent
Extract content that should be preserved from messages.
Sourcepub fn find_stale_tool_calls(&self, messages: &[Message]) -> HashSet<usize>
pub fn find_stale_tool_calls(&self, messages: &[Message]) -> HashSet<usize>
Identify indices of stale tool calls that can be safely removed.
Stale tool calls include:
- Tool results that were just acknowledgments
- Read operations for files that were later modified
Sourcepub async fn generate_summary<LLM: LanguageModel>(
&self,
llm: &LLM,
messages: &[Message],
preserved: &PreservedContent,
) -> Result<String, LLM::Error>
pub async fn generate_summary<LLM: LanguageModel>( &self, llm: &LLM, messages: &[Message], preserved: &PreservedContent, ) -> Result<String, LLM::Error>
Generate a compressed summary of messages.
§Errors
Returns an error if the LLM fails to generate a summary.
Sourcepub async fn generate_summary_with_urls<LLM: LanguageModel>(
&self,
llm: &LLM,
messages: &[Message],
preserved: &PreservedContent,
pending_urls: &[ContentWithUrl],
) -> Result<CompactionResult, LLM::Error>
pub async fn generate_summary_with_urls<LLM: LanguageModel>( &self, llm: &LLM, messages: &[Message], preserved: &PreservedContent, pending_urls: &[ContentWithUrl], ) -> Result<CompactionResult, LLM::Error>
Generate a compressed summary with URL tracking for tool outputs.
This method:
- Takes messages and their associated pending URLs
- Generates a summary that may reference those URLs
- Scans the summary to find which URLs were actually referenced
- Returns both the summary and the set of referenced URLs
The caller should only write files for URLs that appear in referenced_urls.
§Arguments
llm- The fast LLM to use for summary generationmessages- Messages to compresspreserved- Content to preserve verbatimpending_urls- Map of message content to allocated URLs
§Errors
Returns an error if the LLM fails to generate a summary.
Trait Implementations§
Source§impl Clone for SmartCompressionConfig
impl Clone for SmartCompressionConfig
Source§fn clone(&self) -> SmartCompressionConfig
fn clone(&self) -> SmartCompressionConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SmartCompressionConfig
impl Debug for SmartCompressionConfig
Auto Trait Implementations§
impl Freeze for SmartCompressionConfig
impl RefUnwindSafe for SmartCompressionConfig
impl Send for SmartCompressionConfig
impl Sync for SmartCompressionConfig
impl Unpin for SmartCompressionConfig
impl UnsafeUnpin for SmartCompressionConfig
impl UnwindSafe for SmartCompressionConfig
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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> ⓘ
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> ⓘ
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