Skip to main content

Crate agentkit_compaction

Crate agentkit_compaction 

Source
Expand description

Transcript compaction primitives for reducing context size while preserving useful state.

This crate provides the building blocks for compacting an agent transcript when it grows too large. The main concepts are:

Wire a StrategyCompactor (bundling a trigger closure + strategy + optional backend) into the loop, or implement Compactor directly for stateful triggers.

Structs§

AgentCompactor
CompactionBackend that summarises items by running a nested loop over a sub-agent.
AgentCompactorBuilder
Builder for AgentCompactor.
CompactionContext
Runtime context passed to each CompactionStrategy during execution.
CompactionPipeline
An ordered sequence of CompactionStrategy steps executed one after another.
CompactionRequest
Input to a CompactionStrategy. Carries the transcript plus request metadata so strategies can decide which items to keep, drop, or summarise.
CompactionResult
Output of a CompactionStrategy.
CompactorMutator
Adapts any Compactor to a LoopMutator so it can be registered directly via AgentBuilder::mutator. Most callers reach this through AgentBuilderCompactorExt::compactor rather than constructing it directly.
DropFailedToolResultsStrategy
Strategy that removes Part::ToolResult parts where is_error is true.
DropReasoningStrategy
Strategy that removes Part::Reasoning parts from every item.
KeepRecentStrategy
Strategy that keeps only the N most recent removable items and drops the rest.
StrategyCompactor
A reusable Compactor that bundles a trigger closure with a CompactionStrategy (often a CompactionPipeline) and an optional CompactionBackend. Use this when your trigger logic is a simple predicate over the transcript; implement Compactor directly when you need richer state (token meters, atomics, etc.).
StrategyCompactorBuilder
Builder for StrategyCompactor.
SummarizeOlderStrategy
Strategy that replaces older transcript items with a backend-generated summary.
SummaryRequest
Request sent to a CompactionBackend asking it to summarise a set of transcript items.
SummaryResult
Response from a CompactionBackend containing the summarised items.

Enums§

AgentCompactorBuildError
Builder error for AgentCompactor.
CompactionError
Errors that can occur during compaction.
CompactionReason
The reason a compaction was triggered.
StrategyCompactorBuildError
Builder error for StrategyCompactor.

Traits§

AgentBuilderCompactorExt
Extension trait that adds compactor to AgentBuilder, wrapping any Compactor in a CompactorMutator and registering it via AgentBuilder::mutator.
CompactionBackend
Provider-backed summarisation service.
CompactionStrategy
A single compaction step that transforms a transcript.
Compactor
High-level compaction primitive. Implementations decide whether and how to compact, owning their own derived state (e.g. running token totals behind interior mutability) so the framework doesn’t need to plumb a separate observer or shared atomic.

Functions§

context_window_trigger
Build a trigger closure that fires when the most recent transcript item’s reported usage.tokens.input_tokens reaches window * percent / 100.
item_count_trigger
Build a trigger closure that fires when the transcript grows beyond max_items items. Convenience matching StrategyCompactorBuilder::item_count_trigger.

Type Aliases§

TriggerFn
Boxed predicate driving StrategyCompactor: it inspects the transcript and current MutationPoint and returns the reason to fire compaction, or None to skip.