@nhtio/adk/batteries/context/compact/summarizer
The Compact summarizer and history assembler — the whole Compact thesis, in code.
Remarks
This is a direct extraction of the flagship reference agent's #summariseTurns / #assembleCompactedTurns head-to-head baseline (the "compact" arm evaluated against Token Thrift — see the battery barrel's TSDoc for the honest, both-ways evaluation results), retargeted at the local structural contracts in @nhtio/adk/batteries/context/compact/contracts and the shared @nhtio/adk/batteries/context/thrift/relevance!HistoryTurn shape so it couples to nothing in @nhtio/adk core — the one true dependency this battery cannot avoid (an actual model call to summarize) is an injected SummarizeFn, never a bundled transport.
Interfaces
| Interface | Description |
|---|---|
| AssembleCompactedTurnsOptions | Options for assembleCompactedTurns. |
| AssembleCompactedTurnsResult | assembleCompactedTurns's return value: the compacted turns PLUS the rolling state a caller must persist and pass back in as options.priorState on the next call (this battery is stateless between calls by design — no private fields, no globalThis). |
| SummariseTurnsOptions | Options for summariseTurns. |
Variables
| Variable | Description |
|---|---|
| COMPACTION_SYSTEM_PROMPT | The FAITHFUL Claude Code compaction schema — the 9 sections extracted VERBATIM from the flagship reference agent's own real auto-compactions (~4700-token structured summaries observed across 28 compactions in that agent's development session). Using the real prompt (not an invented one) is what makes this battery's evaluation honest: the compact strategy loses exactly the detail Claude Code's own compaction loses, no more and no less. |
| DEFAULT_KEEP_VERBATIM | How many of the MOST RECENT turns stay verbatim, never folded into the running summary — coreference ("it", "that file") needs the immediately preceding turns present no matter what. |
| DEFAULT_SUMMARISE_AT_TOKENS | The token threshold, measured over the OLDER (non-verbatim) region's combined text, past which a (re)summarization call fires. |
| DEFAULT_SUMMARY_MESSAGE_ID | The default id assigned to the synthetic summary message assembleCompactedTurns emits. |
Functions
| Function | Description |
|---|---|
| assembleCompactedTurns | The Compact assembly step: keep the newest keepVerbatim turns in full; fold everything OLDER into a running structured summary, (re)generated via summariseTurns when the older region grows past summariseAtTokens AND new turns have aged into it since the last summarization. Returns [syntheticSummaryTurn, ...recentVerbatimTurns]. |
| summariseTurns | Run ONE summarization call: fold priorSummary (if any) and historyText into the request text exactly as the flagship reference agent's #summariseTurns did, dispatch it through the injected SummarizeFn, and report the estimated token cost via options.onCost. |
References
CompactionCostEvent
Re-exports CompactionCostEvent
EstimateTokensFn
Re-exports EstimateTokensFn
HistoryTurn
Re-exports HistoryTurn
OnCostFn
Re-exports OnCostFn
RelevanceMessage
Re-exports RelevanceMessage
RelevanceToolCall
Re-exports RelevanceToolCall
SummarizeFn
Re-exports SummarizeFn