Skip to content
1 min read · 272 words

Interface: CompactionCostEvent ​

Defined in: src/batteries/context/compact/contracts.ts:94

One summarization call's estimated token cost — reported via OnCostFn so a caller can total up the real overhead this battery pays (the cost profile a thrift-only pipeline never incurs).

Remarks ​

inTok/outTok are ESTIMATES, not metered usage: when the injected SummarizeFn's transport doesn't report real token usage back (many don't — a bare Promise<string> return carries no usage envelope), the battery has no other way to know what the call cost. It measures what it CAN measure — the exact text it sent (system + text) and the exact text it got back (the summary) — via the same injected EstimateTokensFn the caller already supplies for its own token accounting, so these numbers are at least self-consistent with whatever budget arithmetic the caller runs elsewhere. A caller whose SummarizeFn DOES have access to real usage counts can ignore this estimate and total its own numbers from inside the function instead.

Properties ​

PropertyTypeDescriptionDefined in
callsnumberHow many summarization calls this event represents — always 1 per OnCostFn firing (one call, one event); a caller totals calls across events to get the run's summarizer call count.src/batteries/context/compact/contracts.ts:97
inToknumberEstimated input token cost: estimateTokens(system + text, encoding) for the exact request sent to SummarizeFn this call (system prompt plus the history/prior-summary text).src/batteries/context/compact/contracts.ts:100
outToknumberEstimated output token cost: estimateTokens(summary, encoding) for the text SummarizeFn returned.src/batteries/context/compact/contracts.ts:103