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:
| Strategy | What it does |
|---|---|
DropReasoningStrategy | Strips reasoning parts from items |
DropFailedToolResultsStrategy | Removes errored tool results |
KeepRecentStrategy | Keeps only the N most recent removable items |
SummarizeOlderStrategy | Replaces 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§
Sourcefn 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,
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.