Function: assembleCompactedTurns()
function assembleCompactedTurns<M, TC>(
turns: readonly HistoryTurn<M, TC>[],
options: AssembleCompactedTurnsOptions,
): Promise<AssembleCompactedTurnsResult<M, TC>>;Defined in: src/batteries/context/compact/summarizer.ts:260
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].
Type Parameters
| Type Parameter | Default type |
|---|---|
M extends RelevanceMessage | RelevanceMessage |
TC extends RelevanceToolCall | RelevanceToolCall |
Parameters
| Parameter | Type | Description |
|---|---|---|
turns | readonly HistoryTurn<M, TC>[] | The full grouped history, chronological (e.g. from @nhtio/adk/batteries/context/thrift/relevance!groupHistoryIntoTurns). |
options | AssembleCompactedTurnsOptions | See AssembleCompactedTurnsOptions. |
Returns
Promise<AssembleCompactedTurnsResult<M, TC>>
See AssembleCompactedTurnsResult.
Remarks
Faithfulness to the original (#assembleCompactedTurns): the threshold/keep-verbatim/rolling logic is a line-for-line port — same re-summarize condition (older.length > coveredOlder && (summary === null || olderTokens > summariseAtTokens)), same synthetic turn shape (qa = the summary text, createdAt = the epoch-zero sentinel that sorts before every real turn, one message with id: summaryMessageId, content prefixed [Earlier conversation, compacted summary], no tool calls), same "nothing to compact yet" early return when there's no older region at all. The ONE deviation: state that lived on private class fields (#compactSummary, #compactCoveredOlder) in the original is now explicit input/output (options.priorState in, { summary, coveredOlder } out) — a pure battery function cannot own mutable instance state, so the caller threads it through. This is a mechanical decoupling change, not a behavioral one: a caller who persists and re-supplies priorState exactly as returned reproduces the original's stateful behavior turn-for-turn.
Unlike Token Thrift, this function CANNOT resurface the exact older detail a later turn needs — it only has the summary's blurred prose. See the module barrel for the honest, both-ways evaluation of that fidelity trade-off against thrift's subtractive approach.
Throws
@nhtio/adk/batteries/context/exceptions!E_CONTEXT_RESOLVER_MISSING When options.summarize or options.estimateTokens is not a function.