pub trait BlockCompactionStrategy: Send + Sync {
// Required methods
fn keep_first(
&self,
record: &LoopRecord,
turn_map: &TurnMap,
config: &CompactionConfig,
) -> Option<TurnRange>;
fn keep_recent(
&self,
record: &LoopRecord,
turn_map: &TurnMap,
config: &CompactionConfig,
) -> Option<CompactedSection>;
fn keep_compacted(
&self,
record: &LoopRecord,
turn_map: &TurnMap,
config: &CompactionConfig,
is_most_recent: bool,
) -> Option<CompactedSection>;
// Provided method
fn compact(
&self,
record: &LoopRecord,
config: &CompactionConfig,
is_most_recent: bool,
) -> CompactionBlock { ... }
}Expand description
Strategy for creating non-destructive CompactionBlock overlays.
Three methods produce the three sections of a CompactionBlock:
keep_first: turns kept verbatim from the startkeep_recent: recent turns with truncated tool outputskeep_compacted: fully summarised section
The default compact() method assembles them. Override individual methods
to customise specific sections (e.g. LLM-based summarisation for keep_compacted).
Required Methods§
Sourcefn keep_first(
&self,
record: &LoopRecord,
turn_map: &TurnMap,
config: &CompactionConfig,
) -> Option<TurnRange>
fn keep_first( &self, record: &LoopRecord, turn_map: &TurnMap, config: &CompactionConfig, ) -> Option<TurnRange>
Determine the keep_first section: turns kept verbatim from the start. Only called for the most recent loop.
Sourcefn keep_recent(
&self,
record: &LoopRecord,
turn_map: &TurnMap,
config: &CompactionConfig,
) -> Option<CompactedSection>
fn keep_recent( &self, record: &LoopRecord, turn_map: &TurnMap, config: &CompactionConfig, ) -> Option<CompactedSection>
Create the keep_recent section: recent turns with truncated tool outputs. Only called for the most recent loop.
Sourcefn keep_compacted(
&self,
record: &LoopRecord,
turn_map: &TurnMap,
config: &CompactionConfig,
is_most_recent: bool,
) -> Option<CompactedSection>
fn keep_compacted( &self, record: &LoopRecord, turn_map: &TurnMap, config: &CompactionConfig, is_most_recent: bool, ) -> Option<CompactedSection>
Create the keep_compacted section: fully summarised turns. For most recent loop: summarises the middle (between keep_first and keep_recent). For older loops: summarises the entire loop.
Implementations should aim to summarise ALL turns in the range within
config.max_summary_tokens — e.g. shorter per-turn summaries or an
LLM-generated holistic digest. The token budget is for the total output,
not a per-turn limit.
Provided Methods§
Sourcefn compact(
&self,
record: &LoopRecord,
config: &CompactionConfig,
is_most_recent: bool,
) -> CompactionBlock
fn compact( &self, record: &LoopRecord, config: &CompactionConfig, is_most_recent: bool, ) -> CompactionBlock
Assemble a CompactionBlock from the three sections.
Default implementation calls the three methods above.