ContextCompactor

Trait ContextCompactor 

Source
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§

Source

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,

Compact a list of messages into a summary.

§Errors

Returns an error if summarization fails.

Source

fn estimate_tokens(&self, messages: &[Message]) -> usize

Estimate tokens for a message list.

Source

fn needs_compaction(&self, messages: &[Message]) -> bool

Check if compaction is needed.

Source

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.

Implementors§