import type { Message, ToolMessage } from '../types/message/index.js'; /** * Clear stale tool OUTPUT in place, without touching the conversation's * shape. * * Compaction was all-or-nothing: once the threshold hit, every older * message became a summary and the agent's own reasoning — the decisions, * the false starts it learned from, the exact wording of a plan — was * paraphrased away with it. That is a heavy price to pay for a context * problem that is usually caused by something much dumber: a handful of * enormous tool outputs the agent already read, extracted what it needed * from, and moved past. * * Clearing those reclaims most of the same tokens while preserving every * message verbatim. It is safe where trimming is not, because the `tool` * message stays exactly where it is with the same `toolCallId` — so the * `tool_use` ↔ `tool_result` pairing the providers require is untouched by * construction. The placeholder tells the model what happened, so a result * it turns out to still need is one tool call away rather than lost. */ export interface ToolResultEditConfig { /** * How many of the most recent tool results to leave alone. The agent is * usually still working with these, and clearing them buys tokens by * forcing an immediate re-read — a net loss. */ readonly keepRecentToolResults?: number; /** * Don't bother clearing results smaller than this. Below it the * placeholder is comparable in size to the output, so the churn buys * nothing and costs the model a confusing hole in its history. */ readonly minCharsToClear?: number; /** Tools whose output is never cleared, by name. */ readonly preserveTools?: readonly string[]; } export declare const DEFAULT_KEEP_RECENT_TOOL_RESULTS = 3; export declare const DEFAULT_MIN_CHARS_TO_CLEAR = 1000; export interface ToolResultEditOutcome { readonly messages: Message[]; readonly clearedCount: number; /** Payload characters removed, including encoded data; not a token estimate. */ readonly charsReclaimed: number; } /** * One result cleared on its own, for a caller that chose it by some * other rule than staleness. The same placeholder, the same accounting. */ export declare function clearToolResult(tool: ToolMessage, toolName: string): { readonly message: ToolMessage; readonly charsReclaimed: number; }; export declare function isClearedToolResult(content: unknown): boolean; /** * Replace the output of old, large tool results with a short placeholder. * * Returns a NEW array; the input is not mutated. `clearedCount === 0` means * nothing was eligible, and the caller should fall through to whatever it * would have done anyway. */ export declare function clearStaleToolResults(messages: readonly Message[], config?: ToolResultEditConfig): ToolResultEditOutcome; //# sourceMappingURL=tool-result-editing.d.ts.map