langchain 1.0.0-alpha.2 → 1.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/agents/ReactAgent.cjs +1 -1
  2. package/dist/agents/ReactAgent.cjs.map +1 -1
  3. package/dist/agents/ReactAgent.d.cts +3 -3
  4. package/dist/agents/ReactAgent.d.cts.map +1 -1
  5. package/dist/agents/ReactAgent.d.ts +3 -3
  6. package/dist/agents/ReactAgent.d.ts.map +1 -1
  7. package/dist/agents/ReactAgent.js +2 -2
  8. package/dist/agents/ReactAgent.js.map +1 -1
  9. package/dist/agents/annotation.cjs +122 -2
  10. package/dist/agents/annotation.cjs.map +1 -1
  11. package/dist/agents/annotation.d.cts +18 -14
  12. package/dist/agents/annotation.d.cts.map +1 -1
  13. package/dist/agents/annotation.d.ts +18 -14
  14. package/dist/agents/annotation.d.ts.map +1 -1
  15. package/dist/agents/annotation.js +121 -2
  16. package/dist/agents/annotation.js.map +1 -1
  17. package/dist/agents/errors.cjs +1 -1
  18. package/dist/agents/errors.cjs.map +1 -1
  19. package/dist/agents/errors.js +1 -1
  20. package/dist/agents/errors.js.map +1 -1
  21. package/dist/agents/index.cjs +2 -2
  22. package/dist/agents/index.cjs.map +1 -1
  23. package/dist/agents/index.d.cts +15 -15
  24. package/dist/agents/index.d.cts.map +1 -1
  25. package/dist/agents/index.d.ts +15 -15
  26. package/dist/agents/index.d.ts.map +1 -1
  27. package/dist/agents/index.js +2 -2
  28. package/dist/agents/index.js.map +1 -1
  29. package/dist/agents/nodes/AgentNode.cjs +8 -3
  30. package/dist/agents/nodes/AgentNode.cjs.map +1 -1
  31. package/dist/agents/nodes/AgentNode.js +8 -3
  32. package/dist/agents/nodes/AgentNode.js.map +1 -1
  33. package/dist/agents/nodes/ToolNode.cjs +2 -2
  34. package/dist/agents/nodes/ToolNode.cjs.map +1 -1
  35. package/dist/agents/nodes/ToolNode.d.cts +1 -1
  36. package/dist/agents/nodes/ToolNode.d.cts.map +1 -1
  37. package/dist/agents/nodes/ToolNode.d.ts +1 -1
  38. package/dist/agents/nodes/ToolNode.d.ts.map +1 -1
  39. package/dist/agents/nodes/ToolNode.js +2 -2
  40. package/dist/agents/nodes/ToolNode.js.map +1 -1
  41. package/dist/agents/responses.cjs +2 -3
  42. package/dist/agents/responses.cjs.map +1 -1
  43. package/dist/agents/responses.d.cts +6 -1
  44. package/dist/agents/responses.d.cts.map +1 -1
  45. package/dist/agents/responses.d.ts +6 -1
  46. package/dist/agents/responses.d.ts.map +1 -1
  47. package/dist/agents/responses.js +2 -3
  48. package/dist/agents/responses.js.map +1 -1
  49. package/dist/agents/types.d.cts +28 -10
  50. package/dist/agents/types.d.cts.map +1 -1
  51. package/dist/agents/types.d.ts +28 -10
  52. package/dist/agents/types.d.ts.map +1 -1
  53. package/dist/agents/utils.cjs +1 -1
  54. package/dist/agents/utils.cjs.map +1 -1
  55. package/dist/agents/utils.js +1 -1
  56. package/dist/agents/utils.js.map +1 -1
  57. package/dist/agents/withAgentName.cjs +1 -1
  58. package/dist/agents/withAgentName.cjs.map +1 -1
  59. package/dist/agents/withAgentName.js +1 -1
  60. package/dist/agents/withAgentName.js.map +1 -1
  61. package/dist/evaluation/agents/trajectory.d.cts.map +1 -1
  62. package/dist/evaluation/agents/trajectory.d.ts.map +1 -1
  63. package/dist/evaluation/comparison/pairwise.d.cts.map +1 -1
  64. package/dist/evaluation/comparison/pairwise.d.ts.map +1 -1
  65. package/dist/evaluation/criteria/criteria.d.cts.map +1 -1
  66. package/dist/evaluation/criteria/criteria.d.ts.map +1 -1
  67. package/dist/index.cjs +52 -3
  68. package/dist/index.cjs.map +1 -1
  69. package/dist/index.d.cts +4 -4
  70. package/dist/index.d.ts +4 -4
  71. package/dist/index.js +12 -5
  72. package/dist/index.js.map +1 -1
  73. package/package.json +6 -6
@@ -1 +1 @@
1
- {"version":3,"file":"ToolNode.cjs","names":["input: unknown","isBaseMessage","RunnableCallable","tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[]","options?: ToolNodeOptions","call: ToolCall","config: RunnableConfig","tool","mergeAbortSignals","ToolMessage","e: unknown","ToolInputParsingException","ToolInvocationError","state: ToAnnotationRoot<StateSchema>[\"State\"] & PreHookAnnotation[\"State\"]","outputs: (ToolMessage | Command)[]","messages: BaseMessage[]","toolMessageIds: Set<string>","aiMessage: AIMessage | undefined","isCommand","combinedOutputs: (\n | { messages: BaseMessage[] }\n | BaseMessage[]\n | Command\n )[]","parentCommand: Command | null","Command","x: unknown","Send"],"sources":["../../../src/agents/nodes/ToolNode.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport {\n BaseMessage,\n ToolMessage,\n AIMessage,\n isBaseMessage,\n isToolMessage,\n} from \"@langchain/core/messages\";\nimport { RunnableConfig, RunnableToolLike } from \"@langchain/core/runnables\";\nimport {\n DynamicTool,\n StructuredToolInterface,\n ToolInputParsingException,\n} from \"@langchain/core/tools\";\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\nimport type { InteropZodObject } from \"@langchain/core/utils/types\";\nimport {\n isCommand,\n Command,\n Send,\n isGraphInterrupt,\n type NodeInterrupt,\n} from \"@langchain/langgraph\";\n\nimport { RunnableCallable } from \"../RunnableCallable.js\";\nimport {\n PreHookAnnotation,\n AnyAnnotationRoot,\n ToAnnotationRoot,\n} from \"../annotation.js\";\nimport { mergeAbortSignals } from \"./utils.js\";\nimport { ToolInvocationError } from \"../errors.js\";\n\nexport interface ToolNodeOptions {\n /**\n * The name of the tool node.\n */\n name?: string;\n /**\n * The tags to add to the tool call.\n */\n tags?: string[];\n /**\n * The abort signal to cancel the tool call.\n */\n signal?: AbortSignal;\n /**\n * Whether to throw the error immediately if the tool fails or handle it by the `onToolError` function or via ToolMessage.\n *\n * If `true` (default):\n * - a tool message with the error will be returned to the LLM\n *\n * If `false`:\n * - the error will be thrown immediately\n *\n * If a function is provided:\n * - returns a custom {@link ToolMessage} as result\n * - throws an error otherwise\n *\n * @default true\n */\n handleToolErrors?:\n | boolean\n | ((error: unknown, toolCall: ToolCall) => ToolMessage | undefined);\n}\n\nconst isBaseMessageArray = (input: unknown): input is BaseMessage[] =>\n Array.isArray(input) && input.every(isBaseMessage);\n\nconst isMessagesState = (\n input: unknown\n): input is { messages: BaseMessage[] } =>\n typeof input === \"object\" &&\n input != null &&\n \"messages\" in input &&\n isBaseMessageArray(input.messages);\n\nconst isSendInput = (input: unknown): input is { lg_tool_call: ToolCall } =>\n typeof input === \"object\" && input != null && \"lg_tool_call\" in input;\n\n/**\n * `ToolNode` is a built-in LangGraph component that handles tool calls within an agent's workflow.\n * It works seamlessly with `createReactAgent`, offering advanced tool execution control, built\n * in parallelism, and error handling.\n *\n * @example\n * ```ts\n * import { ToolNode, tool, AIMessage } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * }),\n * });\n *\n * const tools = [getWeather];\n * const toolNode = new ToolNode(tools);\n *\n * const messageWithSingleToolCall = new AIMessage({\n * content: \"\",\n * tool_calls: [\n * {\n * name: \"get_weather\",\n * args: { location: \"sf\" },\n * id: \"tool_call_id\",\n * type: \"tool_call\",\n * }\n * ]\n * })\n *\n * await toolNode.invoke({ messages: [messageWithSingleToolCall] });\n * // Returns tool invocation responses as:\n * // { messages: ToolMessage[] }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class ToolNode<\n StateSchema extends AnyAnnotationRoot | InteropZodObject = any,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = any\n> extends RunnableCallable<StateSchema, ContextSchema> {\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[];\n\n trace = false;\n\n signal?: AbortSignal;\n\n handleToolErrors:\n | boolean\n | ((error: unknown, toolCall: ToolCall) => ToolMessage | undefined) = true;\n\n constructor(\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[],\n public options?: ToolNodeOptions\n ) {\n const { name, tags, handleToolErrors } = options ?? {};\n super({\n name,\n tags,\n func: (state, config) =>\n this.run(\n state as ToAnnotationRoot<StateSchema>[\"State\"] &\n PreHookAnnotation[\"State\"],\n config as RunnableConfig\n ),\n });\n this.tools = tools;\n this.handleToolErrors = handleToolErrors ?? this.handleToolErrors;\n this.signal = options?.signal;\n }\n\n protected async runTool(\n call: ToolCall,\n config: RunnableConfig\n ): Promise<ToolMessage | Command> {\n const tool = this.tools.find((tool) => tool.name === call.name);\n try {\n if (tool === undefined) {\n throw new Error(`Tool \"${call.name}\" not found.`);\n }\n\n const output = await tool.invoke(\n { ...call, type: \"tool_call\" },\n {\n ...config,\n signal: mergeAbortSignals(this.signal, config.signal),\n }\n );\n\n if (\n (isBaseMessage(output) && output.getType() === \"tool\") ||\n isCommand(output)\n ) {\n return output as ToolMessage | Command;\n }\n\n return new ToolMessage({\n name: tool.name,\n content: typeof output === \"string\" ? output : JSON.stringify(output),\n tool_call_id: call.id!,\n });\n } catch (e: unknown) {\n /**\n * If tool invocation fails due to input parsing error, throw a {@link ToolInvocationError}\n */\n if (e instanceof ToolInputParsingException) {\n throw new ToolInvocationError(e, call);\n }\n\n /**\n * throw the error if user prefers not to handle tool errors\n */\n if (!this.handleToolErrors) {\n throw e;\n }\n\n if (isGraphInterrupt(e)) {\n /**\n * {@link NodeInterrupt} errors are a breakpoint to bring a human into the loop.\n * As such, they are not recoverable by the agent and shouldn't be fed\n * back. Instead, re-throw these errors even when `handleToolErrors = true`.\n */\n throw e;\n }\n\n /**\n * If the signal is aborted, we want to bubble up the error to the invoke caller.\n */\n if (this.signal?.aborted) {\n throw e;\n }\n\n /**\n * if the user provides a function, call it with the error and tool call\n * and return the result if it is a {@link ToolMessage}\n */\n if (typeof this.handleToolErrors === \"function\") {\n const result = this.handleToolErrors(e, call);\n if (result && isToolMessage(result)) {\n return result;\n }\n } else if (this.handleToolErrors) {\n return new ToolMessage({\n name: call.name,\n content: `Error: ${e}\\n Please fix your mistakes.`,\n tool_call_id: call.id!,\n });\n }\n\n /**\n * If the user doesn't handle the error, throw it\n */\n throw e;\n }\n }\n\n protected async run(\n state: ToAnnotationRoot<StateSchema>[\"State\"] & PreHookAnnotation[\"State\"],\n config: RunnableConfig\n ): Promise<ContextSchema> {\n let outputs: (ToolMessage | Command)[];\n\n if (isSendInput(state)) {\n outputs = [await this.runTool(state.lg_tool_call, config)];\n } else {\n let messages: BaseMessage[];\n if (isBaseMessageArray(state)) {\n messages = state;\n } else if (isMessagesState(state)) {\n messages = state.messages;\n } else {\n throw new Error(\n \"ToolNode only accepts BaseMessage[] or { messages: BaseMessage[] } as input.\"\n );\n }\n\n const toolMessageIds: Set<string> = new Set(\n messages\n .filter((msg) => msg.getType() === \"tool\")\n .map((msg) => (msg as ToolMessage).tool_call_id)\n );\n\n let aiMessage: AIMessage | undefined;\n for (let i = messages.length - 1; i >= 0; i -= 1) {\n const message = messages[i];\n if (message.getType() === \"ai\") {\n aiMessage = message;\n break;\n }\n }\n\n if (aiMessage?.getType() !== \"ai\") {\n throw new Error(\"ToolNode only accepts AIMessages as input.\");\n }\n\n outputs = await Promise.all(\n aiMessage.tool_calls\n ?.filter((call) => call.id == null || !toolMessageIds.has(call.id))\n .map((call) => this.runTool(call, config)) ?? []\n );\n }\n\n // Preserve existing behavior for non-command tool outputs for backwards compatibility\n if (!outputs.some(isCommand)) {\n return (Array.isArray(state)\n ? outputs\n : { messages: outputs }) as unknown as ContextSchema;\n }\n\n // Handle mixed Command and non-Command outputs\n const combinedOutputs: (\n | { messages: BaseMessage[] }\n | BaseMessage[]\n | Command\n )[] = [];\n let parentCommand: Command | null = null;\n\n for (const output of outputs) {\n if (isCommand(output)) {\n if (\n output.graph === Command.PARENT &&\n Array.isArray(output.goto) &&\n output.goto.every((send) => isSend(send))\n ) {\n if (parentCommand) {\n (parentCommand.goto as Send[]).push(...(output.goto as Send[]));\n } else {\n parentCommand = new Command({\n graph: Command.PARENT,\n goto: output.goto,\n });\n }\n } else {\n combinedOutputs.push(output);\n }\n } else {\n combinedOutputs.push(\n Array.isArray(state) ? [output] : { messages: [output] }\n );\n }\n }\n\n if (parentCommand) {\n combinedOutputs.push(parentCommand);\n }\n\n return combinedOutputs as unknown as ContextSchema;\n }\n}\n\nexport function isSend(x: unknown): x is Send {\n // eslint-disable-next-line no-instanceof/no-instanceof\n return x instanceof Send;\n}\n"],"mappings":";;;;;;;;;AAkEA,MAAM,qBAAqB,CAACA,UAC1B,MAAM,QAAQ,MAAM,IAAI,MAAM,MAAMC,wCAAc;AAEpD,MAAM,kBAAkB,CACtBD,UAEA,OAAO,UAAU,YACjB,SAAS,QACT,cAAc,SACd,mBAAmB,MAAM,SAAS;AAEpC,MAAM,cAAc,CAACA,UACnB,OAAO,UAAU,YAAY,SAAS,QAAQ,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+ClE,IAAa,WAAb,cAGUE,0CAA6C;CACrD;CAEA,QAAQ;CAER;CAEA,mBAEwE;CAExE,YACEC,OACOC,SACP;EACA,MAAM,EAAE,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAE;EACtD,MAAM;GACJ;GACA;GACA,MAAM,CAAC,OAAO,WACZ,KAAK,IACH,OAEA,OACD;EACJ,EAAC;EAZK;EAaP,KAAK,QAAQ;EACb,KAAK,mBAAmB,oBAAoB,KAAK;EACjD,KAAK,SAAS,SAAS;CACxB;CAED,MAAgB,QACdC,MACAC,QACgC;EAChC,MAAM,OAAO,KAAK,MAAM,KAAK,CAACC,WAASA,OAAK,SAAS,KAAK,KAAK;AAC/D,MAAI;AACF,OAAI,SAAS,OACX,OAAM,IAAI,MAAM,CAAC,MAAM,EAAE,KAAK,KAAK,YAAY,CAAC;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,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG;IAChD,MAAM,UAAU,SAAS;AACzB,QAAI,QAAQ,SAAS,KAAK,MAAM;KAC9B,YAAY;AACZ;IACD;GACF;AAED,OAAI,WAAW,SAAS,KAAK,KAC3B,OAAM,IAAI,MAAM;GAGlB,UAAU,MAAM,QAAQ,IACtB,UAAU,YACN,OAAO,CAAC,SAAS,KAAK,MAAM,QAAQ,CAAC,eAAe,IAAI,KAAK,GAAG,CAAC,CAClE,IAAI,CAAC,SAAS,KAAK,QAAQ,MAAM,OAAO,CAAC,IAAI,CAAE,EACnD;EACF;AAGD,MAAI,CAAC,QAAQ,KAAKC,gCAAU,CAC1B,QAAQ,MAAM,QAAQ,MAAM,GACxB,UACA,EAAE,UAAU,QAAS;EAI3B,MAAMC,kBAIA,CAAE;EACR,IAAIC,gBAAgC;AAEpC,OAAK,MAAM,UAAU,QACnB,0CAAc,OAAO,CACnB,KACE,OAAO,UAAUC,8BAAQ,UACzB,MAAM,QAAQ,OAAO,KAAK,IAC1B,OAAO,KAAK,MAAM,CAAC,SAAS,OAAO,KAAK,CAAC,CAEzC,KAAI,eACD,cAAc,KAAgB,KAAK,GAAI,OAAO,KAAgB;OAE/D,gBAAgB,IAAIA,8BAAQ;GAC1B,OAAOA,8BAAQ;GACf,MAAM,OAAO;EACd;OAGH,gBAAgB,KAAK,OAAO;OAG9B,gBAAgB,KACd,MAAM,QAAQ,MAAM,GAAG,CAAC,MAAO,IAAG,EAAE,UAAU,CAAC,MAAO,EAAE,EACzD;AAIL,MAAI,eACF,gBAAgB,KAAK,cAAc;AAGrC,SAAO;CACR;AACF;AAED,SAAgB,OAAOC,GAAuB;AAE5C,QAAO,aAAaC;AACrB"}
1
+ {"version":3,"file":"ToolNode.cjs","names":["input: unknown","isBaseMessage","RunnableCallable","tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[]","options?: ToolNodeOptions","call: ToolCall","config: RunnableConfig","tool","mergeAbortSignals","ToolMessage","e: unknown","ToolInputParsingException","ToolInvocationError","state: ToAnnotationRoot<StateSchema>[\"State\"] & PreHookAnnotation[\"State\"]","outputs: (ToolMessage | Command)[]","messages: BaseMessage[]","toolMessageIds: Set<string>","aiMessage: AIMessage | undefined","isCommand","combinedOutputs: (\n | { messages: BaseMessage[] }\n | BaseMessage[]\n | Command\n )[]","parentCommand: Command | null","Command","x: unknown","Send"],"sources":["../../../src/agents/nodes/ToolNode.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport {\n BaseMessage,\n ToolMessage,\n AIMessage,\n isBaseMessage,\n isToolMessage,\n} from \"@langchain/core/messages\";\nimport { RunnableConfig, RunnableToolLike } from \"@langchain/core/runnables\";\nimport {\n DynamicTool,\n StructuredToolInterface,\n ToolInputParsingException,\n} from \"@langchain/core/tools\";\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\nimport type { InteropZodObject } from \"@langchain/core/utils/types\";\nimport {\n isCommand,\n Command,\n Send,\n isGraphInterrupt,\n type NodeInterrupt,\n} from \"@langchain/langgraph\";\n\nimport { RunnableCallable } from \"../RunnableCallable.js\";\nimport {\n PreHookAnnotation,\n AnyAnnotationRoot,\n ToAnnotationRoot,\n} from \"../annotation.js\";\nimport { mergeAbortSignals } from \"./utils.js\";\nimport { ToolInvocationError } from \"../errors.js\";\n\nexport interface ToolNodeOptions {\n /**\n * The name of the tool node.\n */\n name?: string;\n /**\n * The tags to add to the tool call.\n */\n tags?: string[];\n /**\n * The abort signal to cancel the tool call.\n */\n signal?: AbortSignal;\n /**\n * Whether to throw the error immediately if the tool fails or handle it by the `onToolError` function or via ToolMessage.\n *\n * If `true` (default):\n * - a tool message with the error will be returned to the LLM\n *\n * If `false`:\n * - the error will be thrown immediately\n *\n * If a function is provided:\n * - returns a custom {@link ToolMessage} as result\n * - throws an error otherwise\n *\n * @default true\n */\n handleToolErrors?:\n | boolean\n | ((error: unknown, toolCall: ToolCall) => ToolMessage | undefined);\n}\n\nconst isBaseMessageArray = (input: unknown): input is BaseMessage[] =>\n Array.isArray(input) && input.every(isBaseMessage);\n\nconst isMessagesState = (\n input: unknown\n): input is { messages: BaseMessage[] } =>\n typeof input === \"object\" &&\n input != null &&\n \"messages\" in input &&\n isBaseMessageArray(input.messages);\n\nconst isSendInput = (input: unknown): input is { lg_tool_call: ToolCall } =>\n typeof input === \"object\" && input != null && \"lg_tool_call\" in input;\n\n/**\n * `ToolNode` is a built-in LangGraph component that handles tool calls within an agent's workflow.\n * It works seamlessly with `createAgent`, offering advanced tool execution control, built\n * in parallelism, and error handling.\n *\n * @example\n * ```ts\n * import { ToolNode, tool, AIMessage } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * }),\n * });\n *\n * const tools = [getWeather];\n * const toolNode = new ToolNode(tools);\n *\n * const messageWithSingleToolCall = new AIMessage({\n * content: \"\",\n * tool_calls: [\n * {\n * name: \"get_weather\",\n * args: { location: \"sf\" },\n * id: \"tool_call_id\",\n * type: \"tool_call\",\n * }\n * ]\n * })\n *\n * await toolNode.invoke({ messages: [messageWithSingleToolCall] });\n * // Returns tool invocation responses as:\n * // { messages: ToolMessage[] }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class ToolNode<\n StateSchema extends AnyAnnotationRoot | InteropZodObject = any,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = any\n> extends RunnableCallable<StateSchema, ContextSchema> {\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[];\n\n trace = false;\n\n signal?: AbortSignal;\n\n handleToolErrors:\n | boolean\n | ((error: unknown, toolCall: ToolCall) => ToolMessage | undefined) = true;\n\n constructor(\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[],\n public options?: ToolNodeOptions\n ) {\n const { name, tags, handleToolErrors } = options ?? {};\n super({\n name,\n tags,\n func: (state, config) =>\n this.run(\n state as ToAnnotationRoot<StateSchema>[\"State\"] &\n PreHookAnnotation[\"State\"],\n config as RunnableConfig\n ),\n });\n this.tools = tools;\n this.handleToolErrors = handleToolErrors ?? this.handleToolErrors;\n this.signal = options?.signal;\n }\n\n protected async runTool(\n call: ToolCall,\n config: RunnableConfig\n ): Promise<ToolMessage | Command> {\n const tool = this.tools.find((tool) => tool.name === call.name);\n try {\n if (tool === undefined) {\n throw new Error(`Tool \"${call.name}\" not found.`);\n }\n\n const output = await tool.invoke(\n { ...call, type: \"tool_call\" },\n {\n ...config,\n signal: mergeAbortSignals(this.signal, config.signal),\n }\n );\n\n if (\n (isBaseMessage(output) && output.getType() === \"tool\") ||\n isCommand(output)\n ) {\n return output as ToolMessage | Command;\n }\n\n return new ToolMessage({\n name: tool.name,\n content: typeof output === \"string\" ? output : JSON.stringify(output),\n tool_call_id: call.id!,\n });\n } catch (e: unknown) {\n /**\n * If tool invocation fails due to input parsing error, throw a {@link ToolInvocationError}\n */\n if (e instanceof ToolInputParsingException) {\n throw new ToolInvocationError(e, call);\n }\n\n /**\n * throw the error if user prefers not to handle tool errors\n */\n if (!this.handleToolErrors) {\n throw e;\n }\n\n if (isGraphInterrupt(e)) {\n /**\n * {@link NodeInterrupt} errors are a breakpoint to bring a human into the loop.\n * As such, they are not recoverable by the agent and shouldn't be fed\n * back. Instead, re-throw these errors even when `handleToolErrors = true`.\n */\n throw e;\n }\n\n /**\n * If the signal is aborted, we want to bubble up the error to the invoke caller.\n */\n if (this.signal?.aborted) {\n throw e;\n }\n\n /**\n * if the user provides a function, call it with the error and tool call\n * and return the result if it is a {@link ToolMessage}\n */\n if (typeof this.handleToolErrors === \"function\") {\n const result = this.handleToolErrors(e, call);\n if (result && isToolMessage(result)) {\n return result;\n }\n } else if (this.handleToolErrors) {\n return new ToolMessage({\n name: call.name,\n content: `${e}\\n Please fix your mistakes.`,\n tool_call_id: call.id!,\n });\n }\n\n /**\n * If the user doesn't handle the error, throw it\n */\n throw e;\n }\n }\n\n protected async run(\n state: ToAnnotationRoot<StateSchema>[\"State\"] & PreHookAnnotation[\"State\"],\n config: RunnableConfig\n ): Promise<ContextSchema> {\n let outputs: (ToolMessage | Command)[];\n\n if (isSendInput(state)) {\n outputs = [await this.runTool(state.lg_tool_call, config)];\n } else {\n let messages: BaseMessage[];\n if (isBaseMessageArray(state)) {\n messages = state;\n } else if (isMessagesState(state)) {\n messages = state.messages;\n } else {\n throw new Error(\n \"ToolNode only accepts BaseMessage[] or { messages: BaseMessage[] } as input.\"\n );\n }\n\n const toolMessageIds: Set<string> = new Set(\n messages\n .filter((msg) => msg.getType() === \"tool\")\n .map((msg) => (msg as ToolMessage).tool_call_id)\n );\n\n let aiMessage: AIMessage | undefined;\n for (let i = messages.length - 1; i >= 0; i -= 1) {\n const message = messages[i];\n if (message.getType() === \"ai\") {\n aiMessage = message;\n break;\n }\n }\n\n if (aiMessage?.getType() !== \"ai\") {\n throw new Error(\"ToolNode only accepts AIMessages as input.\");\n }\n\n outputs = await Promise.all(\n aiMessage.tool_calls\n ?.filter((call) => call.id == null || !toolMessageIds.has(call.id))\n .map((call) => this.runTool(call, config)) ?? []\n );\n }\n\n // Preserve existing behavior for non-command tool outputs for backwards compatibility\n if (!outputs.some(isCommand)) {\n return (Array.isArray(state)\n ? outputs\n : { messages: outputs }) as unknown as ContextSchema;\n }\n\n // Handle mixed Command and non-Command outputs\n const combinedOutputs: (\n | { messages: BaseMessage[] }\n | BaseMessage[]\n | Command\n )[] = [];\n let parentCommand: Command | null = null;\n\n for (const output of outputs) {\n if (isCommand(output)) {\n if (\n output.graph === Command.PARENT &&\n Array.isArray(output.goto) &&\n output.goto.every((send) => isSend(send))\n ) {\n if (parentCommand) {\n (parentCommand.goto as Send[]).push(...(output.goto as Send[]));\n } else {\n parentCommand = new Command({\n graph: Command.PARENT,\n goto: output.goto,\n });\n }\n } else {\n combinedOutputs.push(output);\n }\n } else {\n combinedOutputs.push(\n Array.isArray(state) ? [output] : { messages: [output] }\n );\n }\n }\n\n if (parentCommand) {\n combinedOutputs.push(parentCommand);\n }\n\n return combinedOutputs as unknown as ContextSchema;\n }\n}\n\nexport function isSend(x: unknown): x is Send {\n // eslint-disable-next-line no-instanceof/no-instanceof\n return x instanceof Send;\n}\n"],"mappings":";;;;;;;;;AAkEA,MAAM,qBAAqB,CAACA,UAC1B,MAAM,QAAQ,MAAM,IAAI,MAAM,MAAMC,wCAAc;AAEpD,MAAM,kBAAkB,CACtBD,UAEA,OAAO,UAAU,YACjB,SAAS,QACT,cAAc,SACd,mBAAmB,MAAM,SAAS;AAEpC,MAAM,cAAc,CAACA,UACnB,OAAO,UAAU,YAAY,SAAS,QAAQ,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+ClE,IAAa,WAAb,cAGUE,0CAA6C;CACrD;CAEA,QAAQ;CAER;CAEA,mBAEwE;CAExE,YACEC,OACOC,SACP;EACA,MAAM,EAAE,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAE;EACtD,MAAM;GACJ;GACA;GACA,MAAM,CAAC,OAAO,WACZ,KAAK,IACH,OAEA,OACD;EACJ,EAAC;EAZK;EAaP,KAAK,QAAQ;EACb,KAAK,mBAAmB,oBAAoB,KAAK;EACjD,KAAK,SAAS,SAAS;CACxB;CAED,MAAgB,QACdC,MACAC,QACgC;EAChC,MAAM,OAAO,KAAK,MAAM,KAAK,CAACC,WAASA,OAAK,SAAS,KAAK,KAAK;AAC/D,MAAI;AACF,OAAI,SAAS,OACX,OAAM,IAAI,MAAM,CAAC,MAAM,EAAE,KAAK,KAAK,YAAY,CAAC;GAGlD,MAAM,SAAS,MAAM,KAAK,OACxB;IAAE,GAAG;IAAM,MAAM;GAAa,GAC9B;IACE,GAAG;IACH,QAAQC,gCAAkB,KAAK,QAAQ,O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,OAAI,WAAW,SAAS,KAAK,KAC3B,OAAM,IAAI,MAAM;GAGlB,UAAU,MAAM,QAAQ,IACtB,UAAU,YACN,OAAO,CAAC,SAAS,KAAK,MAAM,QAAQ,CAAC,eAAe,IAAI,KAAK,GAAG,CAAC,CAClE,IAAI,CAAC,SAAS,KAAK,QAAQ,MAAM,OAAO,CAAC,IAAI,CAAE,EACnD;EACF;AAGD,MAAI,CAAC,QAAQ,KAAKC,gCAAU,CAC1B,QAAQ,MAAM,QAAQ,MAAM,GACxB,UACA,EAAE,UAAU,QAAS;EAI3B,MAAMC,kBAIA,CAAE;EACR,IAAIC,gBAAgC;AAEpC,OAAK,MAAM,UAAU,QACnB,0CAAc,OAAO,CACnB,KACE,OAAO,UAAUC,8BAAQ,UACzB,MAAM,QAAQ,OAAO,KAAK,IAC1B,OAAO,KAAK,MAAM,CAAC,SAAS,OAAO,KAAK,CAAC,CAEzC,KAAI,eACD,cAAc,KAAgB,KAAK,GAAI,OAAO,KAAgB;OAE/D,gBAAgB,IAAIA,8BAAQ;GAC1B,OAAOA,8BAAQ;GACf,MAAM,OAAO;EACd;OAGH,gBAAgB,KAAK,OAAO;OAG9B,gBAAgB,KACd,MAAM,QAAQ,MAAM,GAAG,CAAC,MAAO,IAAG,EAAE,UAAU,CAAC,MAAO,EAAE,EACzD;AAIL,MAAI,eACF,gBAAgB,KAAK,cAAc;AAGrC,SAAO;CACR;AACF;AAED,SAAgB,OAAOC,GAAuB;AAE5C,QAAO,aAAaC;AACrB"}
@@ -40,7 +40,7 @@ interface ToolNodeOptions {
40
40
  }
