Skip to content

CompactionConfig

Defined in: agent/compaction/config.ts:70

Configuration for the context compaction system.

// Custom configuration
const agent = await LLMist.createAgent()
.withModel('sonnet')
.withCompaction({
triggerThresholdPercent: 70,
targetPercent: 40,
preserveRecentTurns: 10,
})
.ask('...');
// Disable compaction
const agent = await LLMist.createAgent()
.withModel('sonnet')
.withoutCompaction()
.ask('...');

optional enabled: boolean

Defined in: agent/compaction/config.ts:75

Enable or disable compaction.

true

optional onCompaction: (event) => void

Defined in: agent/compaction/config.ts:127

Callback invoked when compaction occurs. Useful for logging or analytics.

CompactionEvent

void


optional preserveRecentTurns: number

Defined in: agent/compaction/config.ts:108

Number of recent turns to preserve during compaction. A “turn” is a user message + assistant response pair. Recent turns are kept verbatim while older ones are summarized/dropped.

5

optional strategy: CompactionStrategy | "sliding-window" | "summarization" | "hybrid"

Defined in: agent/compaction/config.ts:85

The compaction strategy to use.

  • ‘sliding-window’: Fast, drops oldest turns (no LLM call)
  • ‘summarization’: LLM-based compression of old messages
  • ‘hybrid’: Summarizes old messages + keeps recent turns (recommended)
  • Or provide a custom CompactionStrategy instance
'hybrid'

optional summarizationModel: string

Defined in: agent/compaction/config.ts:115

Model to use for summarization. If not specified, uses the agent’s model.

undefined (uses agent's model)

optional summarizationPrompt: string

Defined in: agent/compaction/config.ts:121

Custom system prompt for summarization. If not specified, uses a default prompt optimized for context preservation.


optional targetPercent: number

Defined in: agent/compaction/config.ts:100

Target context usage percentage after compaction. The compaction will aim to reduce tokens to this percentage.

50

optional triggerThresholdPercent: number

Defined in: agent/compaction/config.ts:93

Context usage percentage that triggers compaction. When token count exceeds this percentage of the context window, compaction is performed before the next LLM call.

80