import { T as ToolDefinition } from './message-CyXbT7Zj.cjs'; import 'json-schema'; interface SelfDebugInput { tool: ToolDefinition; args: Record; error: Error; attempt: number; } interface SelfDebugResult { /** Either corrected arguments (retry) or `null` to give up. */ args: Record | null; /** Free-form note appended to telemetry. */ reasoning?: string; } type SelfDebugger = (input: SelfDebugInput) => Promise | SelfDebugResult; interface SelfDebugOptions { /** Max retry attempts after the original call. Default 2. */ maxAttempts?: number; /** Called on every failure + retry for observability. */ onEvent?: (event: { type: 'failure' | 'retry' | 'give-up' | 'success'; tool: string; attempt: number; error?: string; }) => void; } /** * Wrap any tool with a self-debug loop. When `execute` throws, the * configured `debugger` receives the error + args and can return * corrected args for another attempt. Give up by returning * `{ args: null }`. No retry happens on the original (attempt 0) call * — `maxAttempts` controls additional retries. * * This is the "agent fixes itself" pattern — typically plug in an * LLM call that reads the error + schema and emits new arguments. */ declare function wrapToolWithSelfDebug(tool: ToolDefinition, selfDebugger: SelfDebugger, options?: SelfDebugOptions): ToolDefinition; /** * Debugger backed by a user-supplied async function that asks an LLM * to produce corrected JSON arguments. The helper handles prompt * construction + JSON parsing; plug in your own completion * (`runOnce(adapter, prompt)` via any runtime). */ declare function createLlmSelfDebugger(complete: (prompt: string) => Promise): SelfDebugger; export { type SelfDebugInput, type SelfDebugOptions, type SelfDebugResult, type SelfDebugger, createLlmSelfDebugger, wrapToolWithSelfDebug };