agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
48 lines (47 loc) • 2.19 kB
TypeScript
/**
* tokenBudget — compaction's trigger discipline, without the summarizer.
*
* Pattern: WindowStrategy implementation. Its own module, registering
* nothing at import.
* Role: core/ layer.
* Emits: N/A — the stage emits, records and costs; this file decides.
*
* The market's other familiar policy: cap the window at a token budget
* (Mastra's `TokenLimiter` is the closest sibling). What is different here is
* the same thing that is different about compaction — the number is COUNTED,
* never guessed:
*
* • the trigger reads the input tokens the PROVIDER reported for the last
* call, not a character estimate and not a divide-by-four heuristic;
* • a provider that reports no usage gets `CompactionUnmeasurableError` by
* name, the same refusal `.compaction()` makes, rather than an invented
* window size or a configured budget that silently never applies.
*
* When over budget it drops the oldest contiguous removable span — the same
* span compaction would have folded, chosen by the same refusal engine — and
* writes no summary at all. Nothing is claimed about what left, because
* nothing was read: the record and the eviction events name it, and the
* commit log still has it verbatim.
*
* Use it over `summarizeOldest` when you would rather lose the old turns than
* pay a summarizer to paraphrase them, and over `slidingWindow` when the
* thing you are actually defending is a token bill rather than a turn depth.
*/
import type { WindowStrategy } from '../strategy.js';
import type { TokenBudgetOptions } from '../types.js';
/** `WindowRecord.strategy` written by every record this strategy files. */
export declare const TOKEN_BUDGET = "token-budget";
/**
* Drop the oldest turns whenever the last call's adapter-reported input
* tokens exceed `thresholdTokens`.
*
* @example
* ```ts
* import { Agent, tokenBudget } from 'agentfootprint';
*
* const agent = Agent.create({ provider: anthropic(), model: 'claude-sonnet-4-5' })
* .window(tokenBudget({ thresholdTokens: 120_000 }))
* .build();
* ```
*/
export declare function tokenBudget(options: TokenBudgetOptions): WindowStrategy;