import type { Compactor } from '../types/compactor.js'; import type { Message } from '../types/messages.js'; import type { Tool } from '../types/tool.js'; /** * Context introspection and management tool. * Allows the model to: * - "check" → see token budget and message counts * - "summary" → summarize and replace a range of messages * - "prune" → remove specific message indices * - "add_note" → inject a summary note at a specific point * - "compact" → run compaction via the injected compactor */ export declare const CONTEXT_MANAGER_TOOL_NAME = "context_manager"; export type ContextManagerAction = 'check' | 'summary' | 'prune' | 'add_note' | 'compact' | 'repair'; export interface ContextManagerInput { action: ContextManagerAction; /** 0-based message indices for prune/summary (inclusive). */ from?: number | undefined; to?: number | undefined; /** Text for add_note / summary actions. For summary, this is the LLM-provided summary text. */ text?: string | undefined; /** Inject after which index (for add_note). Defaults to prepend (0). */ afterIndex?: number | undefined; /** * System prompt blocks for accurate total token estimation in check action. * When provided, check returns the full API request estimate * (messages + system + tools) instead of just message tokens. */ systemPrompt?: unknown | undefined; /** * Registered tools for accurate total token estimation in check action. * Each tool's name + description + inputSchema is counted. */ tools?: { name: string; description?: string | undefined; inputSchema: unknown; }[]; } export interface ContextManagerResult { action: ContextManagerAction; beforeTokens: number; afterTokens?: number | undefined; removedCount?: number | undefined; messageCount: number; summary?: string | undefined; notes?: string | undefined; repaired?: { removedToolUses: string[]; removedToolResults: string[]; removedMessages: number; } | undefined; } /** * Options for creating a context manager tool. * `compactor` is required for the "compact" action; without it the action returns an error. */ export interface ContextManagerToolOptions { compactor?: Compactor | undefined; /** * Optional sub-LLM summarizer. When provided, the "summary" action calls this * to produce real summaries of message ranges instead of placeholder text. * (signature matches Provider.complete — return the summary text in result.content[0].text) */ summarizer?: (((messages: Message[]) => Promise)) | undefined; /** * Minimum full-request token count before the compact action is allowed to run. * Prevents unnecessary compaction calls when context is small. * Default: 0 (always allow). Set to ~5000 for meaningful compaction targets. */ minCompactThreshold?: number | undefined; /** * Minimum token growth required before retrying after a NOOP compaction. * A NOOP is when compaction saved nothing (preserveK protects everything, * no oversized tool_results). Default: 2000. */ noopRetryDeltaTokens?: number | undefined; /** * Provider's max context window in tokens. Used to compute a relative * threshold when `minCompactThreshold` is not set. Default: 128_000. */ maxContext?: number | undefined; /** * Fraction of maxContext that triggers compaction. Only used when * `minCompactThreshold` is not set. Default: 0.5 (50% of maxContext). */ compactThresholdFraction?: number | undefined; } export declare function createContextManagerTool(opts?: ContextManagerToolOptions): Tool; /** Pre-built instance with no compactor — compact action will return an error. */ export declare const contextManagerTool: Tool; //# sourceMappingURL=context-manager.d.ts.map