/** * Tool-call argument validation pipeline. * * Tools may declare their parameters as either Zod schemas (canonical) or * plain JSON Schema (legacy / extensions). This module is the single * entrypoint the agent calls before dispatching a tool — it: * * 1. Builds (or fetches from cache) a `ValidationContext` for the tool — * the Zod schema if available plus the equivalent wire JSON Schema, or * just the JSON Schema for non-Zod tools. * 2. Normalizes LLM quirks (null / "null" → omit-or-default substitution) * against the JSON Schema before validation. * 3. Validates with the Zod or JSON-Schema validator. * 4. On failure, walks the resulting issues and coerces common LLM type * drift (JSON-stringified values, boolean/number/string scalar drift), * drops unrecognized keys, and retries up to `MAX_COERCION_PASSES` times. * 5. Throws a formatted error if reconciliation fails; otherwise returns * the parsed arguments with original unknown root fields preserved (so * hallucinated top-level keys still surface to the caller). * * The goal is to be conservative: every coercion is a structural rewrite that * keeps the schema in charge of acceptance — we never invent values, only * massage shapes the LLM almost got right. */ import type { Tool, ToolCall } from "../types"; /** * Finds a tool by name and validates the tool call arguments against its schema. * @param tools Array of tool definitions * @param toolCall The tool call from the LLM * @returns The validated arguments * @throws Error if tool is not found or validation fails */ export declare function validateToolCall(tools: Tool[], toolCall: ToolCall): ToolCall["arguments"]; /** * Validates tool call arguments against the tool's schema (Zod or plain JSON * Schema). Applies LLM-quirk coercions (numeric strings, JSON-string * containers, null/invalid-empty-string-for-optional, null-for-default) before * declaring failure. * * @throws Error with a formatted message when validation cannot be reconciled. */ export declare function validateToolArguments(tool: Tool, toolCall: ToolCall): ToolCall["arguments"];