Skip to main content

CompactionStrategy

Trait CompactionStrategy 

Source
pub trait CompactionStrategy: Send + Sync {
    // Required methods
    fn should_compact(
        &self,
        messages: &[ChatMessage],
        context_window_tokens: u64,
    ) -> bool;
    fn compact<'life0, 'life1, 'async_trait>(
        &'life0 self,
        messages: Vec<ChatMessage>,
        ctx: &'life1 CompactionContext,
    ) -> Pin<Box<dyn Future<Output = Result<CompactionOutcome, CompactionError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}

Required Methods§

Source

fn should_compact( &self, messages: &[ChatMessage], context_window_tokens: u64, ) -> bool

Boolean gate. Pure (no side effects). Cheap to call every step.

Source

fn compact<'life0, 'life1, 'async_trait>( &'life0 self, messages: Vec<ChatMessage>, ctx: &'life1 CompactionContext, ) -> Pin<Box<dyn Future<Output = Result<CompactionOutcome, CompactionError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fold history. Caller hands over the full messages list and expects a shorter list back (typically [summary, ...tail]). Failures bubble up; agent_loop treats them as “skip this turn’s compaction” rather than failing the whole turn.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§