Skip to main content

CompactionStrategy

Trait CompactionStrategy 

Source
pub trait CompactionStrategy: Send + Sync {
    // Required method
    fn apply<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        request: CompactionRequest,
        ctx: &'life1 mut CompactionContext<'life2>,
    ) -> Pin<Box<dyn Future<Output = Result<CompactionResult, CompactionError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

A single compaction step that transforms a transcript.

Strategies are the core abstraction in this crate. Each strategy receives the transcript inside a CompactionRequest and returns a CompactionResult with the (possibly shorter) transcript.

Built-in strategies:

StrategyWhat it does
DropReasoningStrategyStrips reasoning parts from items
DropFailedToolResultsStrategyRemoves errored tool results
KeepRecentStrategyKeeps only the N most recent removable items
SummarizeOlderStrategyReplaces older items with a backend-generated summary

Use CompactionPipeline to chain multiple strategies together.

§Example

use agentkit_compaction::DropReasoningStrategy;

// Strategies are composable via CompactionPipeline
let strategy = DropReasoningStrategy::new();

Required Methods§

Source

fn apply<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, request: CompactionRequest, ctx: &'life1 mut CompactionContext<'life2>, ) -> Pin<Box<dyn Future<Output = Result<CompactionResult, CompactionError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Apply this strategy to the transcript in request.

§Arguments
  • request - The transcript and session context to compact.
  • ctx - Runtime context providing the backend, metadata, and cancellation token.
§Errors

Returns CompactionError on failure or cancellation.

Implementors§