agentkit-compaction
Transcript compaction primitives for reducing context size while preserving useful state.
This crate includes:
- Triggers (
CompactionTrigger,ItemCountTrigger) that decide when compaction should run - Strategies (
DropReasoningStrategy,DropFailedToolResultsStrategy,KeepRecentStrategy,SummarizeOlderStrategy) that drop, keep, or summarize transcript items - Backends (
CompactionBackend) for provider-backed summarization - Pipelines (
CompactionPipeline) for composing multiple compaction steps into a single pass
Use it from agentkit-loop or your own runtime when you need to trim older transcript state without losing essential context.
Quick start
Combine a trigger with a multi-step pipeline to build a CompactionConfig:
use ;
use ItemKind;
// Trigger compaction once the transcript exceeds 32 items.
let trigger = new;
// Build a pipeline that:
// 1. Strips chain-of-thought reasoning parts
// 2. Removes failed tool results
// 3. Keeps only the 24 most recent items (preserving system/context)
let pipeline = new
.with_strategy
.with_strategy
.with_strategy;
let config = new;
assert!;
Using a summarization backend
When you want older items to be condensed rather than dropped, use
SummarizeOlderStrategy together with a CompactionBackend:
use ;
use ;
use async_trait;
;
let config = new
.with_backend;
assert!;
Checking the trigger manually
You can query the trigger yourself outside of the agent loop:
use ;
use SessionId;
let trigger = new;
let transcript = Vecnew;
assert!;