Skip to content
1 min read · 137 words

Type Alias: OnCostFn ​

ts
type OnCostFn = (event: CompactionCostEvent) => void;

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

Optional per-summarization cost callback — fired once per SummarizeFn call that actually runs, replacing the production flagship agent's globalThis.__agentCompactionCost ring buffer with an injectable, testable seam that leaves no global state behind.

Parameters ​

ParameterTypeDescription
eventCompactionCostEventSee CompactionCostEvent.

Returns ​

void

Remarks ​

Never invoked when the threshold hasn't been crossed (no summarization call made — see @nhtio/adk/batteries/context/compact/summarizer!assembleCompactedTurns's below-threshold pass-through path). A caller who wants a running total across a whole session's worth of dispatches accumulates across onCost firings themselves; this battery holds no cross-call state of its own beyond what a single assembleCompactedTurns invocation's caller threads through (the rolling prior summary is passed in and returned explicitly, never stashed on globalThis).