Skip to main content

BlockCompactionStrategy

Trait BlockCompactionStrategy 

Source
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 start
  • keep_recent: recent turns with truncated tool outputs
  • keep_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§

Source

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.

Source

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.

Source

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§

Source

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§