Skip to content
3 min read · 550 words

@nhtio/adk/batteries/context

Aggregate barrel for bundled context-management batteries — strategies for fitting a large working set of messages, memories, retrievables, thoughts, and tools into a model's context window.

Remarks

A context-management battery answers one question: given more candidate content than a dispatch's window can hold, what do you send? Different strategies answer this differently, at different costs:

  • thrift (available now, re-exported below): SUBTRACTIVE — start with everything reasonable, then shed the lowest-signal content first (an image, stale tool results, the RAG tail, low-value memories, old turns, guidance thoughts, then tools as a last resort) until the dispatch fits. Every decision is a measured token comparison; zero extra model calls. See @nhtio/adk/batteries/context/thrift for the full algorithm and its head-to-head evaluation results.
  • compact (available now, re-exported below): SUMMARIZING — instead of shedding old turns outright, pay for a model call to compress them into a running summary message, trading a real API cost for retaining compressed signal from everything folded away. thrift already carries the one hook compact needs to coexist with it (the isSummaryMessage predicate on @nhtio/adk/batteries/context/thrift/subtractive_pass!SubtractToFitOptions), so a caller can run compact upstream and thrift downstream in the same pipeline without the two strategies fighting over the same running-summary message. See @nhtio/adk/batteries/context/compact for the full algorithm and its head-to-head evaluation results.

These are genuinely different trade-offs, not tiers of the same idea — thrift is the cost-optimal, always-available default; compact is the strategy to reach for when a project can afford (and benefits from, per the honest head-to-head result documented in the thrift battery barrel) paying for compression on top of subtraction. Both are meant to be composable, not mutually exclusive.

References

argText

Re-exports argText


assembleCompactedTurns

Re-exports assembleCompactedTurns


AssembleCompactedTurnsOptions

Re-exports AssembleCompactedTurnsOptions


AssembleCompactedTurnsResult

Re-exports AssembleCompactedTurnsResult


BucketTrace

Re-exports BucketTrace


COMPACTION_SYSTEM_PROMPT

Re-exports COMPACTION_SYSTEM_PROMPT


CompactionCostEvent

Re-exports CompactionCostEvent


ContentLike

Re-exports ContentLike


contentTokens

Re-exports contentTokens


DEFAULT_ENCODING

Re-exports DEFAULT_ENCODING


DEFAULT_KEEP_VERBATIM

Re-exports DEFAULT_KEEP_VERBATIM


DEFAULT_RESERVE_FRACTION

Re-exports DEFAULT_RESERVE_FRACTION


DEFAULT_SUMMARISE_AT_TOKENS

Re-exports DEFAULT_SUMMARISE_AT_TOKENS


DEFAULT_SUMMARY_MESSAGE_ID

Re-exports DEFAULT_SUMMARY_MESSAGE_ID


DEFAULT_THIS_TURN_RESULT_KEEP

Re-exports DEFAULT_THIS_TURN_RESULT_KEEP


E_CONTEXT_RESOLVER_MISSING

Re-exports E_CONTEXT_RESOLVER_MISSING


Estimable

Re-exports Estimable


EstimateTokensFn

Re-exports EstimateTokensFn


EstimatorOptions

Re-exports EstimatorOptions


groupHistoryIntoTurns

Re-exports groupHistoryIntoTurns


HistoryTurn

Re-exports HistoryTurn


IsEphemeralMessageFn

Re-exports IsEphemeralMessageFn


IsSummaryMessageFn

Re-exports IsSummaryMessageFn


MillisTimestamp

Re-exports MillisTimestamp


OnCostFn

Re-exports OnCostFn


RELEVANCE_FLOOR_CURVE

Re-exports RELEVANCE_FLOOR_CURVE


RELEVANCE_FLOOR_MAX

Re-exports RELEVANCE_FLOOR_MAX


RELEVANCE_FLOOR_MIN

Re-exports RELEVANCE_FLOOR_MIN


RelevanceMessage

Re-exports RelevanceMessage


RelevanceToolCall

Re-exports RelevanceToolCall


relevanceToQuery

Re-exports relevanceToQuery


RenderToolsFn

Re-exports RenderToolsFn


resolveBudget

Re-exports resolveBudget


scaledRelevanceFloor

Re-exports scaledRelevanceFloor


selectNaiveTurns

Re-exports selectNaiveTurns


SelectNaiveTurnsOptions

Re-exports SelectNaiveTurnsOptions


selectRelevantTurns

Re-exports selectRelevantTurns


SelectRelevantTurnsOptions

Re-exports SelectRelevantTurnsOptions


ShedRankFn

Re-exports ShedRankFn


stripPriorTurnThoughts

Re-exports stripPriorTurnThoughts


subtractToFit

Re-exports subtractToFit


SubtractToFitOptions

Re-exports SubtractToFitOptions


summariseTurns

Re-exports summariseTurns


SummariseTurnsOptions

Re-exports SummariseTurnsOptions


SummarizeFn

Re-exports SummarizeFn


ThriftTrace

Re-exports ThriftTrace


WorkingImage

Re-exports WorkingImage


WorkingMemory

Re-exports WorkingMemory


WorkingMessage

Re-exports WorkingMessage


WorkingRetrievable

Re-exports WorkingRetrievable


WorkingSet

Re-exports WorkingSet


WorkingThought

Re-exports WorkingThought


WorkingTool

Re-exports WorkingTool


WorkingToolCall

Re-exports WorkingToolCall


WorkingToolRegistry

Re-exports WorkingToolRegistry