@nhtio/adk/batteries/context/compact/contracts
Structural contracts for the Compact (summarize-over-threshold) context-management battery — the seams it invokes via injected functions, and the one cost-observability shape it hands back.
Remarks
This module has zero imports — not even a type-only import from @nhtio/adk core. Same discipline as @nhtio/adk/batteries/context/thrift/contracts: every capability this battery cannot perform itself is an INJECTED function, and every shape it reads or writes is a local structural declaration.
Compact needs exactly TWO capabilities it cannot bundle itself:
- Summarization (SummarizeFn) — an actual model call. Unlike Token Thrift, which is a zero-model-call algorithm end-to-end, Compact's entire thesis is PAYING for a model call to compress old turns into a running summary — so this seam is unavoidable, and the battery never pretends otherwise.
- Token estimation (EstimateTokensFn, re-exported from @nhtio/adk/batteries/context/thrift/contracts — same signature, same rationale: no bundled tokenizer, ever).
Interfaces
| Interface | Description |
|---|---|
| CompactionCostEvent | 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). |
Type Aliases
| Type Alias | Description |
|---|---|
| OnCostFn | 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. |
| SummarizeFn | THE model-call seam this battery cannot perform itself: given a system prompt and a body of text to summarize, return the summary text. |
References
EstimateTokensFn
Re-exports EstimateTokensFn