v0.6.0 — Compactor trait, StrategyCompactor
v0.6.0 — Compactor trait, StrategyCompactor
Compaction gets a single, clean entry point. The old "config + trigger + strategy" trio is replaced by one Compactor trait, with a StrategyCompactor that bundles a trigger closure, a strategy, and an optional summarisation backend. Breaking — hence the 0.6 bump.
What's Changed
Compactor trait + StrategyCompactor
CompactionConfig, CompactionTrigger, ItemCountTrigger, AgentBuilderCompactionExt, and the internal LegacyCompactor wrapper are gone. Register a compactor on the agent builder via the new AgentBuilderCompactorExt::compactor:
use agentkit_compaction::{
AgentBuilderCompactorExt, CompactionPipeline, DropFailedToolResultsStrategy,
DropReasoningStrategy, NestedLoopCompactionBackend, StrategyCompactor,
SummarizeOlderStrategy,
};
use agentkit_loop::Agent;
let compactor = StrategyCompactor::builder()
.item_count_trigger(64)
.strategy(
CompactionPipeline::new()
.with_strategy(DropReasoningStrategy::new())
.with_strategy(DropFailedToolResultsStrategy::new())
.with_strategy(SummarizeOlderStrategy::new(8)),
)
.backend(NestedLoopCompactionBackend { adapter: adapter.clone() })
.build()?;
let agent = Agent::builder()
.model(adapter)
.compactor(compactor)
.build()?;For stateful triggers (e.g. token-window aware), supply a closure that reads external state:
use agentkit_compaction::{CompactionReason, StrategyCompactor, SummarizeOlderStrategy};
let compactor = StrategyCompactor::builder()
.trigger(move |transcript, _point| {
(transcript.len() > 64).then_some(CompactionReason::TranscriptTooLong)
})
.strategy(SummarizeOlderStrategy::new(8))
.build()?;CompactionRequest slimmed down
session_id and turn_id are removed from CompactionRequest — strategies that need session context read it from the surrounding LoopCtx instead. CompactionRequest::for_turn and CompactionRequest::with_turn_id are gone; use CompactionRequest::new(transcript, reason) and .with_metadata(...).
Examples + docs migrated
All four examples/openrouter-* agents (chat, parallel, compaction, context-window-compaction) now use StrategyCompactor. Book chapters ch02/ch03/ch04/ch06/ch16/ch19/ch21/ch22/ch23 rewritten against the new surface.
Clippy pass
12 trivial lints fixed across the workspace: collapsible match/if, unused imports, while let → while, map_or → is_none_or, needless borrows. (One real refactor in cerebras-chat left for a follow-up.)
Migration notes
- Replace
CompactionConfig::new(trigger, strategy).with_backend(...)+.compaction(config)with:let compactor = StrategyCompactor::builder() .trigger(...) // Fn(&[Item], MutationPoint) -> Option<CompactionReason> .strategy(...) // single CompactionStrategy (use CompactionPipeline to chain) .backend(...) // optional, for SummarizeOlderStrategy .build()?; agent_builder.compactor(compactor)
ItemCountTrigger::new(n)→StrategyCompactor::builder().item_count_trigger(n).- Custom
impl CompactionTriggertypes: convert to a closure passed to.trigger(...), or implement the newCompactortrait directly if you need state. CompactionRequest::for_turn(session_id, turn_id, transcript, reason)→CompactionRequest::new(transcript, reason); read session/turn info from the surrounding loop context.AgentBuilderCompactionExtimport paths change toAgentBuilderCompactorExt.
Commits
- refactor(compaction): replace CompactionConfig/Trigger with StrategyCompactor (3226515)
Full Changelog: v0.5.1...v0.6.0