41
41
  /**
42
42
  * `ToolNode` is a built-in LangGraph component that handles tool calls within an agent's workflow.
43
- * It works seamlessly with `createReactAgent`, offering advanced tool execution control, built
43
+ * It works seamlessly with `createAgent`, offering advanced tool execution control, built
44
44
  * in parallelism, and error handling.
45
45
  *
46
46
  * @example
@@ -1 +1 @@
1
- {"version":3,"file":"ToolNode.d.cts","names":["ToolMessage","RunnableConfig","RunnableToolLike","DynamicTool","StructuredToolInterface","ToolCall","InteropZodObject","Command","Send","RunnableCallable","PreHookAnnotation","AnyAnnotationRoot","ToAnnotationRoot","ToolNodeOptions","AbortSignal","ToolNode","StateSchema","ContextSchema","Promise","isSend"],"sources":["../../../src/agents/nodes/ToolNode.d.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport { ToolMessage } from \"@langchain/core/messages\";\nimport { RunnableConfig, RunnableToolLike } from \"@langchain/core/runnables\";\nimport { DynamicTool, StructuredToolInterface } from \"@langchain/core/tools\";\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\nimport type { InteropZodObject } from \"@langchain/core/utils/types\";\nimport { Command, Send } from \"@langchain/langgraph\";\nimport { RunnableCallable } from \"../RunnableCallable.js\";\nimport { PreHookAnnotation, AnyAnnotationRoot, ToAnnotationRoot } from \"../annotation.js\";\nexport interface ToolNodeOptions {\n /**\n * The name of the tool node.\n */\n name?: string;\n /**\n * The tags to add to the tool call.\n */\n tags?: string[];\n /**\n * The abort signal to cancel the tool call.\n */\n signal?: AbortSignal;\n /**\n * Whether to throw the error immediately if the tool fails or handle it by the `onToolError` function or via ToolMessage.\n *\n * If `true` (default):\n * - a tool message with the error will be returned to the LLM\n *\n * If `false`:\n * - the error will be thrown immediately\n *\n * If a function is provided:\n * - returns a custom {@link ToolMessage} as result\n * - throws an error otherwise\n *\n * @default true\n */\n handleToolErrors?: boolean | ((error: unknown, toolCall: ToolCall) => ToolMessage | undefined);\n}\n/**\n * `ToolNode` is a built-in LangGraph component that handles tool calls within an agent's workflow.\n * It works seamlessly with `createReactAgent`, offering advanced tool execution control, built\n * in parallelism, and error handling.\n *\n * @example\n * ```ts\n * import { ToolNode, tool, AIMessage } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * }),\n * });\n *\n * const tools = [getWeather];\n * const toolNode = new ToolNode(tools);\n *\n * const messageWithSingleToolCall = new AIMessage({\n * content: \"\",\n * tool_calls: [\n * {\n * name: \"get_weather\",\n * args: { location: \"sf\" },\n * id: \"tool_call_id\",\n * type: \"tool_call\",\n * }\n * ]\n * })\n *\n * await toolNode.invoke({ messages: [messageWithSingleToolCall] });\n * // Returns tool invocation responses as:\n * // { messages: ToolMessage[] }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport declare class ToolNode<StateSchema extends AnyAnnotationRoot | InteropZodObject = any, ContextSchema extends AnyAnnotationRoot | InteropZodObject = any> extends RunnableCallable<StateSchema, ContextSchema> {\n options?: ToolNodeOptions | undefined;\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[];\n trace: boolean;\n signal?: AbortSignal;\n handleToolErrors: boolean | ((error: unknown, toolCall: ToolCall) => ToolMessage | undefined);\n constructor(tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[], options?: ToolNodeOptions | undefined);\n protected runTool(call: ToolCall, config: RunnableConfig): Promise<ToolMessage | Command>;\n protected run(state: ToAnnotationRoot<StateSchema>[\"State\"] & PreHookAnnotation[\"State\"], config: RunnableConfig): Promise<ContextSchema>;\n}\nexport declare function isSend(x: unknown): x is Send;\n"],"mappings":";;;;;;;;;;UASiBa,eAAAA;EAAAA;;;EAYO,IAgBqCR,CAAAA,EAAAA,MAAAA;EAAQ;AAAgB;AA+CrF;EAA6B,IAAA,CAAA,EAAA,MAAA,EAAA;EAAA;;;EAAwG,MAAGC,CAAAA,EA/D3HQ,WA+D2HR;EAAgB;;;;;;;;;;;;;;;EAO5F,gBAAWN,CAAAA,EAAAA,OAAAA,GAAAA,CAAAA,CAAAA,KAAAA,EAAAA,OAAAA,EAAAA,QAAAA,EAtDVK,QAsDUL,EAAAA,GAtDGA,WAsDHA,GAAAA,SAAAA,CAAAA;;;;;;;;;;AAPiH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAnKe,6BAA6BJ,oBAAoBL,8CAA8CK,oBAAoBL,gCAAgCG,iBAAiBO,aAAaC;YACxLJ;UACFT,0BAA0BD,cAAcD;;WAEvCY;0DAC+CT,aAAaL;sBACjDI,0BAA0BD,cAAcD,+BAA+BW;0BACnER,kBAAkBJ,iBAAiBiB,QAAQlB,cAAcO;uBAC5DK,iBAAiBI,wBAAwBN,oCAAoCT,iBAAiBiB,QAAQD"}
1
+ {"version":3,"file":"ToolNode.d.cts","names":["ToolMessage","RunnableConfig","RunnableToolLike","DynamicTool","StructuredToolInterface","ToolCall","InteropZodObject","Command","Send","RunnableCallable","PreHookAnnotation","AnyAnnotationRoot","ToAnnotationRoot","ToolNodeOptions","AbortSignal","ToolNode","StateSchema","ContextSchema","Promise","isSend"],"sources":["../../../src/agents/nodes/ToolNode.d.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport { ToolMessage } from \"@langchain/core/messages\";\nimport { RunnableConfig, RunnableToolLike } from \"@langchain/core/runnables\";\nimport { DynamicTool, StructuredToolInterface } from \"@langchain/core/tools\";\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\nimport type { InteropZodObject } from \"@langchain/core/utils/types\";\nimport { Command, Send } from \"@langchain/langgraph\";\nimport { RunnableCallable } from \"../RunnableCallable.js\";\nimport { PreHookAnnotation, AnyAnnotationRoot, ToAnnotationRoot } from \"../annotation.js\";\nexport interface ToolNodeOptions {\n /**\n * The name of the tool node.\n */\n name?: string;\n /**\n * The tags to add to the tool call.\n */\n tags?: string[];\n /**\n * The abort signal to cancel the tool call.\n */\n signal?: AbortSignal;\n /**\n * Whether to throw the error immediately if the tool fails or handle it by the `onToolError` function or via ToolMessage.\n *\n * If `true` (default):\n * - a tool message with the error will be returned to the LLM\n *\n * If `false`:\n * - the error will be thrown immediately\n *\n * If a function is provided:\n * - returns a custom {@link ToolMessage} as result\n * - throws an error otherwise\n *\n * @default true\n */\n handleToolErrors?: boolean | ((error: unknown, toolCall: ToolCall) => ToolMessage | undefined);\n}\n/**\n * `ToolNode` is a built-in LangGraph component that handles tool calls within an agent's workflow.\n * It works seamlessly with `createAgent`, offering advanced tool execution control, built\n * in parallelism, and error handling.\n *\n * @example\n * ```ts\n * import { ToolNode, tool, AIMessage } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * }),\n * });\n *\n * const tools = [getWeather];\n * const toolNode = new ToolNode(tools);\n *\n * const messageWithSingleToolCall = new AIMessage({\n * content: \"\",\n * tool_calls: [\n * {\n * name: \"get_weather\",\n * args: { location: \"sf\" },\n * id: \"tool_call_id\",\n * type: \"tool_call\",\n * }\n * ]\n * })\n *\n * await toolNode.invoke({ messages: [messageWithSingleToolCall] });\n * // Returns tool invocation responses as:\n * // { messages: ToolMessage[] }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport declare class ToolNode<StateSchema extends AnyAnnotationRoot | InteropZodObject = any, ContextSchema extends AnyAnnotationRoot | InteropZodObject = any> extends RunnableCallable<StateSchema, ContextSchema> {\n options?: ToolNodeOptions | undefined;\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[];\n trace: boolean;\n signal?: AbortSignal;\n handleToolErrors: boolean | ((error: unknown, toolCall: ToolCall) => ToolMessage | undefined);\n constructor(tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[], options?: ToolNodeOptions | undefined);\n protected runTool(call: ToolCall, config: RunnableConfig): Promise<ToolMessage | Command>;\n protected run(state: ToAnnotationRoot<StateSchema>[\"State\"] & PreHookAnnotation[\"State\"], config: RunnableConfig): Promise<ContextSchema>;\n}\nexport declare function isSend(x: unknown): x is Send;\n"],"mappings":";;;;;;;;;;UASiBa,eAAAA;EAAAA;;;EAYO,IAgBqCR,CAAAA,EAAAA,MAAAA;EAAQ;AAAgB;AA+CrF;EAA6B,IAAA,CAAA,EAAA,MAAA,EAAA;EAAA;;;EAAwG,MAAGC,CAAAA,EA/D3HQ,WA+D2HR;EAAgB;;;;;;;;;;;;;;;EAO5F,gBAAWN,CAAAA,EAAAA,OAAAA,GAAAA,CAAAA,CAAAA,KAAAA,EAAAA,OAAAA,EAAAA,QAAAA,EAtDVK,QAsDUL,EAAAA,GAtDGA,WAsDHA,GAAAA,SAAAA,CAAAA;;;;;;;;;;AAPiH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAnKe,6BAA6BJ,oBAAoBL,8CAA8CK,oBAAoBL,gCAAgCG,iBAAiBO,aAAaC;YACxLJ;UACFT,0BAA0BD,cAAcD;;WAEvCY;0DAC+CT,aAAaL;sBACjDI,0BAA0BD,cAAcD,+BAA+BW;0BACnER,kBAAkBJ,iBAAiBiB,QAAQlB,cAAcO;uBAC5DK,iBAAiBI,wBAAwBN,oCAAoCT,iBAAiBiB,QAAQD"}
@@ -40,7 +40,7 @@ interface ToolNodeOptions {
40
40
  }
41
41
  /**
42
42
  * `ToolNode` is a built-in LangGraph component that handles tool calls within an agent's workflow.
43
- * It works seamlessly with `createReactAgent`, offering advanced tool execution control, built
43
+ * It works seamlessly with `createAgent`, offering advanced tool execution control, built
44
44
  * in parallelism, and error handling.
45
45
  *
46
46
  * @example
@@ -1 +1 @@
1
- {"version":3,"file":"ToolNode.d.ts","names":["ToolMessage","RunnableConfig","RunnableToolLike","DynamicTool","StructuredToolInterface","ToolCall","InteropZodObject","Command","Send","RunnableCallable","PreHookAnnotation","AnyAnnotationRoot","ToAnnotationRoot","ToolNodeOptions","AbortSignal","ToolNode","StateSchema","ContextSchema","Promise","isSend"],"sources":["../../../src/agents/nodes/ToolNode.d.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport { ToolMessage } from \"@langchain/core/messages\";\nimport { RunnableConfig, RunnableToolLike } from \"@langchain/core/runnables\";\nimport { DynamicTool, StructuredToolInterface } from \"@langchain/core/tools\";\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\nimport type { InteropZodObject } from \"@langchain/core/utils/types\";\nimport { Command, Send } from \"@langchain/langgraph\";\nimport { RunnableCallable } from \"../RunnableCallable.js\";\nimport { PreHookAnnotation, AnyAnnotationRoot, ToAnnotationRoot } from \"../annotation.js\";\nexport interface ToolNodeOptions {\n /**\n * The name of the tool node.\n */\n name?: string;\n /**\n * The tags to add to the tool call.\n */\n tags?: string[];\n /**\n * The abort signal to cancel the tool call.\n */\n signal?: AbortSignal;\n /**\n * Whether to throw the error immediately if the tool fails or handle it by the `onToolError` function or via ToolMessage.\n *\n * If `true` (default):\n * - a tool message with the error will be returned to the LLM\n *\n * If `false`:\n * - the error will be thrown immediately\n *\n * If a function is provided:\n * - returns a custom {@link ToolMessage} as result\n * - throws an error otherwise\n *\n * @default true\n */\n handleToolErrors?: boolean | ((error: unknown, toolCall: ToolCall) => ToolMessage | undefined);\n}\n/**\n * `ToolNode` is a built-in LangGraph component that handles tool calls within an agent's workflow.\n * It works seamlessly with `createReactAgent`, offering advanced tool execution control, built\n * in parallelism, and error handling.\n *\n * @example\n * ```ts\n * import { ToolNode, tool, AIMessage } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * }),\n * });\n *\n * const tools = [getWeather];\n * const toolNode = new ToolNode(tools);\n *\n * const messageWithSingleToolCall = new AIMessage({\n * content: \"\",\n * tool_calls: [\n * {\n * name: \"get_weather\",\n * args: { location: \"sf\" },\n * id: \"tool_call_id\",\n * type: \"tool_call\",\n * }\n * ]\n * })\n *\n * await toolNode.invoke({ messages: [messageWithSingleToolCall] });\n * // Returns tool invocation responses as:\n * // { messages: ToolMessage[] }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport declare class ToolNode<StateSchema extends AnyAnnotationRoot | InteropZodObject = any, ContextSchema extends AnyAnnotationRoot | InteropZodObject = any> extends RunnableCallable<StateSchema, ContextSchema> {\n options?: ToolNodeOptions | undefined;\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[];\n trace: boolean;\n signal?: AbortSignal;\n handleToolErrors: boolean | ((error: unknown, toolCall: ToolCall) => ToolMessage | undefined);\n constructor(tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[], options?: ToolNodeOptions | undefined);\n protected runTool(call: ToolCall, config: RunnableConfig): Promise<ToolMessage | Command>;\n protected run(state: ToAnnotationRoot<StateSchema>[\"State\"] & PreHookAnnotation[\"State\"], config: RunnableConfig): Promise<ContextSchema>;\n}\nexport declare function isSend(x: unknown): x is Send;\n"],"mappings":";;;;;;;;;;UASiBa,eAAAA;EAAAA;;;EAYO,IAgBqCR,CAAAA,EAAAA,MAAAA;EAAQ;AAAgB;AA+CrF;EAA6B,IAAA,CAAA,EAAA,MAAA,EAAA;EAAA;;;EAAwG,MAAGC,CAAAA,EA/D3HQ,WA+D2HR;EAAgB;;;;;;;;;;;;;;;EAO5F,gBAAWN,CAAAA,EAAAA,OAAAA,GAAAA,CAAAA,CAAAA,KAAAA,EAAAA,OAAAA,EAAAA,QAAAA,EAtDVK,QAsDUL,EAAAA,GAtDGA,WAsDHA,GAAAA,SAAAA,CAAAA;;;;;;;;;;AAPiH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAnKe,6BAA6BJ,oBAAoBL,8CAA8CK,oBAAoBL,gCAAgCG,iBAAiBO,aAAaC;YACxLJ;UACFT,0BAA0BD,cAAcD;;WAEvCY;0DAC+CT,aAAaL;sBACjDI,0BAA0BD,cAAcD,+BAA+BW;0BACnER,kBAAkBJ,iBAAiBiB,QAAQlB,cAAcO;uBAC5DK,iBAAiBI,wBAAwBN,oCAAoCT,iBAAiBiB,QAAQD"}
1
+ {"version":3,"file":"ToolNode.d.ts","names":["ToolMessage","RunnableConfig","RunnableToolLike","DynamicTool","StructuredToolInterface","ToolCall","InteropZodObject","Command","Send","RunnableCallable","PreHookAnnotation","AnyAnnotationRoot","ToAnnotationRoot","ToolNodeOptions","AbortSignal","ToolNode","StateSchema","ContextSchema","Promise","isSend"],"sources":["../../../src/agents/nodes/ToolNode.d.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport { ToolMessage } from \"@langchain/core/messages\";\nimport { RunnableConfig, RunnableToolLike } from \"@langchain/core/runnables\";\nimport { DynamicTool, StructuredToolInterface } from \"@langchain/core/tools\";\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\nimport type { InteropZodObject } from \"@langchain/core/utils/types\";\nimport { Command, Send } from \"@langchain/langgraph\";\nimport { RunnableCallable } from \"../RunnableCallable.js\";\nimport { PreHookAnnotation, AnyAnnotationRoot, ToAnnotationRoot } from \"../annotation.js\";\nexport interface ToolNodeOptions {\n /**\n * The name of the tool node.\n */\n name?: string;\n /**\n * The tags to add to the tool call.\n */\n tags?: string[];\n /**\n * The abort signal to cancel the tool call.\n */\n signal?: AbortSignal;\n /**\n * Whether to throw the error immediately if the tool fails or handle it by the `onToolError` function or via ToolMessage.\n *\n * If `true` (default):\n * - a tool message with the error will be returned to the LLM\n *\n * If `false`:\n * - the error will be thrown immediately\n *\n * If a function is provided:\n * - returns a custom {@link ToolMessage} as result\n * - throws an error otherwise\n *\n * @default true\n */\n handleToolErrors?: boolean | ((error: unknown, toolCall: ToolCall) => ToolMessage | undefined);\n}\n/**\n * `ToolNode` is a built-in LangGraph component that handles tool calls within an agent's workflow.\n * It works seamlessly with `createAgent`, offering advanced tool execution control, built\n * in parallelism, and error handling.\n *\n * @example\n * ```ts\n * import { ToolNode, tool, AIMessage } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * }),\n * });\n *\n * const tools = [getWeather];\n * const toolNode = new ToolNode(tools);\n *\n * const messageWithSingleToolCall = new AIMessage({\n * content: \"\",\n * tool_calls: [\n * {\n * name: \"get_weather\",\n * args: { location: \"sf\" },\n * id: \"tool_call_id\",\n * type: \"tool_call\",\n * }\n * ]\n * })\n *\n * await toolNode.invoke({ messages: [messageWithSingleToolCall] });\n * // Returns tool invocation responses as:\n * // { messages: ToolMessage[] }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport declare class ToolNode<StateSchema extends AnyAnnotationRoot | InteropZodObject = any, ContextSchema extends AnyAnnotationRoot | InteropZodObject = any> extends RunnableCallable<StateSchema, ContextSchema> {\n options?: ToolNodeOptions | undefined;\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[];\n trace: boolean;\n signal?: AbortSignal;\n handleToolErrors: boolean | ((error: unknown, toolCall: ToolCall) => ToolMessage | undefined);\n constructor(tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[], options?: ToolNodeOptions | undefined);\n protected runTool(call: ToolCall, config: RunnableConfig): Promise<ToolMessage | Command>;\n protected run(state: ToAnnotationRoot<StateSchema>[\"State\"] & PreHookAnnotation[\"State\"], config: RunnableConfig): Promise<ContextSchema>;\n}\nexport declare function isSend(x: unknown): x is Send;\n"],"mappings":";;;;;;;;;;UASiBa,eAAAA;EAAAA;;;EAYO,IAgBqCR,CAAAA,EAAAA,MAAAA;EAAQ;AAAgB;AA+CrF;EAA6B,IAAA,CAAA,EAAA,MAAA,EAAA;EAAA;;;EAAwG,MAAGC,CAAAA,EA/D3HQ,WA+D2HR;EAAgB;;;;;;;;;;;;;;;EAO5F,gBAAWN,CAAAA,EAAAA,OAAAA,GAAAA,CAAAA,CAAAA,KAAAA,EAAAA,OAAAA,EAAAA,QAAAA,EAtDVK,QAsDUL,EAAAA,GAtDGA,WAsDHA,GAAAA,SAAAA,CAAAA;;;;;;;;;;AAPiH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAnKe,6BAA6BJ,oBAAoBL,8CAA8CK,oBAAoBL,gCAAgCG,iBAAiBO,aAAaC;YACxLJ;UACFT,0BAA0BD,cAAcD;;WAEvCY;0DAC+CT,aAAaL;sBACjDI,0BAA0BD,cAAcD,+BAA+BW;0BACnER,kBAAkBJ,iBAAiBiB,QAAQlB,cAAcO;uBAC5DK,iBAAiBI,wBAAwBN,oCAAoCT,iBAAiBiB,QAAQD"}
@@ -11,7 +11,7 @@ const isMessagesState = (input) => typeof input === "object" && input != null &&
11
11
  const isSendInput = (input) => typeof input === "object" && input != null && "lg_tool_call" in input;
12
12
  /**
13
13
  * `ToolNode` is a built-in LangGraph component that handles tool calls within an agent's workflow.
14
- * It works seamlessly with `createReactAgent`, offering advanced tool execution control, built
14
+ * It works seamlessly with `createAgent`, offering advanced tool execution control, built
15
15
  * in parallelism, and error handling.
16
16
  *
17
17
  * @example
@@ -116,7 +116,7 @@ var ToolNode = class extends RunnableCallable {
116
116
  if (result && isToolMessage(result)) return result;
117
117
  } else if (this.handleToolErrors) return new ToolMessage({
118
118
  name: call.name,
119
- content: `Error: ${e}\n Please fix your mistakes.`,
119
+ content: `${e}\n Please fix your mistakes.`,
120
120
  tool_call_id: call.id
121
121
  });
122
122
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ToolNode.js","names":["input: unknown","tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[]","options?: ToolNodeOptions","call: ToolCall","config: RunnableConfig","tool","e: unknown","state: ToAnnotationRoot<StateSchema>[\"State\"] & PreHookAnnotation[\"State\"]","outputs: (ToolMessage | Command)[]","messages: BaseMessage[]","toolMessageIds: Set<string>","aiMessage: AIMessage | undefined","combinedOutputs: (\n | { messages: BaseMessage[] }\n | BaseMessage[]\n | Command\n )[]","parentCommand: Command | null","x: unknown"],"sources":["../../../src/agents/nodes/ToolNode.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport {\n BaseMessage,\n ToolMessage,\n AIMessage,\n isBaseMessage,\n isToolMessage,\n} from \"@langchain/core/messages\";\nimport { RunnableConfig, RunnableToolLike } from \"@langchain/core/runnables\";\nimport {\n DynamicTool,\n StructuredToolInterface,\n ToolInputParsingException,\n} from \"@langchain/core/tools\";\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\nimport type { InteropZodObject } from \"@langchain/core/utils/types\";\nimport {\n isCommand,\n Command,\n Send,\n isGraphInterrupt,\n type NodeInterrupt,\n} from \"@langchain/langgraph\";\n\nimport { RunnableCallable } from \"../RunnableCallable.js\";\nimport {\n PreHookAnnotation,\n AnyAnnotationRoot,\n ToAnnotationRoot,\n} from \"../annotation.js\";\nimport { mergeAbortSignals } from \"./utils.js\";\nimport { ToolInvocationError } from \"../errors.js\";\n\nexport interface ToolNodeOptions {\n /**\n * The name of the tool node.\n */\n name?: string;\n /**\n * The tags to add to the tool call.\n */\n tags?: string[];\n /**\n * The abort signal to cancel the tool call.\n */\n signal?: AbortSignal;\n /**\n * Whether to throw the error immediately if the tool fails or handle it by the `onToolError` function or via ToolMessage.\n *\n * If `true` (default):\n * - a tool message with the error will be returned to the LLM\n *\n * If `false`:\n * - the error will be thrown immediately\n *\n * If a function is provided:\n * - returns a custom {@link ToolMessage} as result\n * - throws an error otherwise\n *\n * @default true\n */\n handleToolErrors?:\n | boolean\n | ((error: unknown, toolCall: ToolCall) => ToolMessage | undefined);\n}\n\nconst isBaseMessageArray = (input: unknown): input is BaseMessage[] =>\n Array.isArray(input) && input.every(isBaseMessage);\n\nconst isMessagesState = (\n input: unknown\n): input is { messages: BaseMessage[] } =>\n typeof input === \"object\" &&\n input != null &&\n \"messages\" in input &&\n isBaseMessageArray(input.messages);\n\nconst isSendInput = (input: unknown): input is { lg_tool_call: ToolCall } =>\n typeof input === \"object\" && input != null && \"lg_tool_call\" in input;\n\n/**\n * `ToolNode` is a built-in LangGraph component that handles tool calls within an agent's workflow.\n * It works seamlessly with `createReactAgent`, offering advanced tool execution control, built\n * in parallelism, and error handling.\n *\n * @example\n * ```ts\n * import { ToolNode, tool, AIMessage } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * }),\n * });\n *\n * const tools = [getWeather];\n * const toolNode = new ToolNode(tools);\n *\n * const messageWithSingleToolCall = new AIMessage({\n * content: \"\",\n * tool_calls: [\n * {\n * name: \"get_weather\",\n * args: { location: \"sf\" },\n * id: \"tool_call_id\",\n * type: \"tool_call\",\n * }\n * ]\n * })\n *\n * await toolNode.invoke({ messages: [messageWithSingleToolCall] });\n * // Returns tool invocation responses as:\n * // { messages: ToolMessage[] }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class ToolNode<\n StateSchema extends AnyAnnotationRoot | InteropZodObject = any,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = any\n> extends RunnableCallable<StateSchema, ContextSchema> {\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[];\n\n trace = false;\n\n signal?: AbortSignal;\n\n handleToolErrors:\n | boolean\n | ((error: unknown, toolCall: ToolCall) => ToolMessage | undefined) = true;\n\n constructor(\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[],\n public options?: ToolNodeOptions\n ) {\n const { name, tags, handleToolErrors } = options ?? {};\n super({\n name,\n tags,\n func: (state, config) =>\n this.run(\n state as ToAnnotationRoot<StateSchema>[\"State\"] &\n PreHookAnnotation[\"State\"],\n config as RunnableConfig\n ),\n });\n this.tools = tools;\n this.handleToolErrors = handleToolErrors ?? this.handleToolErrors;\n this.signal = options?.signal;\n }\n\n protected async runTool(\n call: ToolCall,\n config: RunnableConfig\n ): Promise<ToolMessage | Command> {\n const tool = this.tools.find((tool) => tool.name === call.name);\n try {\n if (tool === undefined) {\n throw new Error(`Tool \"${call.name}\" not found.`);\n }\n\n const output = await tool.invoke(\n { ...call, type: \"tool_call\" },\n {\n ...config,\n signal: mergeAbortSignals(this.signal, config.signal),\n }\n );\n\n if (\n (isBaseMessage(output) && output.getType() === \"tool\") ||\n isCommand(output)\n ) {\n return output as ToolMessage | Command;\n }\n\n return new ToolMessage({\n name: tool.name,\n content: typeof output === \"string\" ? output : JSON.stringify(output),\n tool_call_id: call.id!,\n });\n } catch (e: unknown) {\n /**\n * If tool invocation fails due to input parsing error, throw a {@link ToolInvocationError}\n */\n if (e instanceof ToolInputParsingException) {\n throw new ToolInvocationError(e, call);\n }\n\n /**\n * throw the error if user prefers not to handle tool errors\n */\n if (!this.handleToolErrors) {\n throw e;\n }\n\n if (isGraphInterrupt(e)) {\n /**\n * {@link NodeInterrupt} errors are a breakpoint to bring a human into the loop.\n * As such, they are not recoverable by the agent and shouldn't be fed\n * back. Instead, re-throw these errors even when `handleToolErrors = true`.\n */\n throw e;\n }\n\n /**\n * If the signal is aborted, we want to bubble up the error to the invoke caller.\n */\n if (this.signal?.aborted) {\n throw e;\n }\n\n /**\n * if the user provides a function, call it with the error and tool call\n * and return the result if it is a {@link ToolMessage}\n */\n if (typeof this.handleToolErrors === \"function\") {\n const result = this.handleToolErrors(e, call);\n if (result && isToolMessage(result)) {\n return result;\n }\n } else if (this.handleToolErrors) {\n return new ToolMessage({\n name: call.name,\n content: `Error: ${e}\\n Please fix your mistakes.`,\n tool_call_id: call.id!,\n });\n }\n\n /**\n * If the user doesn't handle the error, throw it\n */\n throw e;\n }\n }\n\n protected async run(\n state: ToAnnotationRoot<StateSchema>[\"State\"] & PreHookAnnotation[\"State\"],\n config: RunnableConfig\n ): Promise<ContextSchema> {\n let outputs: (ToolMessage | Command)[];\n\n if (isSendInput(state)) {\n outputs = [await this.runTool(state.lg_tool_call, config)];\n } else {\n let messages: BaseMessage[];\n if (isBaseMessageArray(state)) {\n messages = state;\n } else if (isMessagesState(state)) {\n messages = state.messages;\n } else {\n throw new Error(\n \"ToolNode only accepts BaseMessage[] or { messages: BaseMessage[] } as input.\"\n );\n }\n\n const toolMessageIds: Set<string> = new Set(\n messages\n .filter((msg) => msg.getType() === \"tool\")\n .map((msg) => (msg as ToolMessage).tool_call_id)\n );\n\n let aiMessage: AIMessage | undefined;\n for (let i = messages.length - 1; i >= 0; i -= 1) {\n const message = messages[i];\n if (message.getType() === \"ai\") {\n aiMessage = message;\n break;\n }\n }\n\n if (aiMessage?.getType() !== \"ai\") {\n throw new Error(\"ToolNode only accepts AIMessages as input.\");\n }\n\n outputs = await Promise.all(\n aiMessage.tool_calls\n ?.filter((call) => call.id == null || !toolMessageIds.has(call.id))\n .map((call) => this.runTool(call, config)) ?? []\n );\n }\n\n // Preserve existing behavior for non-command tool outputs for backwards compatibility\n if (!outputs.some(isCommand)) {\n return (Array.isArray(state)\n ? outputs\n : { messages: outputs }) as unknown as ContextSchema;\n }\n\n // Handle mixed Command and non-Command outputs\n const combinedOutputs: (\n | { messages: BaseMessage[] }\n | BaseMessage[]\n | Command\n )[] = [];\n let parentCommand: Command | null = null;\n\n for (const output of outputs) {\n if (isCommand(output)) {\n if (\n output.graph === Command.PARENT &&\n Array.isArray(output.goto) &&\n output.goto.every((send) => isSend(send))\n ) {\n if (parentCommand) {\n (parentCommand.goto as Send[]).push(...(output.goto as Send[]));\n } else {\n parentCommand = new Command({\n graph: Command.PARENT,\n goto: output.goto,\n });\n }\n } else {\n combinedOutputs.push(output);\n }\n } else {\n combinedOutputs.push(\n Array.isArray(state) ? [output] : { messages: [output] }\n );\n }\n }\n\n if (parentCommand) {\n combinedOutputs.push(parentCommand);\n }\n\n return combinedOutputs as unknown as ContextSchema;\n }\n}\n\nexport function isSend(x: unknown): x is Send {\n // eslint-disable-next-line no-instanceof/no-instanceof\n return x instanceof Send;\n}\n"],"mappings":";;;;;;;;AAkEA,MAAM,qBAAqB,CAACA,UAC1B,MAAM,QAAQ,MAAM,IAAI,MAAM,MAAM,cAAc;AAEpD,MAAM,kBAAkB,CACtBA,UAEA,OAAO,UAAU,YACjB,SAAS,QACT,cAAc,SACd,mBAAmB,MAAM,SAAS;AAEpC,MAAM,cAAc,CAACA,UACnB,OAAO,UAAU,YAAY,SAAS,QAAQ,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+ClE,IAAa,WAAb,cAGU,iBAA6C;CACrD;CAEA,QAAQ;CAER;CAEA,mBAEwE;CAExE,YACEC,OACOC,SACP;EACA,MAAM,EAAE,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAE;EACtD,MAAM;GACJ;GACA;GACA,MAAM,CAAC,OAAO,WACZ,KAAK,IACH,OAEA,OACD;EACJ,EAAC;EAZK;EAaP,KAAK,QAAQ;EACb,KAAK,mBAAmB,oBAAoB,KAAK;EACjD,KAAK,SAAS,SAAS;CACxB;CAED,MAAgB,QACdC,MACAC,QACgC;EAChC,MAAM,OAAO,KAAK,MAAM,KAAK,CAACC,WAASA,OAAK,SAAS,KAAK,KAAK;AAC/D,MAAI;AACF,OAAI,SAAS,OACX,OAAM,IAAI,MAAM,CAAC,MAAM,EAAE,KAAK,KAAK,YAAY,CAAC;GAGlD,MAAM,SAAS,MAAM,KAAK,OACxB;IAAE,GAAG;IAAM,MAAM;GAAa,GAC9B;IACE,GAAG;IACH,QAAQ,kBAA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MAAM;KAC9B,YAAY;AACZ;IACD;GACF;AAED,OAAI,WAAW,SAAS,KAAK,KAC3B,OAAM,IAAI,MAAM;GAGlB,UAAU,MAAM,QAAQ,IACtB,UAAU,YACN,OAAO,CAAC,SAAS,KAAK,MAAM,QAAQ,CAAC,eAAe,IAAI,KAAK,GAAG,CAAC,CAClE,IAAI,CAAC,SAAS,KAAK,QAAQ,MAAM,OAAO,CAAC,IAAI,CAAE,EACnD;EACF;AAGD,MAAI,CAAC,QAAQ,KAAK,UAAU,CAC1B,QAAQ,MAAM,QAAQ,MAAM,GACxB,UACA,EAAE,UAAU,QAAS;EAI3B,MAAMC,kBAIA,CAAE;EACR,IAAIC,gBAAgC;AAEpC,OAAK,MAAM,UAAU,QACnB,KAAI,UAAU,OAAO,CACnB,KACE,OAAO,UAAU,QAAQ,UACzB,MAAM,QAAQ,OAAO,KAAK,IAC1B,OAAO,KAAK,MAAM,CAAC,SAAS,OAAO,KAAK,CAAC,CAEzC,KAAI,eACD,cAAc,KAAgB,KAAK,GAAI,OAAO,KAAgB;OAE/D,gBAAgB,IAAI,QAAQ;GAC1B,OAAO,QAAQ;GACf,MAAM,OAAO;EACd;OAGH,gBAAgB,KAAK,OAAO;OAG9B,gBAAgB,KACd,MAAM,QAAQ,MAAM,GAAG,CAAC,MAAO,IAAG,EAAE,UAAU,CAAC,MAAO,EAAE,EACzD;AAIL,MAAI,eACF,gBAAgB,KAAK,cAAc;AAGrC,SAAO;CACR;AACF;AAED,SAAgB,OAAOC,GAAuB;AAE5C,QAAO,aAAa;AACrB"}
1
+ {"version":3,"file":"ToolNode.js","names":["input: unknown","tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[]","options?: ToolNodeOptions","call: ToolCall","config: RunnableConfig","tool","e: unknown","state: ToAnnotationRoot<StateSchema>[\"State\"] & PreHookAnnotation[\"State\"]","outputs: (ToolMessage | Command)[]","messages: BaseMessage[]","toolMessageIds: Set<string>","aiMessage: AIMessage | undefined","combinedOutputs: (\n | { messages: BaseMessage[] }\n | BaseMessage[]\n | Command\n )[]","parentCommand: Command | null","x: unknown"],"sources":["../../../src/agents/nodes/ToolNode.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport {\n BaseMessage,\n ToolMessage,\n AIMessage,\n isBaseMessage,\n isToolMessage,\n} from \"@langchain/core/messages\";\nimport { RunnableConfig, RunnableToolLike } from \"@langchain/core/runnables\";\nimport {\n DynamicTool,\n StructuredToolInterface,\n ToolInputParsingException,\n} from \"@langchain/core/tools\";\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\nimport type { InteropZodObject } from \"@langchain/core/utils/types\";\nimport {\n isCommand,\n Command,\n Send,\n isGraphInterrupt,\n type NodeInterrupt,\n} from \"@langchain/langgraph\";\n\nimport { RunnableCallable } from \"../RunnableCallable.js\";\nimport {\n PreHookAnnotation,\n AnyAnnotationRoot,\n ToAnnotationRoot,\n} from \"../annotation.js\";\nimport { mergeAbortSignals } from \"./utils.js\";\nimport { ToolInvocationError } from \"../errors.js\";\n\nexport interface ToolNodeOptions {\n /**\n * The name of the tool node.\n */\n name?: string;\n /**\n * The tags to add to the tool call.\n */\n tags?: string[];\n /**\n * The abort signal to cancel the tool call.\n */\n signal?: AbortSignal;\n /**\n * Whether to throw the error immediately if the tool fails or handle it by the `onToolError` function or via ToolMessage.\n *\n * If `true` (default):\n * - a tool message with the error will be returned to the LLM\n *\n * If `false`:\n * - the error will be thrown immediately\n *\n * If a function is provided:\n * - returns a custom {@link ToolMessage} as result\n * - throws an error otherwise\n *\n * @default true\n */\n handleToolErrors?:\n | boolean\n | ((error: unknown, toolCall: ToolCall) => ToolMessage | undefined);\n}\n\nconst isBaseMessageArray = (input: unknown): input is BaseMessage[] =>\n Array.isArray(input) && input.every(isBaseMessage);\n\nconst isMessagesState = (\n input: unknown\n): input is { messages: BaseMessage[] } =>\n typeof input === \"object\" &&\n input != null &&\n \"messages\" in input &&\n isBaseMessageArray(input.messages);\n\nconst isSendInput = (input: unknown): input is { lg_tool_call: ToolCall } =>\n typeof input === \"object\" && input != null && \"lg_tool_call\" in input;\n\n/**\n * `ToolNode` is a built-in LangGraph component that handles tool calls within an agent's workflow.\n * It works seamlessly with `createAgent`, offering advanced tool execution control, built\n * in parallelism, and error handling.\n *\n * @example\n * ```ts\n * import { ToolNode, tool, AIMessage } from \"langchain\";\n * import { z } from \"zod\";\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * }),\n * });\n *\n * const tools = [getWeather];\n * const toolNode = new ToolNode(tools);\n *\n * const messageWithSingleToolCall = new AIMessage({\n * content: \"\",\n * tool_calls: [\n * {\n * name: \"get_weather\",\n * args: { location: \"sf\" },\n * id: \"tool_call_id\",\n * type: \"tool_call\",\n * }\n * ]\n * })\n *\n * await toolNode.invoke({ messages: [messageWithSingleToolCall] });\n * // Returns tool invocation responses as:\n * // { messages: ToolMessage[] }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class ToolNode<\n StateSchema extends AnyAnnotationRoot | InteropZodObject = any,\n ContextSchema extends AnyAnnotationRoot | InteropZodObject = any\n> extends RunnableCallable<StateSchema, ContextSchema> {\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[];\n\n trace = false;\n\n signal?: AbortSignal;\n\n handleToolErrors:\n | boolean\n | ((error: unknown, toolCall: ToolCall) => ToolMessage | undefined) = true;\n\n constructor(\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[],\n public options?: ToolNodeOptions\n ) {\n const { name, tags, handleToolErrors } = options ?? {};\n super({\n name,\n tags,\n func: (state, config) =>\n this.run(\n state as ToAnnotationRoot<StateSchema>[\"State\"] &\n PreHookAnnotation[\"State\"],\n config as RunnableConfig\n ),\n });\n this.tools = tools;\n this.handleToolErrors = handleToolErrors ?? this.handleToolErrors;\n this.signal = options?.signal;\n }\n\n protected async runTool(\n call: ToolCall,\n config: RunnableConfig\n ): Promise<ToolMessage | Command> {\n const tool = this.tools.find((tool) => tool.name === call.name);\n try {\n if (tool === undefined) {\n throw new Error(`Tool \"${call.name}\" not found.`);\n }\n\n const output = await tool.invoke(\n { ...call, type: \"tool_call\" },\n {\n ...config,\n signal: mergeAbortSignals(this.signal, config.signal),\n }\n );\n\n if (\n (isBaseMessage(output) && output.getType() === \"tool\") ||\n isCommand(output)\n ) {\n return output as ToolMessage | Command;\n }\n\n return new ToolMessage({\n name: tool.name,\n content: typeof output === \"string\" ? output : JSON.stringify(output),\n tool_call_id: call.id!,\n });\n } catch (e: unknown) {\n /**\n * If tool invocation fails due to input parsing error, throw a {@link ToolInvocationError}\n */\n if (e instanceof ToolInputParsingException) {\n throw new ToolInvocationError(e, call);\n }\n\n /**\n * throw the error if user prefers not to handle tool errors\n */\n if (!this.handleToolErrors) {\n throw e;\n }\n\n if (isGraphInterrupt(e)) {\n /**\n * {@link NodeInterrupt} errors are a breakpoint to bring a human into the loop.\n * As such, they are not recoverable by the agent and shouldn't be fed\n * back. Instead, re-throw these errors even when `handleToolErrors = true`.\n */\n throw e;\n }\n\n /**\n * If the signal is aborted, we want to bubble up the error to the invoke caller.\n */\n if (this.signal?.aborted) {\n throw e;\n }\n\n /**\n * if the user provides a function, call it with the error and tool call\n * and return the result if it is a {@link ToolMessage}\n */\n if (typeof this.handleToolErrors === \"function\") {\n const result = this.handleToolErrors(e, call);\n if (result && isToolMessage(result)) {\n return result;\n }\n } else if (this.handleToolErrors) {\n return new ToolMessage({\n name: call.name,\n content: `${e}\\n Please fix your mistakes.`,\n tool_call_id: call.id!,\n });\n }\n\n /**\n * If the user doesn't handle the error, throw it\n */\n throw e;\n }\n }\n\n protected async run(\n state: ToAnnotationRoot<StateSchema>[\"State\"] & PreHookAnnotation[\"State\"],\n config: RunnableConfig\n ): Promise<ContextSchema> {\n let outputs: (ToolMessage | Command)[];\n\n if (isSendInput(state)) {\n outputs = [await this.runTool(state.lg_tool_call, config)];\n } else {\n let messages: BaseMessage[];\n if (isBaseMessageArray(state)) {\n messages = state;\n } else if (isMessagesState(state)) {\n messages = state.messages;\n } else {\n throw new Error(\n \"ToolNode only accepts BaseMessage[] or { messages: BaseMessage[] } as input.\"\n );\n }\n\n const toolMessageIds: Set<string> = new Set(\n messages\n .filter((msg) => msg.getType() === \"tool\")\n .map((msg) => (msg as ToolMessage).tool_call_id)\n );\n\n let aiMessage: AIMessage | undefined;\n for (let i = messages.length - 1; i >= 0; i -= 1) {\n const message = messages[i];\n if (message.getType() === \"ai\") {\n aiMessage = message;\n break;\n }\n }\n\n if (aiMessage?.getType() !== \"ai\") {\n throw new Error(\"ToolNode only accepts AIMessages as input.\");\n }\n\n outputs = await Promise.all(\n aiMessage.tool_calls\n ?.filter((call) => call.id == null || !toolMessageIds.has(call.id))\n .map((call) => this.runTool(call, config)) ?? []\n );\n }\n\n // Preserve existing behavior for non-command tool outputs for backwards compatibility\n if (!outputs.some(isCommand)) {\n return (Array.isArray(state)\n ? outputs\n : { messages: outputs }) as unknown as ContextSchema;\n }\n\n // Handle mixed Command and non-Command outputs\n const combinedOutputs: (\n | { messages: BaseMessage[] }\n | BaseMessage[]\n | Command\n )[] = [];\n let parentCommand: Command | null = null;\n\n for (const output of outputs) {\n if (isCommand(output)) {\n if (\n output.graph === Command.PARENT &&\n Array.isArray(output.goto) &&\n output.goto.every((send) => isSend(send))\n ) {\n if (parentCommand) {\n (parentCommand.goto as Send[]).push(...(output.goto as Send[]));\n } else {\n parentCommand = new Command({\n graph: Command.PARENT,\n goto: output.goto,\n });\n }\n } else {\n combinedOutputs.push(output);\n }\n } else {\n combinedOutputs.push(\n Array.isArray(state) ? [output] : { messages: [output] }\n );\n }\n }\n\n if (parentCommand) {\n combinedOutputs.push(parentCommand);\n }\n\n return combinedOutputs as unknown as ContextSchema;\n }\n}\n\nexport function isSend(x: unknown): x is Send {\n // eslint-disable-next-line no-instanceof/no-instanceof\n return x instanceof Send;\n}\n"],"mappings":";;;;;;;;AAkEA,MAAM,qBAAqB,CAACA,UAC1B,MAAM,QAAQ,MAAM,IAAI,MAAM,MAAM,cAAc;AAEpD,MAAM,kBAAkB,CACtBA,UAEA,OAAO,UAAU,YACjB,SAAS,QACT,cAAc,SACd,mBAAmB,MAAM,SAAS;AAEpC,MAAM,cAAc,CAACA,UACnB,OAAO,UAAU,YAAY,SAAS,QAAQ,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+ClE,IAAa,WAAb,cAGU,iBAA6C;CACrD;CAEA,QAAQ;CAER;CAEA,mBAEwE;CAExE,YACEC,OACOC,SACP;EACA,MAAM,EAAE,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAE;EACtD,MAAM;GACJ;GACA;GACA,MAAM,CAAC,OAAO,WACZ,KAAK,IACH,OAEA,OACD;EACJ,EAAC;EAZK;EAaP,KAAK,QAAQ;EACb,KAAK,mBAAmB,oBAAoB,KAAK;EACjD,KAAK,SAAS,SAAS;CACxB;CAED,MAAgB,QACdC,MACAC,QACgC;EAChC,MAAM,OAAO,KAAK,MAAM,KAAK,CAACC,WAASA,OAAK,SAAS,KAAK,KAAK;AAC/D,MAAI;AACF,OAAI,SAAS,OACX,OAAM,IAAI,MAAM,CAAC,MAAM,EAAE,KAAK,KAAK,YAAY,CAAC;GAGlD,MAAM,SAAS,MAAM,KAAK,OACxB;IAAE,GAAG;IAAM,MAAM;GAAa,GAC9B;IACE,GAAG;IACH,QAAQ,kBAAkB,KAAK,QAAQ,OAAO,OAAO;GACtD,EACF;AAED,OACG,cAAc,OAAO,IAAI,OAAO,SAAS,KAAK,UAC/C,UAAU,OAAO,CAEjB,QAAO;AAGT,UAAO,IAAI,YAAY;IACrB,MAAM,KAAK;IACX,SAAS,OAAO,WAAW,WAAW,SAAS,KAAK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,IAAI,CAAC,SAAS,KAAK,QAAQ,MAAM,OAAO,CAAC,IAAI,CAAE,EACnD;EACF;AAGD,MAAI,CAAC,QAAQ,KAAK,UAAU,CAC1B,QAAQ,MAAM,QAAQ,MAAM,GACxB,UACA,EAAE,UAAU,QAAS;EAI3B,MAAMC,kBAIA,CAAE;EACR,IAAIC,gBAAgC;AAEpC,OAAK,MAAM,UAAU,QACnB,KAAI,UAAU,OAAO,CACnB,KACE,OAAO,UAAU,QAAQ,UACzB,MAAM,QAAQ,OAAO,KAAK,IAC1B,OAAO,KAAK,MAAM,CAAC,SAAS,OAAO,KAAK,CAAC,CAEzC,KAAI,eACD,cAAc,KAAgB,KAAK,GAAI,OAAO,KAAgB;OAE/D,gBAAgB,IAAI,QAAQ;GAC1B,OAAO,QAAQ;GACf,MAAM,OAAO;EACd;OAGH,gBAAgB,KAAK,OAAO;OAG9B,gBAAgB,KACd,MAAM,QAAQ,MAAM,GAAG,CAAC,MAAO,IAAG,EAAE,UAAU,CAAC,MAAO,EAAE,EACzD;AAIL,MAAI,eACF,gBAAgB,KAAK,cAAc;AAGrC,SAAO;CACR;AACF;AAED,SAAgB,OAAOC,GAAuB;AAE5C,QAAO,aAAa;AACrB"}
@@ -49,12 +49,11 @@ var ToolStrategy = class ToolStrategy {
49
49
  else functionDefinition = {
50
50
  name: getFunctionName(schema.title),
51
51
  description: schema.description ?? "",
52
- parameters: schema
52
+ parameters: schema.schema || schema
53
53
  };
54
54
  const asJsonSchema = (0, __langchain_core_utils_json_schema.toJsonSchema)(schema);
55
55
  const tool = {
56
56
  type: "function",
57
- name: getFunctionName(),
58
57
  function: functionDefinition
59
58
  };
60
59
  return new ToolStrategy(asJsonSchema, tool, outputOptions);
@@ -103,7 +102,7 @@ var ProviderStrategy = class ProviderStrategy {
103
102
  }
104
103
  };
