import type { CompletionRequest } from '../../types/messages.js'; import type { AgentMiddleware } from '../create-agent.js'; /** One cleared result, for a custom placeholder. */ export interface ClearedToolResult { /** The tool whose result was cleared. */ tool: string; /** How long the result was, in characters. */ length: number; } /** What one edit did, for logs and for measuring what it saves. */ export interface ContextEdit { /** Tool results cleared. */ cleared: number; /** The request's estimated tokens before. */ tokensBefore: number; /** And after. */ tokensAfter: number; } /** Options for `contextEditor()`. */ export interface ContextEditorOptions { /** Editing starts once the request's estimated tokens pass this. Defaults to 30,000. */ triggerTokens?: number; /** The most recent tool results, kept whole. Defaults to 3. */ keepToolResults?: number; /** * Results are cleared this many at a time, so the edited prefix stays the same for several calls * and a provider's prompt cache keeps working between edits. Defaults to 5. */ batch?: number; /** Tools whose results are never cleared. */ exclude?: readonly string[]; /** Also empties the arguments of each call whose result is cleared, for tools that take large inputs. */ clearArguments?: boolean; /** What a cleared result says instead. Defaults to a line naming the tool and how to get it back. */ placeholder?: string | ((cleared: ClearedToolResult) => string); /** Estimates a request's tokens. Defaults to about four characters a token. */ estimateTokens?: (request: CompletionRequest) => number; /** Called after each edit. */ onEdit?: (edit: ContextEdit) => void; } /** * Clears old tool results from what the model is sent, once the request grows past a threshold. * * Tool output is most of a long agent's context, and the model rarely needs a result from twenty * steps ago verbatim. Every result but the most recent few is replaced by a short placeholder, in * batches, so the edited prefix stays the same between edits and a provider's prompt cache keeps * working. Only the request changes: the transcript in state keeps every result, and checkpoints, * events, and a later summary still see them. */ export declare function contextEditor(options?: ContextEditorOptions): AgentMiddleware; /** About four characters a token, over the messages, the tool calls, and the tool schemas. */ export declare function estimateRequestTokens(request: CompletionRequest): number;