Skip to main content

Module compaction

Module compaction 

Source
Expand description

Context compaction — LLM-driven conversation summarisation.

When a conversation approaches the model’s context window, older messages are summarised by a smaller/cheaper “compaction” LLM call into a structured anchored summary. This frees context tokens while preserving the semantic continuity of the conversation.

§Sub-modules

  • select — Turn-based message selection (head vs tail).
  • prompt — Anchored summary prompt template.
  • overflow — Context overflow detection.
  • prune — Old tool output pruning.

§Architecture

compact_if_needed() / compact_after_overflow()
  ├── overflow::is_overflow()      — detect if compaction is needed
  ├── select::select()             — split messages into head/tail
  ├── prompt::build_prompt()       — construct anchored summary prompt
  └── run_compaction()             — call compaction LLM
      └── store compaction result  — persist compaction messages

Ported from OpenCode V1/V2 compaction infrastructure.

Modules§

overflow
Compact overflow detection.
prompt
Anchored summary prompt template for compaction.
prune
Tool output pruning.
select
Message selection for compaction.

Structs§

CompactionCircuitBreaker
Circuit breaker that gates compaction calls after repeated failures.
CompactionResult
Result of a successful compaction.
CompactionService
Service for LLM-driven conversational context compaction.