import { AgentMiddleware, ToolCallRequest } from "./types.cjs"; import { MessageContent } from "@langchain/core/messages"; import { ClientTool, ServerTool } from "@langchain/core/tools"; //#region src/agents/middleware/toolError.d.ts /** * Handler called when tool execution throws. * * Return content to surface the error to the model as an error `ToolMessage`. * Return nothing to propagate the original error. */ type ToolErrorHandler = (error: unknown, request: ToolCallRequest) => MessageContent | void | Promise; /** * Configuration for {@link toolErrorMiddleware}. */ interface ToolErrorMiddlewareConfig { /** * Handler called when tool execution throws. Return content to convert the * error into an error `ToolMessage`, or return nothing to propagate it. */ onError: ToolErrorHandler; /** * Optional tools or tool names to handle errors for. Handles all tools when * omitted. */ tools?: Array; } /** * Converts selected tool execution errors into error `ToolMessage`s. * * Handling is opt-in: {@link ToolErrorMiddlewareConfig.onError} must return * content for an error to be sent to the model. Returning nothing propagates * the original error unchanged. LangGraph control-flow signals always * propagate and are never passed to `onError`. * * Prefer returning content that identifies the error type without including * the raw error message, which may contain sensitive or internal details. * * This middleware does not retry. To retry before handling an error, place * `toolRetryMiddleware({ onFailure: "error" })` after this middleware. * * @example * ```ts * import { createAgent, toolErrorMiddleware } from "langchain"; * * const agent = createAgent({ * model, * tools: [searchTool], * middleware: [ * toolErrorMiddleware({ * onError: (error, request) => { * if (error instanceof TypeError) { * return `Tool '${request.toolCall.name}' failed with TypeError.`; * } * }, * }), * ], * }); * ``` */ declare function toolErrorMiddleware(config: ToolErrorMiddlewareConfig): AgentMiddleware; //#endregion export { ToolErrorHandler, ToolErrorMiddlewareConfig, toolErrorMiddleware }; //# sourceMappingURL=toolError.d.cts.map