Skip to content

CompactionConfig

Automatic conversation-history compaction.

Long-running sessions (weeks-long WhatsApp threads) grow unbounded; budget truncation silently loses the early relationship. Compaction summarizes the older history into one system note and keeps the recent tail verbatim, so the model retains facts/decisions without paying the full token cost.

Runs post-turn (off the user’s latency path) when the estimated history tokens exceed triggerTokens, and force-runs as the recovery step after a provider context-overflow error (see contextOverflow.ts).

optional keepRecentMessages?: number;

Number of recent messages kept verbatim. Default: 12.


optional model?: LanguageModel;

Summarizer model. Defaults to the active agent’s controlModel/model.


optional summaryPrompt?: string;

Override the summarizer system prompt.


optional triggerTokens?: number;

Estimated history tokens that trigger compaction. Default: 8000.