CompactionConfig
Defined in: agent/compaction/config.ts:70
Configuration for the context compaction system.
Example
Section titled “Example”// Custom configurationconst agent = await LLMist.createAgent() .withModel('sonnet') .withCompaction({ triggerThresholdPercent: 70, targetPercent: 40, preserveRecentTurns: 10, }) .ask('...');
// Disable compactionconst agent = await LLMist.createAgent() .withModel('sonnet') .withoutCompaction() .ask('...');Properties
Section titled “Properties”enabled?
Section titled “enabled?”
optionalenabled:boolean
Defined in: agent/compaction/config.ts:75
Enable or disable compaction.
Default
Section titled “Default”trueonCompaction()?
Section titled “onCompaction()?”
optionalonCompaction: (event) =>void
Defined in: agent/compaction/config.ts:127
Callback invoked when compaction occurs. Useful for logging or analytics.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
preserveRecentTurns?
Section titled “preserveRecentTurns?”
optionalpreserveRecentTurns: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.
Default
Section titled “Default”5strategy?
Section titled “strategy?”
optionalstrategy: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
Default
Section titled “Default”'hybrid'summarizationModel?
Section titled “summarizationModel?”
optionalsummarizationModel:string
Defined in: agent/compaction/config.ts:115
Model to use for summarization. If not specified, uses the agent’s model.
Default
Section titled “Default”undefined (uses agent's model)summarizationPrompt?
Section titled “summarizationPrompt?”
optionalsummarizationPrompt:string
Defined in: agent/compaction/config.ts:121
Custom system prompt for summarization. If not specified, uses a default prompt optimized for context preservation.
targetPercent?
Section titled “targetPercent?”
optionaltargetPercent:number
Defined in: agent/compaction/config.ts:100
Target context usage percentage after compaction. The compaction will aim to reduce tokens to this percentage.
Default
Section titled “Default”50triggerThresholdPercent?
Section titled “triggerThresholdPercent?”
optionaltriggerThresholdPercent: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.
Default
Section titled “Default”80