pub trait ContextCompactor: Send + Sync {
// Required methods
fn compact<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn estimate_tokens(&self, messages: &[Message]) -> usize;
fn needs_compaction(&self, messages: &[Message]) -> bool;
fn compact_history<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
) -> Pin<Box<dyn Future<Output = Result<CompactionResult>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Trait for context compaction strategies.
Implement this trait to provide custom compaction logic.
Required Methods§
Sourcefn compact<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn compact<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Sourcefn estimate_tokens(&self, messages: &[Message]) -> usize
fn estimate_tokens(&self, messages: &[Message]) -> usize
Estimate tokens for a message list.
Sourcefn needs_compaction(&self, messages: &[Message]) -> bool
fn needs_compaction(&self, messages: &[Message]) -> bool
Check if compaction is needed.
Sourcefn compact_history<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
) -> Pin<Box<dyn Future<Output = Result<CompactionResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn compact_history<'life0, 'async_trait>(
&'life0 self,
messages: Vec<Message>,
) -> Pin<Box<dyn Future<Output = Result<CompactionResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Perform full compaction, returning new message history.
§Errors
Returns an error if compaction fails.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".