105
104
  /**
106
- * Handle user input for `responseFormat` parameter of `CreateReactAgentParams`.
105
+ * Handle user input for `responseFormat` parameter of `CreateAgentParams`.
107
106
  * This function defines the default behavior for the `responseFormat` parameter, which is:
108
107
  *
109
108
  * - if value is a Zod schema, default to structured output via tool calling
@@ -1 +1 @@
1
- {"version":3,"file":"responses.cjs","names":["schema: Record<string, unknown>","tool: {\n type: \"function\";\n function: FunctionDefinition;\n }","options?: ToolStrategyOptions","schema: InteropZodObject | Record<string, unknown>","options?: {\n name?: string;\n description?: string;\n strict?: boolean;\n }","outputOptions?: ToolStrategyOptions","name?: string","asJsonSchema","tool","functionDefinition: FunctionDefinition","toolArgs: Record<string, unknown>","Validator","StructuredOutputParsingError","schema: InteropZodType<T> | Record<string, unknown>","response: AIMessage","responseFormat?:\n | InteropZodType<any>\n | InteropZodType<any>[]\n | JsonSchemaFormat\n | JsonSchemaFormat[]\n | ResponseFormat\n | ToolStrategy<any>[]\n | ResponseFormatUndefined","responseFormat:\n | InteropZodType<any>\n | InteropZodType<any>[]\n | JsonSchemaFormat\n | JsonSchemaFormat[]","responseFormat: InteropZodType<any> | JsonSchemaFormat"],"sources":["../../src/agents/responses.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport {\n InteropZodObject,\n isInteropZodSchema,\n InteropZodType,\n isInteropZodObject,\n} from \"@langchain/core/utils/types\";\nimport { type AIMessage } from \"@langchain/core/messages\";\nimport { toJsonSchema, Validator } from \"@langchain/core/utils/json_schema\";\nimport { type FunctionDefinition } from \"@langchain/core/language_models/base\";\n\nimport {\n StructuredOutputParsingError,\n MultipleStructuredOutputsError,\n} from \"./errors.js\";\n\n/**\n * This is a global counter for generating unique names for tools.\n */\nlet bindingIdentifier = 0;\n\n/**\n * Information for tracking structured output tool metadata.\n * This contains all necessary information to handle structured responses generated\n * via tool calls, including the original schema, its type classification, and the\n * corresponding tool implementation used by the tools strategy.\n */\nexport class ToolStrategy<_T = unknown> {\n private constructor(\n /**\n * The original JSON Schema provided for structured output\n */\n public readonly schema: Record<string, unknown>,\n\n /**\n * The tool that will be used to parse the tool call arguments.\n */\n public readonly tool: {\n type: \"function\";\n function: FunctionDefinition;\n },\n\n /**\n * The options to use for the tool output.\n */\n public readonly options?: ToolStrategyOptions\n ) {}\n\n get name() {\n return this.tool.function.name;\n }\n\n static fromSchema<S extends InteropZodObject>(\n schema: S,\n options?: {\n name?: string;\n description?: string;\n strict?: boolean;\n },\n outputOptions?: ToolStrategyOptions\n ): ToolStrategy<S extends InteropZodType<infer U> ? U : unknown>;\n\n static fromSchema(\n schema: Record<string, unknown>,\n options?: {\n name?: string;\n description?: string;\n strict?: boolean;\n },\n outputOptions?: ToolStrategyOptions\n ): ToolStrategy<Record<string, unknown>>;\n\n static fromSchema(\n schema: InteropZodObject | Record<string, unknown>,\n options?: {\n name?: string;\n description?: string;\n strict?: boolean;\n },\n outputOptions?: ToolStrategyOptions\n ): ToolStrategy<any> {\n /**\n * It is required for tools to have a name so we can map the tool call to the correct tool\n * when parsing the response.\n */\n function getFunctionName(name?: string) {\n return name ?? options?.name ?? `extract-${++bindingIdentifier}`;\n }\n\n if (isInteropZodSchema(schema)) {\n const asJsonSchema = toJsonSchema(schema);\n const tool = {\n type: \"function\" as const,\n function: {\n name: getFunctionName(),\n strict: options?.strict,\n description:\n options?.description ??\n asJsonSchema.description ??\n \"Tool for extracting structured output from the model's response.\",\n parameters: asJsonSchema,\n },\n };\n return new ToolStrategy(asJsonSchema, tool, outputOptions);\n }\n\n let functionDefinition: FunctionDefinition;\n if (\n typeof schema.name === \"string\" &&\n typeof schema.parameters === \"object\" &&\n schema.parameters != null\n ) {\n functionDefinition = schema as unknown as FunctionDefinition;\n } else {\n functionDefinition = {\n name: getFunctionName(schema.title as string),\n description: (schema.description as string) ?? \"\",\n parameters: schema,\n };\n }\n const asJsonSchema = toJsonSchema(schema);\n const tool = {\n type: \"function\" as const,\n name: getFunctionName(),\n function: functionDefinition,\n };\n return new ToolStrategy(asJsonSchema, tool, outputOptions);\n }\n\n /**\n * Parse tool arguments according to the schema.\n *\n * @throws {StructuredOutputParsingError} if the response is not valid\n * @param toolArgs - The arguments from the tool call\n * @returns The parsed response according to the schema type\n */\n parse(toolArgs: Record<string, unknown>): Record<string, unknown> {\n const validator = new Validator(this.schema);\n const result = validator.validate(toolArgs);\n if (!result.valid) {\n throw new StructuredOutputParsingError(\n this.name,\n result.errors.map((e) => e.error)\n );\n }\n return toolArgs;\n }\n}\n\nexport class ProviderStrategy<T = unknown> {\n // @ts-expect-error - _schemaType is used only for type inference\n private _schemaType?: T;\n\n private constructor(public readonly schema: Record<string, unknown>) {}\n\n static fromSchema<T>(schema: InteropZodType<T>): ProviderStrategy<T>;\n\n static fromSchema(\n schema: Record<string, unknown>\n ): ProviderStrategy<Record<string, unknown>>;\n\n static fromSchema<T = unknown>(\n schema: InteropZodType<T> | Record<string, unknown>\n ): ProviderStrategy<T> | ProviderStrategy<Record<string, unknown>> {\n const asJsonSchema = toJsonSchema(schema);\n return new ProviderStrategy(asJsonSchema) as\n | ProviderStrategy<T>\n | ProviderStrategy<Record<string, unknown>>;\n }\n\n /**\n * Parse tool arguments according to the schema. If the response is not valid, return undefined.\n *\n * @param toolArgs - The arguments from the tool call\n * @returns The parsed response according to the schema type\n */\n parse(response: AIMessage) {\n /**\n * return if the response doesn't contain valid content\n */\n if (typeof response.content !== \"string\" || response.content === \"\") {\n return;\n }\n\n try {\n const content = JSON.parse(response.content);\n const validator = new Validator(this.schema);\n const result = validator.validate(content);\n if (!result.valid) {\n return;\n }\n\n return content;\n } catch (error) {\n // no-op\n }\n }\n}\n\nexport type ResponseFormat = ToolStrategy<any> | ProviderStrategy<any>;\n\n/**\n * Handle user input for `responseFormat` parameter of `CreateReactAgentParams`.\n * This function defines the default behavior for the `responseFormat` parameter, which is:\n *\n * - if value is a Zod schema, default to structured output via tool calling\n * - if value is a JSON schema, default to structured output via tool calling\n * - if value is a custom response format, return it as is\n * - if value is an array, ensure all array elements are instance of `ToolStrategy`\n * @param responseFormat\n * @returns\n */\nexport function transformResponseFormat(\n responseFormat?:\n | InteropZodType<any>\n | InteropZodType<any>[]\n | JsonSchemaFormat\n | JsonSchemaFormat[]\n | ResponseFormat\n | ToolStrategy<any>[]\n | ResponseFormatUndefined,\n options?: ToolStrategyOptions\n): ResponseFormat[] {\n if (!responseFormat) {\n return [];\n }\n\n // Handle ResponseFormatUndefined case\n if (\n typeof responseFormat === \"object\" &&\n responseFormat !== null &&\n \"__responseFormatUndefined\" in responseFormat\n ) {\n return [];\n }\n\n /**\n * If users provide an array, it should only contain raw schemas (Zod or JSON schema),\n * not ToolStrategy or ProviderStrategy instances.\n */\n if (Array.isArray(responseFormat)) {\n /**\n * if every entry is a ToolStrategy or ProviderStrategy instance, return the array as is\n */\n if (\n responseFormat.every(\n (item) =>\n item instanceof ToolStrategy || item instanceof ProviderStrategy\n )\n ) {\n return responseFormat as unknown as ResponseFormat[];\n }\n\n /**\n * Check if all items are Zod schemas\n */\n if (responseFormat.every((item) => isInteropZodObject(item))) {\n return responseFormat.map((item) =>\n ToolStrategy.fromSchema(item as InteropZodObject, undefined, options)\n );\n }\n\n /**\n * Check if all items are plain objects (JSON schema)\n */\n if (\n responseFormat.every(\n (item) =>\n typeof item === \"object\" && item !== null && !isInteropZodObject(item)\n )\n ) {\n return responseFormat.map((item) =>\n ToolStrategy.fromSchema(item as JsonSchemaFormat, undefined, options)\n );\n }\n\n throw new Error(\n `Invalid response format: list contains mixed types.\\n` +\n `All items must be either InteropZodObject or plain JSON schema objects.`\n );\n }\n\n if (isInteropZodObject(responseFormat)) {\n return [ToolStrategy.fromSchema(responseFormat, undefined, options)];\n }\n\n if (\n responseFormat instanceof ToolStrategy ||\n responseFormat instanceof ProviderStrategy\n ) {\n return [responseFormat];\n }\n\n /**\n * Handle plain object (JSON schema)\n */\n if (\n typeof responseFormat === \"object\" &&\n responseFormat !== null &&\n \"properties\" in responseFormat\n ) {\n return [\n ToolStrategy.fromSchema(\n responseFormat as JsonSchemaFormat,\n undefined,\n options\n ),\n ];\n }\n\n throw new Error(`Invalid response format: ${String(responseFormat)}`);\n}\n\n/**\n * Branded type for ToolStrategy arrays that preserves type information\n */\nexport interface TypedToolStrategy<T = unknown>\n extends Array<ToolStrategy<any>> {\n _schemaType?: T;\n}\nexport type ToolStrategyError =\n | StructuredOutputParsingError\n | MultipleStructuredOutputsError;\nexport interface ToolStrategyOptions {\n /**\n * Handle errors from the structured output tool call. Using tools to generate structured output\n * can cause errors, e.g. if:\n * - you provide multiple structured output schemas and the model calls multiple structured output tools\n * - if the structured output generated by the tool call doesn't match provided schema\n *\n * This property allows to handle these errors in different ways:\n * - `true` - retry the tool call\n * - `false` - throw an error\n * - `string` - retry the tool call with the provided message\n * - `(error: ToolStrategyError) => Promise<string> | string` - retry with the provided message or throw the error\n */\n handleError?:\n | boolean\n | string\n | ((error: ToolStrategyError) => Promise<string> | string);\n}\n\nexport function toolStrategy<T extends InteropZodType<any>>(\n responseFormat: T,\n options?: ToolStrategyOptions\n): TypedToolStrategy<T extends InteropZodType<infer U> ? U : never>;\nexport function toolStrategy<T extends readonly InteropZodType<any>[]>(\n responseFormat: T,\n options?: ToolStrategyOptions\n): TypedToolStrategy<\n { [K in keyof T]: T[K] extends InteropZodType<infer U> ? U : never }[number]\n>;\nexport function toolStrategy(\n responseFormat: JsonSchemaFormat,\n options?: ToolStrategyOptions\n): TypedToolStrategy<Record<string, unknown>>;\nexport function toolStrategy(\n responseFormat: JsonSchemaFormat[],\n options?: ToolStrategyOptions\n): TypedToolStrategy<Record<string, unknown>>;\n\n/**\n * Define how to transform the response format from a tool call.\n *\n * @param responseFormat - The response format to transform\n * @param options - The options to use for the transformation\n * @param options.handleError - Whether to handle errors from the tool call\n * @returns The transformed response format\n */\nexport function toolStrategy(\n responseFormat:\n | InteropZodType<any>\n | InteropZodType<any>[]\n | JsonSchemaFormat\n | JsonSchemaFormat[],\n options?: ToolStrategyOptions\n): TypedToolStrategy {\n return transformResponseFormat(responseFormat, options) as TypedToolStrategy;\n}\n\nexport function providerStrategy<T extends InteropZodType<any>>(\n responseFormat: T\n): ProviderStrategy<T extends InteropZodType<infer U> ? U : never>;\nexport function providerStrategy(\n responseFormat: JsonSchemaFormat\n): ProviderStrategy<Record<string, unknown>>;\nexport function providerStrategy(\n responseFormat: InteropZodType<any> | JsonSchemaFormat\n): ProviderStrategy<any> {\n return ProviderStrategy.fromSchema(\n responseFormat as any\n ) as ProviderStrategy<any>;\n}\n\n/**\n * Special type to indicate that no response format is provided.\n * When this type is used, the structuredResponse property should not be present in the result.\n */\nexport type ResponseFormatUndefined = {\n __responseFormatUndefined: true;\n};\n\n/**\n * Type representing a JSON Schema object format.\n * This is a strict type that excludes ToolStrategy and ProviderStrategy instances.\n */\nexport type JsonSchemaFormat = {\n type:\n | \"null\"\n | \"boolean\"\n | \"object\"\n | \"array\"\n | \"number\"\n | \"string\"\n | \"integer\";\n properties?: Record<string, unknown>;\n required?: string[];\n additionalProperties?: boolean;\n [key: string]: unknown;\n} & {\n // Brand to ensure this is not a ToolStrategy or ProviderStrategy\n __brand?: never;\n};\n"],"mappings":";;;;;;;;;AAmBA,IAAI,oBAAoB;;;;;;;AAQxB,IAAa,eAAb,MAAa,aAA2B;CACtC,AAAQ,YAIUA,QAKAC,MAQAC,SAChB;EAdgB;EAKA;EAQA;CACd;CAEJ,IAAI,OAAO;AACT,SAAO,KAAK,KAAK,SAAS;CAC3B;CAsBD,OAAO,WACLC,QACAC,SAKAC,eACmB;;;;;EAKnB,SAAS,gBAAgBC,MAAe;AACtC,UAAO,QAAQ,SAAS,QAAQ,CAAC,QAAQ,EAAE,EAAE,mBAAmB;EACjE;AAED,2DAAuB,OAAO,EAAE;GAC9B,MAAMC,sEAA4B,OAAO;GACzC,MAAMC,SAAO;IACX,MAAM;IACN,UAAU;KACR,MAAM,iBAAiB;KACvB,QAAQ,SAAS;KACjB,aACE,SAAS,eACTD,eAAa,eACb;KACF,YAAYA;IACb;GACF;AACD,UAAO,IAAI,aAAaA,gBAAcC,QAAM;EAC7C;EAED,IAAIC;AACJ,MACE,OAAO,OAAO,SAAS,YACvB,OAAO,OAAO,eAAe,YAC7B,O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;AAMT,MAAI,eAAe,MAAM,CAAC,8DAA4B,KAAK,CAAC,CAC1D,QAAO,eAAe,IAAI,CAAC,SACzB,aAAa,WAAW,MAA0B,QAAW,QAAQ,CACtE;;;;AAMH,MACE,eAAe,MACb,CAAC,SACC,OAAO,SAAS,YAAY,SAAS,QAAQ,sDAAoB,KAAK,CACzE,CAED,QAAO,eAAe,IAAI,CAAC,SACzB,aAAa,WAAW,MAA0B,QAAW,QAAQ,CACtE;AAGH,QAAM,IAAI,MACR;CAGH;AAED,0DAAuB,eAAe,CACpC,QAAO,CAAC,aAAa,WAAW,gBAAgB,QAAW,QAAQ,AAAC;AAGtE,KACE,0BAA0B,gBAC1B,0BAA0B,iBAE1B,QAAO,CAAC,cAAe;;;;AAMzB,KACE,OAAO,mBAAmB,YAC1B,mBAAmB,QACnB,gBAAgB,eAEhB,QAAO,CACL,aAAa,WACX,gBACA,QACA,QACD,AACF;AAGH,OAAM,IAAI,MAAM,CAAC,yBAAyB,EAAE,OAAO,eAAe,EAAE;AACrE;;;;;;;;;AA0DD,SAAgB,aACdc,gBAKAd,SACmB;AACnB,QAAO,wBAAwB,gBAAgB,QAAQ;AACxD;AAQD,SAAgB,iBACde,gBACuB;AACvB,QAAO,iBAAiB,WACtB,eACD;AACF"}
1
+ {"version":3,"file":"responses.cjs","names":["schema: Record<string, unknown>","tool: {\n type: \"function\";\n function: FunctionDefinition;\n }","options?: ToolStrategyOptions","schema: InteropZodObject | Record<string, unknown>","options?: {\n name?: string;\n description?: string;\n strict?: boolean;\n }","outputOptions?: ToolStrategyOptions","name?: string","asJsonSchema","tool","functionDefinition: FunctionDefinition","toolArgs: Record<string, unknown>","Validator","StructuredOutputParsingError","schema: InteropZodType<T> | Record<string, unknown>","response: AIMessage","responseFormat?:\n | InteropZodType<any>\n | InteropZodType<any>[]\n | JsonSchemaFormat\n | JsonSchemaFormat[]\n | ResponseFormat\n | ToolStrategy<any>[]\n | ResponseFormatUndefined","responseFormat:\n | InteropZodType<any>\n | InteropZodType<any>[]\n | JsonSchemaFormat\n | JsonSchemaFormat[]","responseFormat: InteropZodType<any> | JsonSchemaFormat"],"sources":["../../src/agents/responses.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport {\n InteropZodObject,\n isInteropZodSchema,\n InteropZodType,\n isInteropZodObject,\n} from \"@langchain/core/utils/types\";\nimport { type AIMessage } from \"@langchain/core/messages\";\nimport { toJsonSchema, Validator } from \"@langchain/core/utils/json_schema\";\nimport { type FunctionDefinition } from \"@langchain/core/language_models/base\";\n\nimport {\n StructuredOutputParsingError,\n MultipleStructuredOutputsError,\n} from \"./errors.js\";\n\n/**\n * This is a global counter for generating unique names for tools.\n */\nlet bindingIdentifier = 0;\n\n/**\n * Information for tracking structured output tool metadata.\n * This contains all necessary information to handle structured responses generated\n * via tool calls, including the original schema, its type classification, and the\n * corresponding tool implementation used by the tools strategy.\n */\nexport class ToolStrategy<_T = unknown> {\n private constructor(\n /**\n * The original JSON Schema provided for structured output\n */\n public readonly schema: Record<string, unknown>,\n\n /**\n * The tool that will be used to parse the tool call arguments.\n */\n public readonly tool: {\n type: \"function\";\n function: FunctionDefinition;\n },\n\n /**\n * The options to use for the tool output.\n */\n public readonly options?: ToolStrategyOptions\n ) {}\n\n get name() {\n return this.tool.function.name;\n }\n\n static fromSchema<S extends InteropZodObject>(\n schema: S,\n options?: {\n name?: string;\n description?: string;\n strict?: boolean;\n },\n outputOptions?: ToolStrategyOptions\n ): ToolStrategy<S extends InteropZodType<infer U> ? U : unknown>;\n\n static fromSchema(\n schema: Record<string, unknown>,\n options?: {\n name?: string;\n description?: string;\n strict?: boolean;\n },\n outputOptions?: ToolStrategyOptions\n ): ToolStrategy<Record<string, unknown>>;\n\n static fromSchema(\n schema: InteropZodObject | Record<string, unknown>,\n options?: {\n name?: string;\n description?: string;\n strict?: boolean;\n },\n outputOptions?: ToolStrategyOptions\n ): ToolStrategy<any> {\n /**\n * It is required for tools to have a name so we can map the tool call to the correct tool\n * when parsing the response.\n */\n function getFunctionName(name?: string) {\n return name ?? options?.name ?? `extract-${++bindingIdentifier}`;\n }\n\n if (isInteropZodSchema(schema)) {\n const asJsonSchema = toJsonSchema(schema);\n const tool = {\n type: \"function\" as const,\n function: {\n name: getFunctionName(),\n strict: options?.strict,\n description:\n options?.description ??\n asJsonSchema.description ??\n \"Tool for extracting structured output from the model's response.\",\n parameters: asJsonSchema,\n },\n };\n return new ToolStrategy(asJsonSchema, tool, outputOptions);\n }\n\n let functionDefinition: FunctionDefinition;\n if (\n typeof schema.name === \"string\" &&\n typeof schema.parameters === \"object\" &&\n schema.parameters != null\n ) {\n functionDefinition = schema as unknown as FunctionDefinition;\n } else {\n functionDefinition = {\n name: getFunctionName(schema.title as string),\n description: (schema.description as string) ?? \"\",\n parameters: schema.schema || (schema as Record<string, unknown>),\n };\n }\n const asJsonSchema = toJsonSchema(schema);\n const tool = {\n type: \"function\" as const,\n function: functionDefinition,\n };\n return new ToolStrategy(asJsonSchema, tool, outputOptions);\n }\n\n /**\n * Parse tool arguments according to the schema.\n *\n * @throws {StructuredOutputParsingError} if the response is not valid\n * @param toolArgs - The arguments from the tool call\n * @returns The parsed response according to the schema type\n */\n parse(toolArgs: Record<string, unknown>): Record<string, unknown> {\n const validator = new Validator(this.schema);\n const result = validator.validate(toolArgs);\n if (!result.valid) {\n throw new StructuredOutputParsingError(\n this.name,\n result.errors.map((e) => e.error)\n );\n }\n return toolArgs;\n }\n}\n\nexport class ProviderStrategy<T = unknown> {\n // @ts-expect-error - _schemaType is used only for type inference\n private _schemaType?: T;\n\n private constructor(public readonly schema: Record<string, unknown>) {}\n\n static fromSchema<T>(schema: InteropZodType<T>): ProviderStrategy<T>;\n\n static fromSchema(\n schema: Record<string, unknown>\n ): ProviderStrategy<Record<string, unknown>>;\n\n static fromSchema<T = unknown>(\n schema: InteropZodType<T> | Record<string, unknown>\n ): ProviderStrategy<T> | ProviderStrategy<Record<string, unknown>> {\n const asJsonSchema = toJsonSchema(schema);\n return new ProviderStrategy(asJsonSchema) as\n | ProviderStrategy<T>\n | ProviderStrategy<Record<string, unknown>>;\n }\n\n /**\n * Parse tool arguments according to the schema. If the response is not valid, return undefined.\n *\n * @param toolArgs - The arguments from the tool call\n * @returns The parsed response according to the schema type\n */\n parse(response: AIMessage) {\n /**\n * return if the response doesn't contain valid content\n */\n if (typeof response.content !== \"string\" || response.content === \"\") {\n return;\n }\n\n try {\n const content = JSON.parse(response.content);\n const validator = new Validator(this.schema);\n const result = validator.validate(content);\n if (!result.valid) {\n return;\n }\n\n return content;\n } catch (error) {\n // no-op\n }\n }\n}\n\nexport type ResponseFormat = ToolStrategy<any> | ProviderStrategy<any>;\n\n/**\n * Handle user input for `responseFormat` parameter of `CreateAgentParams`.\n * This function defines the default behavior for the `responseFormat` parameter, which is:\n *\n * - if value is a Zod schema, default to structured output via tool calling\n * - if value is a JSON schema, default to structured output via tool calling\n * - if value is a custom response format, return it as is\n * - if value is an array, ensure all array elements are instance of `ToolStrategy`\n * @param responseFormat\n * @returns\n */\nexport function transformResponseFormat(\n responseFormat?:\n | InteropZodType<any>\n | InteropZodType<any>[]\n | JsonSchemaFormat\n | JsonSchemaFormat[]\n | ResponseFormat\n | ToolStrategy<any>[]\n | ResponseFormatUndefined,\n options?: ToolStrategyOptions\n): ResponseFormat[] {\n if (!responseFormat) {\n return [];\n }\n\n // Handle ResponseFormatUndefined case\n if (\n typeof responseFormat === \"object\" &&\n responseFormat !== null &&\n \"__responseFormatUndefined\" in responseFormat\n ) {\n return [];\n }\n\n /**\n * If users provide an array, it should only contain raw schemas (Zod or JSON schema),\n * not ToolStrategy or ProviderStrategy instances.\n */\n if (Array.isArray(responseFormat)) {\n /**\n * if every entry is a ToolStrategy or ProviderStrategy instance, return the array as is\n */\n if (\n responseFormat.every(\n (item) =>\n item instanceof ToolStrategy || item instanceof ProviderStrategy\n )\n ) {\n return responseFormat as unknown as ResponseFormat[];\n }\n\n /**\n * Check if all items are Zod schemas\n */\n if (responseFormat.every((item) => isInteropZodObject(item))) {\n return responseFormat.map((item) =>\n ToolStrategy.fromSchema(item as InteropZodObject, undefined, options)\n );\n }\n\n /**\n * Check if all items are plain objects (JSON schema)\n */\n if (\n responseFormat.every(\n (item) =>\n typeof item === \"object\" && item !== null && !isInteropZodObject(item)\n )\n ) {\n return responseFormat.map((item) =>\n ToolStrategy.fromSchema(item as JsonSchemaFormat, undefined, options)\n );\n }\n\n throw new Error(\n `Invalid response format: list contains mixed types.\\n` +\n `All items must be either InteropZodObject or plain JSON schema objects.`\n );\n }\n\n if (isInteropZodObject(responseFormat)) {\n return [ToolStrategy.fromSchema(responseFormat, undefined, options)];\n }\n\n if (\n responseFormat instanceof ToolStrategy ||\n responseFormat instanceof ProviderStrategy\n ) {\n return [responseFormat];\n }\n\n /**\n * Handle plain object (JSON schema)\n */\n if (\n typeof responseFormat === \"object\" &&\n responseFormat !== null &&\n \"properties\" in responseFormat\n ) {\n return [\n ToolStrategy.fromSchema(\n responseFormat as JsonSchemaFormat,\n undefined,\n options\n ),\n ];\n }\n\n throw new Error(`Invalid response format: ${String(responseFormat)}`);\n}\n\n/**\n * Branded type for ToolStrategy arrays that preserves type information\n */\nexport interface TypedToolStrategy<T = unknown>\n extends Array<ToolStrategy<any>> {\n _schemaType?: T;\n}\nexport type ToolStrategyError =\n | StructuredOutputParsingError\n | MultipleStructuredOutputsError;\nexport interface ToolStrategyOptions {\n /**\n * Allows you to customize the message that appears in the conversation history when structured\n * output is generated.\n */\n toolMessageContent?: string;\n /**\n * Handle errors from the structured output tool call. Using tools to generate structured output\n * can cause errors, e.g. if:\n * - you provide multiple structured output schemas and the model calls multiple structured output tools\n * - if the structured output generated by the tool call doesn't match provided schema\n *\n * This property allows to handle these errors in different ways:\n * - `true` - retry the tool call\n * - `false` - throw an error\n * - `string` - retry the tool call with the provided message\n * - `(error: ToolStrategyError) => Promise<string> | string` - retry with the provided message or throw the error\n */\n handleError?:\n | boolean\n | string\n | ((error: ToolStrategyError) => Promise<string> | string);\n}\n\nexport function toolStrategy<T extends InteropZodType<any>>(\n responseFormat: T,\n options?: ToolStrategyOptions\n): TypedToolStrategy<T extends InteropZodType<infer U> ? U : never>;\nexport function toolStrategy<T extends readonly InteropZodType<any>[]>(\n responseFormat: T,\n options?: ToolStrategyOptions\n): TypedToolStrategy<\n { [K in keyof T]: T[K] extends InteropZodType<infer U> ? U : never }[number]\n>;\nexport function toolStrategy(\n responseFormat: JsonSchemaFormat,\n options?: ToolStrategyOptions\n): TypedToolStrategy<Record<string, unknown>>;\nexport function toolStrategy(\n responseFormat: JsonSchemaFormat[],\n options?: ToolStrategyOptions\n): TypedToolStrategy<Record<string, unknown>>;\n\n/**\n * Define how to transform the response format from a tool call.\n *\n * @param responseFormat - The response format to transform\n * @param options - The options to use for the transformation\n * @param options.handleError - Whether to handle errors from the tool call\n * @returns The transformed response format\n */\nexport function toolStrategy(\n responseFormat:\n | InteropZodType<any>\n | InteropZodType<any>[]\n | JsonSchemaFormat\n | JsonSchemaFormat[],\n options?: ToolStrategyOptions\n): TypedToolStrategy {\n return transformResponseFormat(responseFormat, options) as TypedToolStrategy;\n}\n\nexport function providerStrategy<T extends InteropZodType<any>>(\n responseFormat: T\n): ProviderStrategy<T extends InteropZodType<infer U> ? U : never>;\nexport function providerStrategy(\n responseFormat: JsonSchemaFormat\n): ProviderStrategy<Record<string, unknown>>;\nexport function providerStrategy(\n responseFormat: InteropZodType<any> | JsonSchemaFormat\n): ProviderStrategy<any> {\n return ProviderStrategy.fromSchema(\n responseFormat as any\n ) as ProviderStrategy<any>;\n}\n\n/**\n * Special type to indicate that no response format is provided.\n * When this type is used, the structuredResponse property should not be present in the result.\n */\nexport type ResponseFormatUndefined = {\n __responseFormatUndefined: true;\n};\n\n/**\n * Type representing a JSON Schema object format.\n * This is a strict type that excludes ToolStrategy and ProviderStrategy instances.\n */\nexport type JsonSchemaFormat = {\n type:\n | \"null\"\n | \"boolean\"\n | \"object\"\n | \"array\"\n | \"number\"\n | \"string\"\n | \"integer\";\n properties?: Record<string, unknown>;\n required?: string[];\n additionalProperties?: boolean;\n [key: string]: unknown;\n} & {\n // Brand to ensure this is not a ToolStrategy or ProviderStrategy\n __brand?: never;\n};\n"],"mappings":";;;;;;;;;AAmBA,IAAI,oBAAoB;;;;;;;AAQxB,IAAa,eAAb,MAAa,aAA2B;CACtC,AAAQ,YAIUA,QAKAC,MAQAC,SAChB;EAdgB;EAKA;EAQA;CACd;CAEJ,IAAI,OAAO;AACT,SAAO,KAAK,KAAK,SAAS;CAC3B;CAsBD,OAAO,WACLC,QACAC,SAKAC,eACmB;;;;;EAKnB,SAAS,gBAAgBC,MAAe;AACtC,UAAO,QAAQ,SAAS,QAAQ,CAAC,QAAQ,EAAE,EAAE,mBAAmB;EACjE;AAED,2DAAuB,OAAO,EAAE;GAC9B,MAAMC,sEAA4B,OAAO;GACzC,MAAMC,SAAO;IACX,MAAM;IACN,UAAU;KACR,MAAM,iBAAiB;KACvB,QAAQ,SAAS;KACjB,aACE,SAAS,eACTD,eAAa,eACb;KACF,YAAYA;IACb;GACF;AACD,UAAO,IAAI,aAAaA,gBAAcC,QAAM;EAC7C;EAED,IAAIC;AACJ,MACE,OAAO,OAAO,SAAS,YACvB,OAAO,OAAO,eAAe,YAC7B,OAAO,cAAc,MAErB,qBAAqB;OAErB,qBAAqB;GACnB,MAAM,gBAAgB,OAAO,MAAgB;GAC7C,aAAc,OAAO,eAA0B;GAC/C,YAAY,OAAO,UAAW;EAC/B;EAEH,MAAM,oEAA4B,OAAO;EACzC,MAAM,OAAO;GACX,MAAM;GACN,UAAU;EACX;AACD,SAAO,IAAI,aAAa,cAAc,MAAM;CAC7C;;;;;;;;CASD,MAAMC,UAA4D;EAChE,MAAM,YAAY,IAAIC,6CAAU,KAAK;EACrC,MAAM,SAAS,UAAU,SAAS,SAAS;AAC3C,MAAI,CAAC,OAAO,MACV,OAAM,IAAIC,4CACR,KAAK,MACL,OAAO,OAAO,IAAI,CAAC,MAAM,EAAE,MAAM;AAGrC,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AMzB,KACE,OAAO,mBAAmB,YAC1B,mBAAmB,QACnB,gBAAgB,eAEhB,QAAO,CACL,aAAa,WACX,gBACA,QACA,QACD,AACF;AAGH,OAAM,IAAI,MAAM,CAAC,yBAAyB,EAAE,OAAO,eAAe,EAAE;AACrE;;;;;;;;;AA+DD,SAAgB,aACdc,gBAKAd,SACmB;AACnB,QAAO,wBAAwB,gBAAgB,QAAQ;AACxD;AAQD,SAAgB,iBACde,gBACuB;AACvB,QAAO,iBAAiB,WACtB,eACD;AACF"}
@@ -56,7 +56,7 @@ declare class ProviderStrategy<T = unknown> {
56
56
  }
57
57
  type ResponseFormat = ToolStrategy<any> | ProviderStrategy<any>;
58
58
  /**
59
- * Handle user input for `responseFormat` parameter of `CreateReactAgentParams`.
59
+ * Handle user input for `responseFormat` parameter of `CreateAgentParams`.
60
60
  * This function defines the default behavior for the `responseFormat` parameter, which is:
61
61
  *
62
62
  * - if value is a Zod schema, default to structured output via tool calling
@@ -75,6 +75,11 @@ interface TypedToolStrategy<T = unknown> extends Array<ToolStrategy<any>> {
75
75
  }
76
76
  type ToolStrategyError = StructuredOutputParsingError | MultipleStructuredOutputsError;
77
77
  interface ToolStrategyOptions {
78
+ /**
79
+ * Allows you to customize the message that appears in the conversation history when structured
80
+ * output is generated.
81
+ */
82
+ toolMessageContent?: string;
78
83
  /**
79
84
  * Handle errors from the structured output tool call. Using tools to generate structured output
80
85
  * can cause errors, e.g. if:
@@ -1 +1 @@
1
- {"version":3,"file":"responses.d.cts","names":["InteropZodObject","InteropZodType","AIMessage","FunctionDefinition","StructuredOutputParsingError","MultipleStructuredOutputsError","ToolStrategy","Record","ToolStrategyOptions","S","U","ProviderStrategy","T","ResponseFormat","transformResponseFormat","JsonSchemaFormat","ResponseFormatUndefined","TypedToolStrategy","Array","ToolStrategyError","Promise","toolStrategy","K","providerStrategy"],"sources":["../../src/agents/responses.d.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport { InteropZodObject, InteropZodType } from \"@langchain/core/utils/types\";\nimport { type AIMessage } from \"@langchain/core/messages\";\nimport { type FunctionDefinition } from \"@langchain/core/language_models/base\";\nimport { StructuredOutputParsingError, MultipleStructuredOutputsError } from \"./errors.js\";\n/**\n * Information for tracking structured output tool metadata.\n * This contains all necessary information to handle structured responses generated\n * via tool calls, including the original schema, its type classification, and the\n * corresponding tool implementation used by the tools strategy.\n */\nexport declare class ToolStrategy<_T = unknown> {\n readonly schema: Record<string, unknown>;\n readonly tool: {\n type: \"function\";\n function: FunctionDefinition;\n };\n readonly options?: ToolStrategyOptions | undefined;\n private constructor();\n get name(): string;\n static fromSchema<S extends InteropZodObject>(schema: S, options?: {\n name?: string;\n description?: string;\n strict?: boolean;\n }, outputOptions?: ToolStrategyOptions): ToolStrategy<S extends InteropZodType<infer U> ? U : unknown>;\n static fromSchema(schema: Record<string, unknown>, options?: {\n name?: string;\n description?: string;\n strict?: boolean;\n }, outputOptions?: ToolStrategyOptions): ToolStrategy<Record<string, unknown>>;\n /**\n * Parse tool arguments according to the schema.\n *\n * @throws {StructuredOutputParsingError} if the response is not valid\n * @param toolArgs - The arguments from the tool call\n * @returns The parsed response according to the schema type\n */\n parse(toolArgs: Record<string, unknown>): Record<string, unknown>;\n}\nexport declare class ProviderStrategy<T = unknown> {\n readonly schema: Record<string, unknown>;\n // @ts-expect-error - _schemaType is used only for type inference\n private _schemaType?;\n private constructor();\n static fromSchema<T>(schema: InteropZodType<T>): ProviderStrategy<T>;\n static fromSchema(schema: Record<string, unknown>): ProviderStrategy<Record<string, unknown>>;\n /**\n * Parse tool arguments according to the schema. If the response is not valid, return undefined.\n *\n * @param toolArgs - The arguments from the tool call\n * @returns The parsed response according to the schema type\n */\n parse(response: AIMessage): any;\n}\nexport type ResponseFormat = ToolStrategy<any> | ProviderStrategy<any>;\n/**\n * Handle user input for `responseFormat` parameter of `CreateReactAgentParams`.\n * This function defines the default behavior for the `responseFormat` parameter, which is:\n *\n * - if value is a Zod schema, default to structured output via tool calling\n * - if value is a JSON schema, default to structured output via tool calling\n * - if value is a custom response format, return it as is\n * - if value is an array, ensure all array elements are instance of `ToolStrategy`\n * @param responseFormat\n * @returns\n */\nexport declare function transformResponseFormat(responseFormat?: InteropZodType<any> | InteropZodType<any>[] | JsonSchemaFormat | JsonSchemaFormat[] | ResponseFormat | ToolStrategy<any>[] | ResponseFormatUndefined, options?: ToolStrategyOptions): ResponseFormat[];\n/**\n * Branded type for ToolStrategy arrays that preserves type information\n */\nexport interface TypedToolStrategy<T = unknown> extends Array<ToolStrategy<any>> {\n _schemaType?: T;\n}\nexport type ToolStrategyError = StructuredOutputParsingError | MultipleStructuredOutputsError;\nexport interface ToolStrategyOptions {\n /**\n * Handle errors from the structured output tool call. Using tools to generate structured output\n * can cause errors, e.g. if:\n * - you provide multiple structured output schemas and the model calls multiple structured output tools\n * - if the structured output generated by the tool call doesn't match provided schema\n *\n * This property allows to handle these errors in different ways:\n * - `true` - retry the tool call\n * - `false` - throw an error\n * - `string` - retry the tool call with the provided message\n * - `(error: ToolStrategyError) => Promise<string> | string` - retry with the provided message or throw the error\n */\n handleError?: boolean | string | ((error: ToolStrategyError) => Promise<string> | string);\n}\nexport declare function toolStrategy<T extends InteropZodType<any>>(responseFormat: T, options?: ToolStrategyOptions): TypedToolStrategy<T extends InteropZodType<infer U> ? U : never>;\nexport declare function toolStrategy<T extends readonly InteropZodType<any>[]>(responseFormat: T, options?: ToolStrategyOptions): TypedToolStrategy<{\n [K in keyof T]: T[K] extends InteropZodType<infer U> ? U : never;\n}[number]>;\nexport declare function toolStrategy(responseFormat: JsonSchemaFormat, options?: ToolStrategyOptions): TypedToolStrategy<Record<string, unknown>>;\nexport declare function toolStrategy(responseFormat: JsonSchemaFormat[], options?: ToolStrategyOptions): TypedToolStrategy<Record<string, unknown>>;\nexport declare function providerStrategy<T extends InteropZodType<any>>(responseFormat: T): ProviderStrategy<T extends InteropZodType<infer U> ? U : never>;\nexport declare function providerStrategy(responseFormat: JsonSchemaFormat): ProviderStrategy<Record<string, unknown>>;\n/**\n * Special type to indicate that no response format is provided.\n * When this type is used, the structuredResponse property should not be present in the result.\n */\nexport type ResponseFormatUndefined = {\n __responseFormatUndefined: true;\n};\n/**\n * Type representing a JSON Schema object format.\n * This is a strict type that excludes ToolStrategy and ProviderStrategy instances.\n */\nexport type JsonSchemaFormat = {\n type: \"null\" | \"boolean\" | \"object\" | \"array\" | \"number\" | \"string\" | \"integer\";\n properties?: Record<string, unknown>;\n required?: string[];\n additionalProperties?: boolean;\n [key: string]: unknown;\n} & {\n // Brand to ensure this is not a ToolStrategy or ProviderStrategy\n __brand?: never;\n};\n"],"mappings":";;;;;;;;AAWA;;;;;AASgCA,cATXM,YASWN,CAAAA,KAAAA,OAAAA,CAAAA,CAAAA;EAAgB,SAAUS,MAAAA,EARrCF,MAQqCE,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;EAAC,SAIpCD,IAAAA,EAAAA;IAAmCC,IAAAA,EAAAA,UAAAA;IAAUR,QAAAA,EATlDE,kBASkDF;EAAc,CAAA;EAAa,SAAlDK,OAAAA,CAAAA,EAPtBE,mBAOsBF,GAAAA,SAAAA;EAAY,QAC3BC,WAAAA,CAAAA;EAAM,IAIbC,IAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAmB,OAAgBD,UAAAA,CAAAA,UAT1BP,gBAS0BO,CAAAA,CAAAA,MAAAA,EATAE,CASAF,EAAAA,OAQN,CARMA,EAAAA;IAAbD,IAAAA,CAAAA,EAAAA,MAAAA;IAQzBC,WAAAA,CAAAA,EAAAA,MAAAA;IAA0BA,MAAAA,CAAAA,EAAAA,OAAAA;EAAM,CAAA,EAAA,aAAA,CAAA,EAb7BC,mBAa6B,CAAA,EAbPF,YAaO,CAbMG,CAaN,SAbgBR,cAahB,CAAA,KAAA,EAAA,CAAA,GAb0CS,CAa1C,GAAA,OAAA,CAAA;EAE/BC,OAAAA,UAAAA,CAAAA,MAAgB,EAdPJ,MAcO,CAAA,MAAA,EAAA,OAAA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,OAAA,CAAA,EAD2CP,mBAC3C,CAAA,EADiES,iBACjE,CADmFV,MACnF,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;AAAA,iBAAhBgB,gBAAgB,CAAA,UAAWtB,cAAX,CAAA,GAAA,CAAA,CAAA,CAAA,cAAA,EAAgDW,CAAhD,CAAA,EAAoDD,gBAApD,CAAqEC,CAArE,SAA+EX,cAA/E,CAAA,KAAA,EAAA,CAAA,GAAyGS,CAAzG,GAAA,KAAA,CAAA;AAAWT,iBAC3BsB,gBAAAA,CAD2BtB,cAAAA,EACMc,gBADNd,CAAAA,EACyBU,gBADzBV,CAC0CM,MAD1CN,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,CAAAA;;;;;AAAyCU,KAMhFK,uBAAAA,GANgFL;EAAgB,yBAAA,EAAA,IAAA;AAC5G,CAAA;;;;;AAA4F,KAYhFI,gBAAAA,GAZgF;EAKhFC,IAAAA,EAAAA,MAAAA,GAAAA,SAAAA,GAAuB,QAAA,GAAA,OAAA,GAAA,QAAA,GAAA,QAAA,GAAA,SAAA;EAOvBD,UAAAA,CAAAA,EAEKR,MAFW,CAAA,MAAA,EAAA,OAEXA,CAAAA"}
1
+ {"version":3,"file":"responses.d.cts","names":["InteropZodObject","InteropZodType","AIMessage","FunctionDefinition","StructuredOutputParsingError","MultipleStructuredOutputsError","ToolStrategy","Record","ToolStrategyOptions","S","U","ProviderStrategy","T","ResponseFormat","transformResponseFormat","JsonSchemaFormat","ResponseFormatUndefined","TypedToolStrategy","Array","ToolStrategyError","Promise","toolStrategy","K","providerStrategy"],"sources":["../../src/agents/responses.d.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport { InteropZodObject, InteropZodType } from \"@langchain/core/utils/types\";\nimport { type AIMessage } from \"@langchain/core/messages\";\nimport { type FunctionDefinition } from \"@langchain/core/language_models/base\";\nimport { StructuredOutputParsingError, MultipleStructuredOutputsError } from \"./errors.js\";\n/**\n * Information for tracking structured output tool metadata.\n * This contains all necessary information to handle structured responses generated\n * via tool calls, including the original schema, its type classification, and the\n * corresponding tool implementation used by the tools strategy.\n */\nexport declare class ToolStrategy<_T = unknown> {\n readonly schema: Record<string, unknown>;\n readonly tool: {\n type: \"function\";\n function: FunctionDefinition;\n };\n readonly options?: ToolStrategyOptions | undefined;\n private constructor();\n get name(): string;\n static fromSchema<S extends InteropZodObject>(schema: S, options?: {\n name?: string;\n description?: string;\n strict?: boolean;\n }, outputOptions?: ToolStrategyOptions): ToolStrategy<S extends InteropZodType<infer U> ? U : unknown>;\n static fromSchema(schema: Record<string, unknown>, options?: {\n name?: string;\n description?: string;\n strict?: boolean;\n }, outputOptions?: ToolStrategyOptions): ToolStrategy<Record<string, unknown>>;\n /**\n * Parse tool arguments according to the schema.\n *\n * @throws {StructuredOutputParsingError} if the response is not valid\n * @param toolArgs - The arguments from the tool call\n * @returns The parsed response according to the schema type\n */\n parse(toolArgs: Record<string, unknown>): Record<string, unknown>;\n}\nexport declare class ProviderStrategy<T = unknown> {\n readonly schema: Record<string, unknown>;\n // @ts-expect-error - _schemaType is used only for type inference\n private _schemaType?;\n private constructor();\n static fromSchema<T>(schema: InteropZodType<T>): ProviderStrategy<T>;\n static fromSchema(schema: Record<string, unknown>): ProviderStrategy<Record<string, unknown>>;\n /**\n * Parse tool arguments according to the schema. If the response is not valid, return undefined.\n *\n * @param toolArgs - The arguments from the tool call\n * @returns The parsed response according to the schema type\n */\n parse(response: AIMessage): any;\n}\nexport type ResponseFormat = ToolStrategy<any> | ProviderStrategy<any>;\n/**\n * Handle user input for `responseFormat` parameter of `CreateAgentParams`.\n * This function defines the default behavior for the `responseFormat` parameter, which is:\n *\n * - if value is a Zod schema, default to structured output via tool calling\n * - if value is a JSON schema, default to structured output via tool calling\n * - if value is a custom response format, return it as is\n * - if value is an array, ensure all array elements are instance of `ToolStrategy`\n * @param responseFormat\n * @returns\n */\nexport declare function transformResponseFormat(responseFormat?: InteropZodType<any> | InteropZodType<any>[] | JsonSchemaFormat | JsonSchemaFormat[] | ResponseFormat | ToolStrategy<any>[] | ResponseFormatUndefined, options?: ToolStrategyOptions): ResponseFormat[];\n/**\n * Branded type for ToolStrategy arrays that preserves type information\n */\nexport interface TypedToolStrategy<T = unknown> extends Array<ToolStrategy<any>> {\n _schemaType?: T;\n}\nexport type ToolStrategyError = StructuredOutputParsingError | MultipleStructuredOutputsError;\nexport interface ToolStrategyOptions {\n /**\n * Allows you to customize the message that appears in the conversation history when structured\n * output is generated.\n */\n toolMessageContent?: string;\n /**\n * Handle errors from the structured output tool call. Using tools to generate structured output\n * can cause errors, e.g. if:\n * - you provide multiple structured output schemas and the model calls multiple structured output tools\n * - if the structured output generated by the tool call doesn't match provided schema\n *\n * This property allows to handle these errors in different ways:\n * - `true` - retry the tool call\n * - `false` - throw an error\n * - `string` - retry the tool call with the provided message\n * - `(error: ToolStrategyError) => Promise<string> | string` - retry with the provided message or throw the error\n */\n handleError?: boolean | string | ((error: ToolStrategyError) => Promise<string> | string);\n}\nexport declare function toolStrategy<T extends InteropZodType<any>>(responseFormat: T, options?: ToolStrategyOptions): TypedToolStrategy<T extends InteropZodType<infer U> ? U : never>;\nexport declare function toolStrategy<T extends readonly InteropZodType<any>[]>(responseFormat: T, options?: ToolStrategyOptions): TypedToolStrategy<{\n [K in keyof T]: T[K] extends InteropZodType<infer U> ? U : never;\n}[number]>;\nexport declare function toolStrategy(responseFormat: JsonSchemaFormat, options?: ToolStrategyOptions): TypedToolStrategy<Record<string, unknown>>;\nexport declare function toolStrategy(responseFormat: JsonSchemaFormat[], options?: ToolStrategyOptions): TypedToolStrategy<Record<string, unknown>>;\nexport declare function providerStrategy<T extends InteropZodType<any>>(responseFormat: T): ProviderStrategy<T extends InteropZodType<infer U> ? U : never>;\nexport declare function providerStrategy(responseFormat: JsonSchemaFormat): ProviderStrategy<Record<string, unknown>>;\n/**\n * Special type to indicate that no response format is provided.\n * When this type is used, the structuredResponse property should not be present in the result.\n */\nexport type ResponseFormatUndefined = {\n __responseFormatUndefined: true;\n};\n/**\n * Type representing a JSON Schema object format.\n * This is a strict type that excludes ToolStrategy and ProviderStrategy instances.\n */\nexport type JsonSchemaFormat = {\n type: \"null\" | \"boolean\" | \"object\" | \"array\" | \"number\" | \"string\" | \"integer\";\n properties?: Record<string, unknown>;\n required?: string[];\n additionalProperties?: boolean;\n [key: string]: unknown;\n} & {\n // Brand to ensure this is not a ToolStrategy or ProviderStrategy\n __brand?: never;\n};\n"],"mappings":";;;;;;;;AAWA;;;;;AASgCA,cATXM,YASWN,CAAAA,KAAAA,OAAAA,CAAAA,CAAAA;EAAgB,SAAUS,MAAAA,EARrCF,MAQqCE,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;EAAC,SAIpCD,IAAAA,EAAAA;IAAmCC,IAAAA,EAAAA,UAAAA;IAAUR,QAAAA,EATlDE,kBASkDF;EAAc,CAAA;EAAa,SAAlDK,OAAAA,CAAAA,EAPtBE,mBAOsBF,GAAAA,SAAAA;EAAY,QAC3BC,WAAAA,CAAAA;EAAM,IAIbC,IAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAmB,OAAgBD,UAAAA,CAAAA,UAT1BP,gBAS0BO,CAAAA,CAAAA,MAAAA,EATAE,CASAF,EAAAA,OAQN,CARMA,EAAAA;IAAbD,IAAAA,CAAAA,EAAAA,MAAAA;IAQzBC,WAAAA,CAAAA,EAAAA,MAAAA;IAA0BA,MAAAA,CAAAA,EAAAA,OAAAA;EAAM,CAAA,EAAA,aAAA,CAAA,EAb7BC,mBAa6B,CAAA,EAbPF,YAaO,CAbMG,CAaN,SAbgBR,cAahB,CAAA,KAAA,EAAA,CAAA,GAb0CS,CAa1C,GAAA,OAAA,CAAA;EAE/BC,OAAAA,UAAAA,CAAAA,MAAgB,EAdPJ,MAcO,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,OAKY,CALZ,EAAA;IAAA,IAAA,CAAA,EAAA,MAAA;IAChBA,WAAAA,CAAAA,EAAAA,MAAAA;IAI2BK,MA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M,MACJN,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,CAAAA;AAA0BS,iBAAzHa,gBAAyHb,CAAAA,UAA9FT,cAA8FS,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,cAAAA,EAAzDE,CAAyDF,CAAAA,EAArDC,gBAAqDD,CAApCE,CAAoCF,SAA1BT,cAA0BS,CAAAA,KAAAA,EAAAA,CAAAA,GAAAA,CAAAA,GAAAA,KAAAA,CAAAA;AAArDC,iBACpEY,gBAAAA,CADoEZ,cAAAA,EACnCI,gBADmCJ,CAAAA,EAChBA,gBADgBA,CACCJ,MADDI,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,CAAAA;AAAgB;AAC5G;;;AAA6FJ,KAKjFS,uBAAAA,GALiFT;EAAM,yBAAvBI,EAAAA,IAAAA;AAAgB,CAAA;AAK5F;AAOA;;;KAAYI,gBAAAA;;eAEKR"}
@@ -56,7 +56,7 @@ declare class ProviderStrategy<T = unknown> {
56
56
  }
57
57
  type ResponseFormat = ToolStrategy<any> | ProviderStrategy<any>;
58
58
  /**
59
- * Handle user input for `responseFormat` parameter of `CreateReactAgentParams`.
59
+ * Handle user input for `responseFormat` parameter of `CreateAgentParams`.
60
60
  * This function defines the default behavior for the `responseFormat` parameter, which is:
61
61
  *
62
62
  * - if value is a Zod schema, default to structured output via tool calling
@@ -75,6 +75,11 @@ interface TypedToolStrategy<T = unknown> extends Array<ToolStrategy<any>> {
75
75
  }
76
76
  type ToolStrategyError = StructuredOutputParsingError | MultipleStructuredOutputsError;
77
77
  interface ToolStrategyOptions {
78
+ /**
79
+ * Allows you to customize the message that appears in the conversation history when structured
80
+ * output is generated.
81
+ */
82
+ toolMessageContent?: string;
78
83
  /**
79
84
  * Handle errors from the structured output tool call. Using tools to generate structured output
80
85
  * can cause errors, e.g. if:
@@ -1 +1 @@
1
- {"version":3,"file":"responses.d.ts","names":["InteropZodObject","InteropZodType","AIMessage","FunctionDefinition","StructuredOutputParsingError","MultipleStructuredOutputsError","ToolStrategy","Record","ToolStrategyOptions","S","U","ProviderStrategy","T","ResponseFormat","transformResponseFormat","JsonSchemaFormat","ResponseFormatUndefined","TypedToolStrategy","Array","ToolStrategyError","Promise","toolStrategy","K","providerStrategy"],"sources":["../../src/agents/responses.d.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport { InteropZodObject, InteropZodType } from \"@langchain/core/utils/types\";\nimport { type AIMessage } from \"@langchain/core/messages\";\nimport { type FunctionDefinition } from \"@langchain/core/language_models/base\";\nimport { StructuredOutputParsingError, MultipleStructuredOutputsError } from \"./errors.js\";\n/**\n * Information for tracking structured output tool metadata.\n * This contains all necessary information to handle structured responses generated\n * via tool calls, including the original schema, its type classification, and the\n * corresponding tool implementation used by the tools strategy.\n */\nexport declare class ToolStrategy<_T = unknown> {\n readonly schema: Record<string, unknown>;\n readonly tool: {\n type: \"function\";\n function: FunctionDefinition;\n };\n readonly options?: ToolStrategyOptions | undefined;\n private constructor();\n get name(): string;\n static fromSchema<S extends InteropZodObject>(schema: S, options?: {\n name?: string;\n description?: string;\n strict?: boolean;\n }, outputOptions?: ToolStrategyOptions): ToolStrategy<S extends InteropZodType<infer U> ? U : unknown>;\n static fromSchema(schema: Record<string, unknown>, options?: {\n name?: string;\n description?: string;\n strict?: boolean;\n }, outputOptions?: ToolStrategyOptions): ToolStrategy<Record<string, unknown>>;\n /**\n * Parse tool arguments according to the schema.\n *\n * @throws {StructuredOutputParsingError} if the response is not valid\n * @param toolArgs - The arguments from the tool call\n * @returns The parsed response according to the schema type\n */\n parse(toolArgs: Record<string, unknown>): Record<string, unknown>;\n}\nexport declare class ProviderStrategy<T = unknown> {\n readonly schema: Record<string, unknown>;\n // @ts-expect-error - _schemaType is used only for type inference\n private _schemaType?;\n private constructor();\n static fromSchema<T>(schema: InteropZodType<T>): ProviderStrategy<T>;\n static fromSchema(schema: Record<string, unknown>): ProviderStrategy<Record<string, unknown>>;\n /**\n * Parse tool arguments according to the schema. If the response is not valid, return undefined.\n *\n * @param toolArgs - The arguments from the tool call\n * @returns The parsed response according to the schema type\n */\n parse(response: AIMessage): any;\n}\nexport type ResponseFormat = ToolStrategy<any> | ProviderStrategy<any>;\n/**\n * Handle user input for `responseFormat` parameter of `CreateReactAgentParams`.\n * This function defines the default behavior for the `responseFormat` parameter, which is:\n *\n * - if value is a Zod schema, default to structured output via tool calling\n * - if value is a JSON schema, default to structured output via tool calling\n * - if value is a custom response format, return it as is\n * - if value is an array, ensure all array elements are instance of `ToolStrategy`\n * @param responseFormat\n * @returns\n */\nexport declare function transformResponseFormat(responseFormat?: InteropZodType<any> | InteropZodType<any>[] | JsonSchemaFormat | JsonSchemaFormat[] | ResponseFormat | ToolStrategy<any>[] | ResponseFormatUndefined, options?: ToolStrategyOptions): ResponseFormat[];\n/**\n * Branded type for ToolStrategy arrays that preserves type information\n */\nexport interface TypedToolStrategy<T = unknown> extends Array<ToolStrategy<any>> {\n _schemaType?: T;\n}\nexport type ToolStrategyError = StructuredOutputParsingError | MultipleStructuredOutputsError;\nexport interface ToolStrategyOptions {\n /**\n * Handle errors from the structured output tool call. Using tools to generate structured output\n * can cause errors, e.g. if:\n * - you provide multiple structured output schemas and the model calls multiple structured output tools\n * - if the structured output generated by the tool call doesn't match provided schema\n *\n * This property allows to handle these errors in different ways:\n * - `true` - retry the tool call\n * - `false` - throw an error\n * - `string` - retry the tool call with the provided message\n * - `(error: ToolStrategyError) => Promise<string> | string` - retry with the provided message or throw the error\n */\n handleError?: boolean | string | ((error: ToolStrategyError) => Promise<string> | string);\n}\nexport declare function toolStrategy<T extends InteropZodType<any>>(responseFormat: T, options?: ToolStrategyOptions): TypedToolStrategy<T extends InteropZodType<infer U> ? U : never>;\nexport declare function toolStrategy<T extends readonly InteropZodType<any>[]>(responseFormat: T, options?: ToolStrategyOptions): TypedToolStrategy<{\n [K in keyof T]: T[K] extends InteropZodType<infer U> ? U : never;\n}[number]>;\nexport declare function toolStrategy(responseFormat: JsonSchemaFormat, options?: ToolStrategyOptions): TypedToolStrategy<Record<string, unknown>>;\nexport declare function toolStrategy(responseFormat: JsonSchemaFormat[], options?: ToolStrategyOptions): TypedToolStrategy<Record<string, unknown>>;\nexport declare function providerStrategy<T extends InteropZodType<any>>(responseFormat: T): ProviderStrategy<T extends InteropZodType<infer U> ? U : never>;\nexport declare function providerStrategy(responseFormat: JsonSchemaFormat): ProviderStrategy<Record<string, unknown>>;\n/**\n * Special type to indicate that no response format is provided.\n * When this type is used, the structuredResponse property should not be present in the result.\n */\nexport type ResponseFormatUndefined = {\n __responseFormatUndefined: true;\n};\n/**\n * Type representing a JSON Schema object format.\n * This is a strict type that excludes ToolStrategy and ProviderStrategy instances.\n */\nexport type JsonSchemaFormat = {\n type: \"null\" | \"boolean\" | \"object\" | \"array\" | \"number\" | \"string\" | \"integer\";\n properties?: Record<string, unknown>;\n required?: string[];\n additionalProperties?: boolean;\n [key: string]: unknown;\n} & {\n // Brand to ensure this is not a ToolStrategy or ProviderStrategy\n __brand?: never;\n};\n"],"mappings":";;;;;;;;AAWA;;;;;AASgCA,cATXM,YASWN,CAAAA,KAAAA,OAAAA,CAAAA,CAAAA;EAAgB,SAAUS,MAAAA,EARrCF,MAQqCE,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;EAAC,SAIpCD,IAAAA,EAAAA;IAAmCC,IAAAA,EAAAA,UAAAA;IAAUR,QAAAA,EATlDE,kBASkDF;EAAc,CAAA;EAAa,SAAlDK,OAAAA,CAAAA,EAPtBE,mBAOsBF,GAAAA,SAAAA;EAAY,QAC3BC,WAAAA,CAAAA;EAAM,IAIbC,IAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAmB,OAAgBD,UAAAA,CAAAA,UAT1BP,gBAS0BO,CAAAA,CAAAA,MAAAA,EATAE,CASAF,EAAAA,OAQN,CARMA,EAAAA;IAAbD,IAAAA,CAAAA,EAAAA,MAAAA;IAQzBC,WAAAA,CAAAA,EAAAA,MAAAA;IAA0BA,MAAAA,CAAAA,EAAAA,O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A,MAAxBU,CAAAA,CAAAA;AAAiB,iBADlGI,YAAAA,CACkG,cAAA,EADrEN,gBACqE,EAAA,OAAA,CAAA,EADzCP,mBACyC,CAAA,EADnBS,iBACmB,CADDV,MACC,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;AAClGgB,iBADAF,YAAAA,CACgB,cAAA,EADaN,gBACb,EAAA,EAAA,OAAA,CAAA,EAD2CP,mBAC3C,CAAA,EADiES,iBACjE,CADmFV,MACnF,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;AAAA,iBAAhBgB,gBAAgB,CAAA,UAAWtB,cAAX,CAAA,GAAA,CAAA,CAAA,CAAA,cAAA,EAAgDW,CAAhD,CAAA,EAAoDD,gBAApD,CAAqEC,CAArE,SAA+EX,cAA/E,CAAA,KAAA,EAAA,CAAA,GAAyGS,CAAzG,GAAA,KAAA,CAAA;AAAWT,iBAC3BsB,gBAAAA,CAD2BtB,cAAAA,EACMc,gBADNd,CAAAA,EACyBU,gBADzBV,CAC0CM,MAD1CN,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,CAAAA;;;;;AAAyCU,KAMhFK,uBAAAA,GANgFL;EAAgB,yBAAA,EAAA,IAAA;AAC5G,CAAA;;;;;AAA4F,KAYhFI,gBAAAA,GAZgF;EAKhFC,IAAAA,EAAAA,MAAAA,GAAAA,SAAAA,GAAuB,QAAA,GAAA,OAAA,GAAA,QAAA,GAAA,QAAA,GAAA,SAAA;EAOvBD,UAAAA,CAAAA,EAEKR,MAFW,CAAA,MAAA,EAAA,OAEXA,CAAAA"}
1
+ {"version":3,"file":"responses.d.ts","names":["InteropZodObject","InteropZodType","AIMessage","FunctionDefinition","StructuredOutputParsingError","MultipleStructuredOutputsError","ToolStrategy","Record","ToolStrategyOptions","S","U","ProviderStrategy","T","ResponseFormat","transformResponseFormat","JsonSchemaFormat","ResponseFormatUndefined","TypedToolStrategy","Array","ToolStrategyError","Promise","toolStrategy","K","providerStrategy"],"sources":["../../src/agents/responses.d.ts"],"sourcesContent":["/* eslint-disable no-instanceof/no-instanceof */\nimport { InteropZodObject, InteropZodType } from \"@langchain/core/utils/types\";\nimport { type AIMessage } from \"@langchain/core/messages\";\nimport { type FunctionDefinition } from \"@langchain/core/language_models/base\";\nimport { StructuredOutputParsingError, MultipleStructuredOutputsError } from \"./errors.js\";\n/**\n * Information for tracking structured output tool metadata.\n * This contains all necessary information to handle structured responses generated\n * via tool calls, including the original schema, its type classification, and the\n * corresponding tool implementation used by the tools strategy.\n */\nexport declare class ToolStrategy<_T = unknown> {\n readonly schema: Record<string, unknown>;\n readonly tool: {\n type: \"function\";\n function: FunctionDefinition;\n };\n readonly options?: ToolStrategyOptions | undefined;\n private constructor();\n get name(): string;\n static fromSchema<S extends InteropZodObject>(schema: S, options?: {\n name?: string;\n description?: string;\n strict?: boolean;\n }, outputOptions?: ToolStrategyOptions): ToolStrategy<S extends InteropZodType<infer U> ? U : unknown>;\n static fromSchema(schema: Record<string, unknown>, options?: {\n name?: string;\n description?: string;\n strict?: boolean;\n }, outputOptions?: ToolStrategyOptions): ToolStrategy<Record<string, unknown>>;\n /**\n * Parse tool arguments according to the schema.\n *\n * @throws {StructuredOutputParsingError} if the response is not valid\n * @param toolArgs - The arguments from the tool call\n * @returns The parsed response according to the schema type\n */\n parse(toolArgs: Record<string, unknown>): Record<string, unknown>;\n}\nexport declare class ProviderStrategy<T = unknown> {\n readonly schema: Record<string, unknown>;\n // @ts-expect-error - _schemaType is used only for type inference\n private _schemaType?;\n private constructor();\n static fromSchema<T>(schema: InteropZodType<T>): ProviderStrategy<T>;\n static fromSchema(schema: Record<string, unknown>): ProviderStrategy<Record<string, unknown>>;\n /**\n * Parse tool arguments according to the schema. If the response is not valid, return undefined.\n *\n * @param toolArgs - The arguments from the tool call\n * @returns The parsed response according to the schema type\n */\n parse(response: AIMessage): any;\n}\nexport type ResponseFormat = ToolStrategy<any> | ProviderStrategy<any>;\n/**\n * Handle user input for `responseFormat` parameter of `CreateAgentParams`.\n * This function defines the default behavior for the `responseFormat` parameter, which is:\n *\n * - if value is a Zod schema, default to structured output via tool calling\n * - if value is a JSON schema, default to structured output via tool calling\n * - if value is a custom response format, return it as is\n * - if value is an array, ensure all array elements are instance of `ToolStrategy`\n * @param responseFormat\n * @returns\n */\nexport declare function transformResponseFormat(responseFormat?: InteropZodType<any> | InteropZodType<any>[] | JsonSchemaFormat | JsonSchemaFormat[] | ResponseFormat | ToolStrategy<any>[] | ResponseFormatUndefined, options?: ToolStrategyOptions): ResponseFormat[];\n/**\n * Branded type for ToolStrategy arrays that preserves type information\n */\nexport interface TypedToolStrategy<T = unknown> extends Array<ToolStrategy<any>> {\n _schemaType?: T;\n}\nexport type ToolStrategyError = StructuredOutputParsingError | MultipleStructuredOutputsError;\nexport interface ToolStrategyOptions {\n /**\n * Allows you to customize the message that appears in the conversation history when structured\n * output is generated.\n */\n toolMessageContent?: string;\n /**\n * Handle errors from the structured output tool call. Using tools to generate structured output\n * can cause errors, e.g. if:\n * - you provide multiple structured output schemas and the model calls multiple structured output tools\n * - if the structured output generated by the tool call doesn't match provided schema\n *\n * This property allows to handle these errors in different ways:\n * - `true` - retry the tool call\n * - `false` - throw an error\n * - `string` - retry the tool call with the provided message\n * - `(error: ToolStrategyError) => Promise<string> | string` - retry with the provided message or throw the error\n */\n handleError?: boolean | string | ((error: ToolStrategyError) => Promise<string> | string);\n}\nexport declare function toolStrategy<T extends InteropZodType<any>>(responseFormat: T, options?: ToolStrategyOptions): TypedToolStrategy<T extends InteropZodType<infer U> ? U : never>;\nexport declare function toolStrategy<T extends readonly InteropZodType<any>[]>(responseFormat: T, options?: ToolStrategyOptions): TypedToolStrategy<{\n [K in keyof T]: T[K] extends InteropZodType<infer U> ? U : never;\n}[number]>;\nexport declare function toolStrategy(responseFormat: JsonSchemaFormat, options?: ToolStrategyOptions): TypedToolStrategy<Record<string, unknown>>;\nexport declare function toolStrategy(responseFormat: JsonSchemaFormat[], options?: ToolStrategyOptions): TypedToolStrategy<Record<string, unknown>>;\nexport declare function providerStrategy<T extends InteropZodType<any>>(responseFormat: T): ProviderStrategy<T extends InteropZodType<infer U> ? U : never>;\nexport declare function providerStrategy(responseFormat: JsonSchemaFormat): ProviderStrategy<Record<string, unknown>>;\n/**\n * Special type to indicate that no response format is provided.\n * When this type is used, the structuredResponse property should not be present in the result.\n */\nexport type ResponseFormatUndefined = {\n __responseFormatUndefined: true;\n};\n/**\n * Type representing a JSON Schema object format.\n * This is a strict type that excludes ToolStrategy and ProviderStrategy instances.\n */\nexport type JsonSchemaFormat = {\n type: \"null\" | \"boolean\" | \"object\" | \"array\" | \"number\" | \"string\" | \"integer\";\n properties?: Record<string, unknown>;\n required?: string[];\n additionalProperties?: boolean;\n [key: string]: unknown;\n} & {\n // Brand to ensure this is not a ToolStrategy or ProviderStrategy\n __brand?: never;\n};\n"],"mappings":";;;;;;;;AAWA;;;;;AASgCA,cATXM,YASWN,CAAAA,KAAAA,OAAAA,CAAAA,CAAAA;EAAgB,SAAUS,MAAAA,EARrCF,MAQqCE,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;EAAC,SAIpCD,IAAAA,EAAAA;IAAmCC,IAAAA,EAAAA,UAAAA;IAAUR,QAAAA,EATlDE,kBASkDF;EAAc,CAAA;EAAa,SAAlDK,OAAAA,CAAAA,EAPtBE,mBAOsBF,GAAAA,SAAAA;EAAY,QAC3BC,WAAAA,CAAAA;EAAM,IAIbC,IAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAmB,OAAgBD,UAAAA,CAAAA,UAT1BP,gBAS0BO,CAAAA,CAAAA,MAAAA,EATAE,CASAF,EAAAA,OAQN,CARMA,EAAAA;IAAbD,IAAAA,CAAAA,EAAAA,MAAAA;IAQzBC,WAAAA,CAAAA,EAAAA,MAAAA;IAA0BA,MAAAA,CAAAA,EAAAA,OAAAA;EAAM,CAAA,EAAA,aAAA,CAAA,EAb7BC,mBAa6B,CAAA,EAbPF,YAaO,CAbMG,CAaN,SAbgBR,cAahB,CAAA,KA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AAAA,EAF5BJ,mBAE4BI,CAAAA,EAFNK,iBAEML,CAFYL,MAEZK,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,CAAAA;AAAUX,iBAD/FoB,YAAAA,CAC+FpB,cAAAA,EADlEc,gBACkEd,EAAAA,EAAAA,OAAAA,CAAAA,EADpCO,mBACoCP,CAAAA,EADdgB,iBACchB,CADIM,MACJN,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,CAAAA;AAA0BS,iBAAzHa,gBAAyHb,CAAAA,UAA9FT,cAA8FS,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,cAAAA,EAAzDE,CAAyDF,CAAAA,EAArDC,gBAAqDD,CAApCE,CAAoCF,SAA1BT,cAA0BS,CAAAA,KAAAA,EAAAA,CAAAA,GAAAA,CAAAA,GAAAA,KAAAA,CAAAA;AAArDC,iBACpEY,gBAAAA,CADoEZ,cAAAA,EACnCI,gBADmCJ,CAAAA,EAChBA,gBADgBA,CACCJ,MADDI,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,CAAAA;AAAgB;AAC5G;;;AAA6FJ,KAKjFS,uBAAAA,GALiFT;EAAM,yBAAvBI,EAAAA,IAAAA;AAAgB,CAAA;AAK5F;AAOA;;;KAAYI,gBAAAA;;eAEKR"}
@@ -48,12 +48,11 @@ var ToolStrategy = class ToolStrategy {
48
48
  else functionDefinition = {
49
49
  name: getFunctionName(schema.title),
50
50
  description: schema.description ?? "",
51
- parameters: schema
51
+ parameters: schema.schema || schema
52
52
  };
53
53
  const asJsonSchema = toJsonSchema(schema);
54
54
  const tool = {
55
55
  type: "function",
56
- name: getFunctionName(),
57
56
  function: functionDefinition
58
57
  };
59
58
  return new ToolStrategy(asJsonSchema, tool, outputOptions);
@@ -102,7 +101,7 @@ var ProviderStrategy = class ProviderStrategy {
102
101
  }
103
102
  };
104
103
  /**
105
- * Handle user input for `responseFormat` parameter of `CreateReactAgentParams`.
104
+ * Handle user input for `responseFormat` parameter of `CreateAgentParams`.
106
105
  * This function defines the default behavior for the `responseFormat` parameter, which is:
107
106
  *
108
107
  * - if value is a Zod schema, default to structured output via tool calling