@librechat/agents 3.3.5 → 3.3.6

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 (127) hide show
  1. package/dist/cjs/hooks/createWorkspacePolicyHook.cjs +1 -1
  2. package/dist/cjs/llm/openai/index.cjs +51 -6
  3. package/dist/cjs/llm/openai/index.cjs.map +1 -1
  4. package/dist/cjs/main.cjs +14 -0
  5. package/dist/cjs/session/JsonlSessionStore.cjs +1 -1
  6. package/dist/cjs/stream.cjs +6 -1
  7. package/dist/cjs/stream.cjs.map +1 -1
  8. package/dist/cjs/tools/BashExecutor.cjs +3 -1
  9. package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
  10. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +2 -0
  11. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
  12. package/dist/cjs/tools/CodeExecutor.cjs +19 -16
  13. package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
  14. package/dist/cjs/tools/ProgrammaticToolCalling.cjs +2 -0
  15. package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
  16. package/dist/cjs/tools/ReadFile.cjs +8 -4
  17. package/dist/cjs/tools/ReadFile.cjs.map +1 -1
  18. package/dist/cjs/tools/SkillTool.cjs +2 -0
  19. package/dist/cjs/tools/SkillTool.cjs.map +1 -1
  20. package/dist/cjs/tools/SubagentTool.cjs +3 -0
  21. package/dist/cjs/tools/SubagentTool.cjs.map +1 -1
  22. package/dist/cjs/tools/ToolNode.cjs +88 -27
  23. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  24. package/dist/cjs/tools/ToolSearch.cjs +5 -1
  25. package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
  26. package/dist/cjs/tools/intentArg.cjs +230 -0
  27. package/dist/cjs/tools/intentArg.cjs.map +1 -0
  28. package/dist/cjs/tools/local/CompileCheckTool.cjs +3 -2
  29. package/dist/cjs/tools/local/CompileCheckTool.cjs.map +1 -1
  30. package/dist/cjs/tools/local/LocalCodingTools.cjs +13 -12
  31. package/dist/cjs/tools/local/LocalCodingTools.cjs.map +1 -1
  32. package/dist/cjs/tools/local/LocalExecutionEngine.cjs +2 -2
  33. package/dist/cjs/tools/ptcTimeout.cjs.map +1 -1
  34. package/dist/cjs/tools/search/schema.cjs +2 -0
  35. package/dist/cjs/tools/search/schema.cjs.map +1 -1
  36. package/dist/cjs/tools/search/tool.cjs +31 -1
  37. package/dist/cjs/tools/search/tool.cjs.map +1 -1
  38. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +1 -0
  39. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
  40. package/dist/cjs/tools/toolOutputReferences.cjs +41 -7
  41. package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -1
  42. package/dist/esm/hooks/createWorkspacePolicyHook.mjs +1 -1
  43. package/dist/esm/llm/openai/index.mjs +51 -6
  44. package/dist/esm/llm/openai/index.mjs.map +1 -1
  45. package/dist/esm/main.mjs +4 -3
  46. package/dist/esm/session/JsonlSessionStore.mjs +1 -1
  47. package/dist/esm/stream.mjs +6 -1
  48. package/dist/esm/stream.mjs.map +1 -1
  49. package/dist/esm/tools/BashExecutor.mjs +3 -1
  50. package/dist/esm/tools/BashExecutor.mjs.map +1 -1
  51. package/dist/esm/tools/BashProgrammaticToolCalling.mjs +2 -0
  52. package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
  53. package/dist/esm/tools/CodeExecutor.mjs +19 -16
  54. package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
  55. package/dist/esm/tools/ProgrammaticToolCalling.mjs +2 -0
  56. package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
  57. package/dist/esm/tools/ReadFile.mjs +8 -4
  58. package/dist/esm/tools/ReadFile.mjs.map +1 -1
  59. package/dist/esm/tools/SkillTool.mjs +2 -0
  60. package/dist/esm/tools/SkillTool.mjs.map +1 -1
  61. package/dist/esm/tools/SubagentTool.mjs +3 -0
  62. package/dist/esm/tools/SubagentTool.mjs.map +1 -1
  63. package/dist/esm/tools/ToolNode.mjs +88 -28
  64. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  65. package/dist/esm/tools/ToolSearch.mjs +5 -1
  66. package/dist/esm/tools/ToolSearch.mjs.map +1 -1
  67. package/dist/esm/tools/intentArg.mjs +220 -0
  68. package/dist/esm/tools/intentArg.mjs.map +1 -0
  69. package/dist/esm/tools/local/CompileCheckTool.mjs +3 -2
  70. package/dist/esm/tools/local/CompileCheckTool.mjs.map +1 -1
  71. package/dist/esm/tools/local/LocalCodingTools.mjs +13 -12
  72. package/dist/esm/tools/local/LocalCodingTools.mjs.map +1 -1
  73. package/dist/esm/tools/local/LocalExecutionEngine.mjs +2 -2
  74. package/dist/esm/tools/ptcTimeout.mjs.map +1 -1
  75. package/dist/esm/tools/search/schema.mjs +2 -0
  76. package/dist/esm/tools/search/schema.mjs.map +1 -1
  77. package/dist/esm/tools/search/tool.mjs +31 -2
  78. package/dist/esm/tools/search/tool.mjs.map +1 -1
  79. package/dist/esm/tools/subagent/SubagentExecutor.mjs +1 -0
  80. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
  81. package/dist/esm/tools/toolOutputReferences.mjs +41 -7
  82. package/dist/esm/tools/toolOutputReferences.mjs.map +1 -1
  83. package/dist/types/index.d.ts +1 -0
  84. package/dist/types/llm/openai/index.d.ts +0 -11
  85. package/dist/types/tools/BashExecutor.d.ts +18 -0
  86. package/dist/types/tools/CodeExecutor.d.ts +18 -0
  87. package/dist/types/tools/ReadFile.d.ts +18 -0
  88. package/dist/types/tools/SkillTool.d.ts +18 -0
  89. package/dist/types/tools/SubagentTool.d.ts +9 -0
  90. package/dist/types/tools/ToolNode.d.ts +37 -5
  91. package/dist/types/tools/ToolSearch.d.ts +18 -0
  92. package/dist/types/tools/intentArg.d.ts +119 -0
  93. package/dist/types/tools/ptcTimeout.d.ts +2 -0
  94. package/dist/types/tools/search/schema.d.ts +18 -0
  95. package/dist/types/tools/search/tool.d.ts +18 -0
  96. package/dist/types/tools/toolOutputReferences.d.ts +12 -2
  97. package/dist/types/types/stream.d.ts +12 -0
  98. package/dist/types/types/tools.d.ts +27 -2
  99. package/package.json +1 -1
  100. package/src/index.ts +1 -0
  101. package/src/llm/openai/index.ts +74 -10
  102. package/src/llm/openai/llm.spec.ts +105 -0
  103. package/src/stream.ts +12 -1
  104. package/src/tools/BashExecutor.ts +6 -0
  105. package/src/tools/BashProgrammaticToolCalling.ts +2 -0
  106. package/src/tools/CodeExecutor.ts +6 -0
  107. package/src/tools/ProgrammaticToolCalling.ts +2 -0
  108. package/src/tools/ReadFile.ts +2 -0
  109. package/src/tools/SkillTool.ts +2 -0
  110. package/src/tools/SubagentTool.ts +3 -0
  111. package/src/tools/ToolNode.ts +190 -43
  112. package/src/tools/ToolSearch.ts +3 -0
  113. package/src/tools/__tests__/ToolNode.onResultCompletion.test.ts +174 -0
  114. package/src/tools/__tests__/intentArg.test.ts +281 -0
  115. package/src/tools/__tests__/intentCoverage.test.ts +139 -0
  116. package/src/tools/__tests__/toolOutputReferences.test.ts +83 -0
  117. package/src/tools/intentArg.ts +323 -0
  118. package/src/tools/local/CompileCheckTool.ts +4 -3
  119. package/src/tools/local/LocalCodingTools.ts +14 -13
  120. package/src/tools/ptcTimeout.ts +2 -0
  121. package/src/tools/search/outcome.test.ts +90 -0
  122. package/src/tools/search/schema.ts +3 -0
  123. package/src/tools/search/tool.ts +47 -1
  124. package/src/tools/subagent/SubagentExecutor.ts +2 -1
  125. package/src/tools/toolOutputReferences.ts +77 -9
  126. package/src/types/stream.ts +12 -0
  127. package/src/types/tools.ts +24 -2
@@ -1,5 +1,6 @@
1
1
  import "../common/enum.mjs";
2
2
  import "../common/index.mjs";
3
+ import { INTENT_PROPERTY } from "./intentArg.mjs";
3
4
  //#region src/tools/ReadFile.ts
4
5
  const ReadFileToolName = "read_file";
5
6
  const ReadFileToolDescription = `Read the contents of a file. Returns text content with line numbers for easy reference.
@@ -19,10 +20,13 @@ CONSTRAINTS:
19
20
  - Do not guess file paths. Use paths from the skill documentation or tool output.`;
20
21
  const ReadFileToolSchema = {
21
22
  type: "object",
22
- properties: { path: {
23
- type: "string",
24
- description: "Path to the file. For skill files: \"{skillName}/{path}\" (e.g. \"pdf-analyzer/src/utils.py\"). For code execution output: the path as returned by the execution tool."
25
- } },
23
+ properties: {
24
+ intent: { ...INTENT_PROPERTY },
25
+ path: {
26
+ type: "string",
27
+ description: "Path to the file. For skill files: \"{skillName}/{path}\" (e.g. \"pdf-analyzer/src/utils.py\"). For code execution output: the path as returned by the execution tool."
28
+ }
29
+ },
26
30
  required: ["path"]
27
31
  };
28
32
  const ReadFileToolDefinition = {
@@ -1 +1 @@
1
- {"version":3,"file":"ReadFile.mjs","names":[],"sources":["../../../src/tools/ReadFile.ts"],"sourcesContent":["// src/tools/ReadFile.ts\nimport { Constants } from '@/common';\n\nexport const ReadFileToolName = Constants.READ_FILE;\n\nexport const ReadFileToolDescription = `Read the contents of a file. Returns text content with line numbers for easy reference.\n\nFor skill files, use the path format: {skillName}/{filePath} (e.g. \"pdf-analyzer/src/utils.py\", \"code-review/SKILL.md\").\n\nBEHAVIOR:\n- Text files: returned with numbered lines.\n- Images (png, jpeg, gif, webp): returned as visual content the model can see.\n- PDFs: returned as document content.\n- Other binary files: metadata returned with a note to use bash for processing.\n- Large files (>256KB text, >10MB binary): metadata only.\n- SKILL.md: returns the skill's instructions directly.\n\nCONSTRAINTS:\n- Only files from invoked skills or code execution output are accessible.\n- Do not guess file paths. Use paths from the skill documentation or tool output.`;\n\nexport const ReadFileToolSchema = {\n type: 'object',\n properties: {\n path: {\n type: 'string',\n description:\n 'Path to the file. For skill files: \"{skillName}/{path}\" (e.g. \"pdf-analyzer/src/utils.py\"). For code execution output: the path as returned by the execution tool.',\n },\n },\n required: ['path'],\n} as const;\n\nexport const ReadFileToolDefinition = {\n name: ReadFileToolName,\n description: ReadFileToolDescription,\n parameters: ReadFileToolSchema,\n responseFormat: 'content_and_artifact' as const,\n} as const;\n"],"mappings":";;;AAGA,MAAa,mBAAA;AAEb,MAAa,0BAA0B;;;;;;;;;;;;;;;AAgBvC,MAAa,qBAAqB;CAChC,MAAM;CACN,YAAY,EACV,MAAM;EACJ,MAAM;EACN,aACE;CACJ,EACF;CACA,UAAU,CAAC,MAAM;AACnB;AAEA,MAAa,yBAAyB;CACpC,MAAM;CACN,aAAa;CACb,YAAY;CACZ,gBAAgB;AAClB"}
1
+ {"version":3,"file":"ReadFile.mjs","names":[],"sources":["../../../src/tools/ReadFile.ts"],"sourcesContent":["// src/tools/ReadFile.ts\nimport { INTENT_PROPERTY } from '@/tools/intentArg';\nimport { Constants } from '@/common';\n\nexport const ReadFileToolName = Constants.READ_FILE;\n\nexport const ReadFileToolDescription = `Read the contents of a file. Returns text content with line numbers for easy reference.\n\nFor skill files, use the path format: {skillName}/{filePath} (e.g. \"pdf-analyzer/src/utils.py\", \"code-review/SKILL.md\").\n\nBEHAVIOR:\n- Text files: returned with numbered lines.\n- Images (png, jpeg, gif, webp): returned as visual content the model can see.\n- PDFs: returned as document content.\n- Other binary files: metadata returned with a note to use bash for processing.\n- Large files (>256KB text, >10MB binary): metadata only.\n- SKILL.md: returns the skill's instructions directly.\n\nCONSTRAINTS:\n- Only files from invoked skills or code execution output are accessible.\n- Do not guess file paths. Use paths from the skill documentation or tool output.`;\n\nexport const ReadFileToolSchema = {\n type: 'object',\n properties: {\n intent: { ...INTENT_PROPERTY },\n path: {\n type: 'string',\n description:\n 'Path to the file. For skill files: \"{skillName}/{path}\" (e.g. \"pdf-analyzer/src/utils.py\"). For code execution output: the path as returned by the execution tool.',\n },\n },\n required: ['path'],\n} as const;\n\nexport const ReadFileToolDefinition = {\n name: ReadFileToolName,\n description: ReadFileToolDescription,\n parameters: ReadFileToolSchema,\n responseFormat: 'content_and_artifact' as const,\n} as const;\n"],"mappings":";;;;AAIA,MAAa,mBAAA;AAEb,MAAa,0BAA0B;;;;;;;;;;;;;;;AAgBvC,MAAa,qBAAqB;CAChC,MAAM;CACN,YAAY;EACV,QAAQ,EAAE,GAAG,gBAAgB;EAC7B,MAAM;GACJ,MAAM;GACN,aACE;EACJ;CACF;CACA,UAAU,CAAC,MAAM;AACnB;AAEA,MAAa,yBAAyB;CACpC,MAAM;CACN,aAAa;CACb,YAAY;CACZ,gBAAgB;AAClB"}
@@ -1,5 +1,6 @@
1
1
  import "../common/enum.mjs";
2
2
  import "../common/index.mjs";
3
+ import { INTENT_PROPERTY } from "./intentArg.mjs";
3
4
  //#region src/tools/SkillTool.ts
4
5
  const SkillToolName = "skill";
5
6
  const SkillToolDescription = `Invoke a skill from the user's library. Skills provide domain-specific instructions loaded into the conversation context, and may also provide files accessible via available tools depending on the runtime environment.
@@ -24,6 +25,7 @@ CONSTRAINTS:
24
25
  const SkillToolSchema = {
25
26
  type: "object",
26
27
  properties: {
28
+ intent: { ...INTENT_PROPERTY },
27
29
  skillName: {
28
30
  type: "string",
29
31
  description: "The kebab-case identifier of the skill to invoke (e.g. \"financial-analyzer\", \"meeting-notes\"). Must match a name from the \"Available Skills\" section."
@@ -1 +1 @@
1
- {"version":3,"file":"SkillTool.mjs","names":[],"sources":["../../../src/tools/SkillTool.ts"],"sourcesContent":["// src/tools/SkillTool.ts\nimport { Constants } from '@/common';\n\nexport const SkillToolName = Constants.SKILL_TOOL;\n\nexport const SkillToolDescription = `Invoke a skill from the user's library. Skills provide domain-specific instructions loaded into the conversation context, and may also provide files accessible via available tools depending on the runtime environment.\n\nWHEN TO USE:\n- The user's request matches a skill listed in the \"Available Skills\" section of the system prompt.\n- You MUST invoke the matching skill BEFORE attempting the task yourself.\n\nWHAT HAPPENS:\n- The skill's full instructions are loaded into the conversation as context.\n- Files bundled with the skill may become accessible via available tools.\n- Follow the skill's instructions to complete the task.\n\nCONSTRAINTS:\n- Do not invoke a skill that is already active in this conversation.\n- Skill names come from the catalog only. Do not guess names.`;\n\n/**\n * JSON Schema for the SkillTool parameters.\n * Single source of truth used by both SkillToolDefinition (LCTool registry)\n * and createSkillTool() (DynamicStructuredTool instance).\n */\nexport const SkillToolSchema = {\n type: 'object',\n properties: {\n skillName: {\n type: 'string',\n description:\n 'The kebab-case identifier of the skill to invoke (e.g. \"financial-analyzer\", \"meeting-notes\"). Must match a name from the \"Available Skills\" section.',\n },\n args: {\n type: 'string',\n description: 'Optional freeform arguments string passed to the skill.',\n },\n },\n required: ['skillName'],\n} as const;\n\nexport const SkillToolDefinition = {\n name: SkillToolName,\n description: SkillToolDescription,\n parameters: SkillToolSchema,\n} as const;\n"],"mappings":";;;AAGA,MAAa,gBAAA;AAEb,MAAa,uBAAuB;;;;;;;;;;;;;;;;;;;AAoBpC,MAAa,kBAAkB;CAC7B,MAAM;CACN,YAAY;EACV,WAAW;GACT,MAAM;GACN,aACE;EACJ;EACA,MAAM;GACJ,MAAM;GACN,aAAa;EACf;CACF;CACA,UAAU,CAAC,WAAW;AACxB;AAEA,MAAa,sBAAsB;CACjC,MAAM;CACN,aAAa;CACb,YAAY;AACd"}
1
+ {"version":3,"file":"SkillTool.mjs","names":[],"sources":["../../../src/tools/SkillTool.ts"],"sourcesContent":["// src/tools/SkillTool.ts\nimport { INTENT_PROPERTY } from '@/tools/intentArg';\nimport { Constants } from '@/common';\n\nexport const SkillToolName = Constants.SKILL_TOOL;\n\nexport const SkillToolDescription = `Invoke a skill from the user's library. Skills provide domain-specific instructions loaded into the conversation context, and may also provide files accessible via available tools depending on the runtime environment.\n\nWHEN TO USE:\n- The user's request matches a skill listed in the \"Available Skills\" section of the system prompt.\n- You MUST invoke the matching skill BEFORE attempting the task yourself.\n\nWHAT HAPPENS:\n- The skill's full instructions are loaded into the conversation as context.\n- Files bundled with the skill may become accessible via available tools.\n- Follow the skill's instructions to complete the task.\n\nCONSTRAINTS:\n- Do not invoke a skill that is already active in this conversation.\n- Skill names come from the catalog only. Do not guess names.`;\n\n/**\n * JSON Schema for the SkillTool parameters.\n * Single source of truth used by both SkillToolDefinition (LCTool registry)\n * and createSkillTool() (DynamicStructuredTool instance).\n */\nexport const SkillToolSchema = {\n type: 'object',\n properties: {\n intent: { ...INTENT_PROPERTY },\n skillName: {\n type: 'string',\n description:\n 'The kebab-case identifier of the skill to invoke (e.g. \"financial-analyzer\", \"meeting-notes\"). Must match a name from the \"Available Skills\" section.',\n },\n args: {\n type: 'string',\n description: 'Optional freeform arguments string passed to the skill.',\n },\n },\n required: ['skillName'],\n} as const;\n\nexport const SkillToolDefinition = {\n name: SkillToolName,\n description: SkillToolDescription,\n parameters: SkillToolSchema,\n} as const;\n"],"mappings":";;;;AAIA,MAAa,gBAAA;AAEb,MAAa,uBAAuB;;;;;;;;;;;;;;;;;;;AAoBpC,MAAa,kBAAkB;CAC7B,MAAM;CACN,YAAY;EACV,QAAQ,EAAE,GAAG,gBAAgB;EAC7B,WAAW;GACT,MAAM;GACN,aACE;EACJ;EACA,MAAM;GACJ,MAAM;GACN,aAAa;EACf;CACF;CACA,UAAU,CAAC,WAAW;AACxB;AAEA,MAAa,sBAAsB;CACjC,MAAM;CACN,aAAa;CACb,YAAY;AACd"}
@@ -1,5 +1,6 @@
1
1
  import "../common/enum.mjs";
2
2
  import "../common/index.mjs";
3
+ import { INTENT_PROPERTY } from "./intentArg.mjs";
3
4
  //#region src/tools/SubagentTool.ts
4
5
  const SubagentToolName = "subagent";
5
6
  const SubagentToolDescription = `Delegate a task to a specialized subagent that runs in an isolated context window. The subagent executes independently and returns only its final text result — all intermediate tool calls, reasoning, and context stay isolated.
@@ -22,6 +23,7 @@ const SUBAGENT_TYPE_PROP_DESCRIPTION = "Which subagent type to delegate to. Must
22
23
  const SubagentToolSchema = {
23
24
  type: "object",
24
25
  properties: {
26
+ intent: { ...INTENT_PROPERTY },
25
27
  description: {
26
28
  type: "string",
27
29
  description: DESCRIPTION_PROP_DESCRIPTION
@@ -51,6 +53,7 @@ function buildSubagentToolParams(configs) {
51
53
  schema: {
52
54
  type: "object",
53
55
  properties: {
56
+ intent: { ...INTENT_PROPERTY },
54
57
  description: {
55
58
  type: "string",
56
59
  description: DESCRIPTION_PROP_DESCRIPTION
@@ -1 +1 @@
1
- {"version":3,"file":"SubagentTool.mjs","names":[],"sources":["../../../src/tools/SubagentTool.ts"],"sourcesContent":["import type { JsonSchemaType, LCTool } from '@/types/tools';\nimport type { SubagentConfig } from '@/types';\nimport { Constants } from '@/common';\n\nexport const SubagentToolName = Constants.SUBAGENT;\n\nexport const SubagentToolDescription = `Delegate a task to a specialized subagent that runs in an isolated context window. The subagent executes independently and returns only its final text result — all intermediate tool calls, reasoning, and context stay isolated.\n\nWHEN TO USE:\n- The task is self-contained and can be described in a single prompt.\n- You want to offload verbose or exploratory work without bloating your own context.\n- A specialized subagent is available for the task domain.\n\nWHAT HAPPENS:\n- A fresh agent is created with the task description as its only input.\n- The subagent runs to completion using its own tools and context.\n- Only the final text response is returned to you.\n\nCONSTRAINTS:\n- subagent_type must match one of the available types listed below.\n- The subagent cannot see your conversation history.`;\n\nconst DESCRIPTION_PROP_DESCRIPTION =\n 'Complete task description for the subagent. This is the ONLY information it receives — include all necessary context, requirements, and constraints.';\n\nconst SUBAGENT_TYPE_PROP_DESCRIPTION =\n 'Which subagent type to delegate to. Must be one of the available types.';\n\nexport const SubagentToolSchema = {\n type: 'object',\n properties: {\n description: {\n type: 'string',\n description: DESCRIPTION_PROP_DESCRIPTION,\n },\n subagent_type: {\n type: 'string',\n description: SUBAGENT_TYPE_PROP_DESCRIPTION,\n },\n },\n required: ['description', 'subagent_type'] as string[],\n} as const;\n\nexport const SubagentToolDefinition: LCTool = {\n name: SubagentToolName,\n description: SubagentToolDescription,\n parameters: SubagentToolSchema,\n};\n\n/**\n * Build the name, schema, and description params for `tool()` from available configs.\n * Used by `Graph.createAgentNode()` when constructing the runtime tool instance.\n * Extends `SubagentToolSchema` by populating `subagent_type.enum` dynamically.\n */\nexport function buildSubagentToolParams(configs: SubagentConfig[]): {\n name: string;\n schema: JsonSchemaType;\n description: string;\n} {\n const types = configs.map((c) => c.type);\n const typeDescriptions = configs\n .map((c) => `- \"${c.type}\" (${c.name}): ${c.description}`)\n .join('\\n');\n\n return {\n name: SubagentToolName,\n schema: {\n type: 'object',\n properties: {\n description: {\n type: 'string',\n description: DESCRIPTION_PROP_DESCRIPTION,\n },\n subagent_type: {\n type: 'string',\n enum: types,\n description: `${SUBAGENT_TYPE_PROP_DESCRIPTION} Available: ${types.join(', ')}.`,\n },\n },\n required: ['description', 'subagent_type'],\n },\n description: `${SubagentToolDescription}\\n\\nAvailable types:\\n${typeDescriptions}`,\n };\n}\n\n/**\n * Create a SubagentTool LCTool definition with dynamic enum and description\n * populated from the available subagent configs.\n * Used for the tool registry in event-driven mode.\n */\nexport function createSubagentToolDefinition(\n configs: SubagentConfig[]\n): LCTool {\n const params = buildSubagentToolParams(configs);\n return {\n name: params.name,\n description: params.description,\n parameters: params.schema,\n };\n}\n"],"mappings":";;;AAIA,MAAa,mBAAA;AAEb,MAAa,0BAA0B;;;;;;;;;;;;;;;AAgBvC,MAAM,+BACJ;AAEF,MAAM,iCACJ;AAEF,MAAa,qBAAqB;CAChC,MAAM;CACN,YAAY;EACV,aAAa;GACX,MAAM;GACN,aAAa;EACf;EACA,eAAe;GACb,MAAM;GACN,aAAa;EACf;CACF;CACA,UAAU,CAAC,eAAe,eAAe;AAC3C;AAEA,MAAa,yBAAiC;CAC5C,MAAM;CACN,aAAa;CACb,YAAY;AACd;;;;;;AAOA,SAAgB,wBAAwB,SAItC;CACA,MAAM,QAAQ,QAAQ,KAAK,MAAM,EAAE,IAAI;CACvC,MAAM,mBAAmB,QACtB,KAAK,MAAM,MAAM,EAAE,KAAK,KAAK,EAAE,KAAK,KAAK,EAAE,aAAa,CAAC,CACzD,KAAK,IAAI;CAEZ,OAAO;EACL,MAAM;EACN,QAAQ;GACN,MAAM;GACN,YAAY;IACV,aAAa;KACX,MAAM;KACN,aAAa;IACf;IACA,eAAe;KACb,MAAM;KACN,MAAM;KACN,aAAa,GAAG,+BAA+B,cAAc,MAAM,KAAK,IAAI,EAAE;IAChF;GACF;GACA,UAAU,CAAC,eAAe,eAAe;EAC3C;EACA,aAAa,GAAG,wBAAwB,wBAAwB;CAClE;AACF;;;;;;AAOA,SAAgB,6BACd,SACQ;CACR,MAAM,SAAS,wBAAwB,OAAO;CAC9C,OAAO;EACL,MAAM,OAAO;EACb,aAAa,OAAO;EACpB,YAAY,OAAO;CACrB;AACF"}
1
+ {"version":3,"file":"SubagentTool.mjs","names":[],"sources":["../../../src/tools/SubagentTool.ts"],"sourcesContent":["import type { JsonSchemaType, LCTool } from '@/types/tools';\nimport type { SubagentConfig } from '@/types';\nimport { INTENT_PROPERTY } from '@/tools/intentArg';\nimport { Constants } from '@/common';\n\nexport const SubagentToolName = Constants.SUBAGENT;\n\nexport const SubagentToolDescription = `Delegate a task to a specialized subagent that runs in an isolated context window. The subagent executes independently and returns only its final text result — all intermediate tool calls, reasoning, and context stay isolated.\n\nWHEN TO USE:\n- The task is self-contained and can be described in a single prompt.\n- You want to offload verbose or exploratory work without bloating your own context.\n- A specialized subagent is available for the task domain.\n\nWHAT HAPPENS:\n- A fresh agent is created with the task description as its only input.\n- The subagent runs to completion using its own tools and context.\n- Only the final text response is returned to you.\n\nCONSTRAINTS:\n- subagent_type must match one of the available types listed below.\n- The subagent cannot see your conversation history.`;\n\nconst DESCRIPTION_PROP_DESCRIPTION =\n 'Complete task description for the subagent. This is the ONLY information it receives — include all necessary context, requirements, and constraints.';\n\nconst SUBAGENT_TYPE_PROP_DESCRIPTION =\n 'Which subagent type to delegate to. Must be one of the available types.';\n\nexport const SubagentToolSchema = {\n type: 'object',\n properties: {\n intent: { ...INTENT_PROPERTY },\n description: {\n type: 'string',\n description: DESCRIPTION_PROP_DESCRIPTION,\n },\n subagent_type: {\n type: 'string',\n description: SUBAGENT_TYPE_PROP_DESCRIPTION,\n },\n },\n required: ['description', 'subagent_type'] as string[],\n} as const;\n\nexport const SubagentToolDefinition: LCTool = {\n name: SubagentToolName,\n description: SubagentToolDescription,\n parameters: SubagentToolSchema,\n};\n\n/**\n * Build the name, schema, and description params for `tool()` from available configs.\n * Used by `Graph.createAgentNode()` when constructing the runtime tool instance.\n * Extends `SubagentToolSchema` by populating `subagent_type.enum` dynamically.\n */\nexport function buildSubagentToolParams(configs: SubagentConfig[]): {\n name: string;\n schema: JsonSchemaType;\n description: string;\n} {\n const types = configs.map((c) => c.type);\n const typeDescriptions = configs\n .map((c) => `- \"${c.type}\" (${c.name}): ${c.description}`)\n .join('\\n');\n\n return {\n name: SubagentToolName,\n schema: {\n type: 'object',\n properties: {\n intent: { ...INTENT_PROPERTY },\n description: {\n type: 'string',\n description: DESCRIPTION_PROP_DESCRIPTION,\n },\n subagent_type: {\n type: 'string',\n enum: types,\n description: `${SUBAGENT_TYPE_PROP_DESCRIPTION} Available: ${types.join(', ')}.`,\n },\n },\n required: ['description', 'subagent_type'],\n },\n description: `${SubagentToolDescription}\\n\\nAvailable types:\\n${typeDescriptions}`,\n };\n}\n\n/**\n * Create a SubagentTool LCTool definition with dynamic enum and description\n * populated from the available subagent configs.\n * Used for the tool registry in event-driven mode.\n */\nexport function createSubagentToolDefinition(\n configs: SubagentConfig[]\n): LCTool {\n const params = buildSubagentToolParams(configs);\n return {\n name: params.name,\n description: params.description,\n parameters: params.schema,\n };\n}\n"],"mappings":";;;;AAKA,MAAa,mBAAA;AAEb,MAAa,0BAA0B;;;;;;;;;;;;;;;AAgBvC,MAAM,+BACJ;AAEF,MAAM,iCACJ;AAEF,MAAa,qBAAqB;CAChC,MAAM;CACN,YAAY;EACV,QAAQ,EAAE,GAAG,gBAAgB;EAC7B,aAAa;GACX,MAAM;GACN,aAAa;EACf;EACA,eAAe;GACb,MAAM;GACN,aAAa;EACf;CACF;CACA,UAAU,CAAC,eAAe,eAAe;AAC3C;AAEA,MAAa,yBAAiC;CAC5C,MAAM;CACN,aAAa;CACb,YAAY;AACd;;;;;;AAOA,SAAgB,wBAAwB,SAItC;CACA,MAAM,QAAQ,QAAQ,KAAK,MAAM,EAAE,IAAI;CACvC,MAAM,mBAAmB,QACtB,KAAK,MAAM,MAAM,EAAE,KAAK,KAAK,EAAE,KAAK,KAAK,EAAE,aAAa,CAAC,CACzD,KAAK,IAAI;CAEZ,OAAO;EACL,MAAM;EACN,QAAQ;GACN,MAAM;GACN,YAAY;IACV,QAAQ,EAAE,GAAG,gBAAgB;IAC7B,aAAa;KACX,MAAM;KACN,aAAa;IACf;IACA,eAAe;KACb,MAAM;KACN,MAAM;KACN,aAAa,GAAG,+BAA+B,cAAc,MAAM,KAAK,IAAI,EAAE;IAChF;GACF;GACA,UAAU,CAAC,eAAe,eAAe;EAC3C;EACA,aAAa,GAAG,wBAAwB,wBAAwB;CAClE;AACF;;;;;;AAOA,SAAgB,6BACd,SACQ;CACR,MAAM,SAAS,wBAAwB,OAAO;CAC9C,OAAO;EACL,MAAM,OAAO;EACb,aAAa,OAAO;EACpB,YAAY,OAAO;CACrB;AACF"}
@@ -6,6 +6,7 @@ import { cloneToolMessageWithContent, compactToolContent, hasComputerCallOutputM
6
6
  import { safeDispatchCustomEvent } from "../utils/events.mjs";
7
7
  import { convertInjectedMessages } from "../messages/injected.mjs";
8
8
  import { buildToolExecutionRequestPlan, recordArgsEqual, resolveRuntimeSessionHint } from "./eagerEventExecution.mjs";
9
+ import { INTENT_ARG, isIntentLabelProperty, outcomeFieldsFromResult, readOutcomeFields, resolveToolOutcome } from "./intentArg.mjs";
9
10
  import { ToolOutputReferenceRegistry, buildReferenceKey } from "./toolOutputReferences.mjs";
10
11
  import { RunnableCallable } from "../utils/run.mjs";
11
12
  import "../utils/index.mjs";
@@ -19,6 +20,12 @@ import { Command, END, Send, interrupt, isCommand, isGraphInterrupt } from "@lan
19
20
  import { nanoid } from "nanoid";
20
21
  import { AsyncLocalStorageProviderSingleton } from "@langchain/core/singletons";
21
22
  //#region src/tools/ToolNode.ts
23
+ function createToolErrorOwnership() {
24
+ return {
25
+ handlerOwned: /* @__PURE__ */ new Set(),
26
+ undispatched: /* @__PURE__ */ new Set()
27
+ };
28
+ }
22
29
  /**
23
30
  * Produces the provider preview and, when requested, the exact registry prefix
24
31
  * in one bounded traversal. String outputs already exist in memory when a tool
@@ -251,12 +258,12 @@ var ToolNode = class extends RunnableCallable {
251
258
  toolCallStepIds;
252
259
  errorHandler;
253
260
  /**
254
- * Tool call ids whose `errorHandler` did NOT dispatch the error completion
255
- * event (it returned `false` or threw). The output loop must dispatch the
256
- * completion for these itself skipping them there would strand the
257
- * client's tool-call part without a terminal event.
261
+ * Fallback error-completion ownership for calls that reach `runTool`
262
+ * outside a batch context (direct `runTool` use in tests / embedders).
263
+ * Batch-scoped ownership is threaded via `RunToolBatchContext` instead
264
+ * see {@link ToolErrorOwnership} for why per-invocation scoping matters.
258
265
  */
259
- undispatchedToolErrors = /* @__PURE__ */ new Set();
266
+ looseErrorOwnership = createToolErrorOwnership();
260
267
  toolUsageCount;
261
268
  /** Maps toolCallId → turn captured in runTool, used by handleRunToolCompletions */
262
269
  toolCallTurns = /* @__PURE__ */ new Map();
@@ -543,8 +550,9 @@ var ToolNode = class extends RunnableCallable {
543
550
  const tool = this.toolMap.get(call.name);
544
551
  const registry = this.toolOutputRegistry;
545
552
  let resolveFn;
546
- if (preBatchSnapshot != null) resolveFn = (_runId, args) => preBatchSnapshot.resolve(args);
547
- else if (registry != null) resolveFn = (runIdArg, args) => registry.resolve(runIdArg, args);
553
+ const resolveOptions = { substituteIntentKey: this.toolDeclaresBusinessIntent(call.name) };
554
+ if (preBatchSnapshot != null) resolveFn = (_runId, args) => preBatchSnapshot.resolve(args, resolveOptions);
555
+ else if (registry != null) resolveFn = (runIdArg, args) => registry.resolve(runIdArg, args, resolveOptions);
548
556
  /**
549
557
  * Precompute the reference key once per call — captured locally
550
558
  * so concurrent `invoke()` calls on the same ToolNode cannot race
@@ -737,12 +745,14 @@ var ToolNode = class extends RunnableCallable {
737
745
  if (!this.handleToolErrors) throw e;
738
746
  if (isGraphInterrupt(e)) throw e;
739
747
  if (this.errorHandler) try {
740
- if (await this.errorHandler({
748
+ const dispatched = await this.errorHandler({
741
749
  error: e,
742
750
  id: call.id,
743
751
  name: call.name,
744
752
  input: call.args
745
- }, config.metadata) === false && call.id != null && call.id !== "")
753
+ }, config.metadata);
754
+ const ownership = batchContext.errorOwnership ?? this.looseErrorOwnership;
755
+ if (call.id != null && call.id !== "") if (dispatched === false)
746
756
  /**
747
757
  * The handler could not dispatch the error completion (typically
748
758
  * a resume pass, where a fast-failing tool errors before the
@@ -750,8 +760,10 @@ var ToolNode = class extends RunnableCallable {
750
760
  * output loop dispatches the completion itself instead of
751
761
  * assuming the handler covered it.
752
762
  */
753
- this.undispatchedToolErrors.add(call.id);
763
+ ownership.undispatched.add(call.id);
764
+ else ownership.handlerOwned.add(call.id);
754
765
  } catch (handlerError) {
766
+ if (call.id != null && call.id !== "") (batchContext.errorOwnership ?? this.looseErrorOwnership).handlerOwned.add(call.id);
755
767
  console.error("Error in errorHandler:", {
756
768
  toolName: call.name,
757
769
  toolCallId: call.id,
@@ -852,11 +864,12 @@ var ToolNode = class extends RunnableCallable {
852
864
  const turn = usageCount;
853
865
  const stepId = this.toolCallStepIds?.get(call.id ?? "") ?? "";
854
866
  let resolvedArgs = call.args;
867
+ const hookResolveOptions = { substituteIntentKey: this.toolDeclaresBusinessIntent(call.name) };
855
868
  if (batchContext.preBatchSnapshot != null) {
856
- const { resolved } = batchContext.preBatchSnapshot.resolve(call.args);
869
+ const { resolved } = batchContext.preBatchSnapshot.resolve(call.args, hookResolveOptions);
857
870
  resolvedArgs = resolved;
858
871
  } else if (this.toolOutputRegistry != null) {
859
- const { resolved } = this.toolOutputRegistry.resolve(registryRunId, call.args);
872
+ const { resolved } = this.toolOutputRegistry.resolve(registryRunId, call.args, hookResolveOptions);
860
873
  resolvedArgs = resolved;
861
874
  }
862
875
  let effectiveCall = call;
@@ -968,6 +981,16 @@ var ToolNode = class extends RunnableCallable {
968
981
  }
969
982
  }
970
983
  }
984
+ /**
985
+ * A hook (`PreToolUse.updatedInput`) or HITL `edit` decision rewrote the
986
+ * args: expose the EFFECTIVE args to downstream completion handling
987
+ * (`handleRunToolCompletions` reads this sink), so the emitted
988
+ * `tool_call.args` — and any intent/outcome label resolved from them —
989
+ * reflect what the tool actually ran with. `runTool`'s own placeholder
990
+ * substitution may overwrite this entry with the post-substitution args,
991
+ * which is strictly more accurate.
992
+ */
993
+ if (effectiveCall !== call && batchContext.resolvedArgsByCallId != null && call.id != null && call.id !== "") batchContext.resolvedArgsByCallId.set(call.id, effectiveCall.args);
971
994
  const output = await this.runTool(effectiveCall, config, {
972
995
  ...batchContext,
973
996
  usageCount
@@ -1174,7 +1197,8 @@ var ToolNode = class extends RunnableCallable {
1174
1197
  * by `runTool`. Threaded as a local map (instead of instance state)
1175
1198
  * so concurrent batches cannot read each other's entries.
1176
1199
  */
1177
- async handleRunToolCompletions(calls, outputs, config, resolvedArgsByCallId) {
1200
+ async handleRunToolCompletions(calls, outputs, config, resolvedArgsByCallId, errorOwnership) {
1201
+ const ownership = errorOwnership ?? this.looseErrorOwnership;
1178
1202
  for (let i = 0; i < calls.length; i++) {
1179
1203
  const call = calls[i];
1180
1204
  const output = outputs[i];
@@ -1182,8 +1206,13 @@ var ToolNode = class extends RunnableCallable {
1182
1206
  if (isCommand(output)) continue;
1183
1207
  const toolMessage = output;
1184
1208
  const toolCallId = call.id ?? "";
1185
- if (toolMessage.status === "error" && this.errorHandler != null) if (this.undispatchedToolErrors.has(toolCallId)) this.undispatchedToolErrors.delete(toolCallId);
1186
- else continue;
1209
+ if (toolMessage.status === "error" && this.errorHandler != null) {
1210
+ if (ownership.handlerOwned.has(toolCallId)) {
1211
+ ownership.handlerOwned.delete(toolCallId);
1212
+ continue;
1213
+ }
1214
+ ownership.undispatched.delete(toolCallId);
1215
+ }
1187
1216
  if (this.sessions && this.participatesInCodeSession(call.name)) {
1188
1217
  const artifact = toolMessage.artifact;
1189
1218
  const execSessionId = artifact?.session_id;
@@ -1195,16 +1224,27 @@ var ToolNode = class extends RunnableCallable {
1195
1224
  if (isComputerCallOutputMessage(toolMessage)) contentString = truncateToolResultContent("[Computer screenshot omitted from completion event]", this.maxToolResultChars);
1196
1225
  else if (typeof toolMessage.content === "string") contentString = toolMessage.content;
1197
1226
  else contentString = serializeStructuredValueBounded(toolMessage.content, this.maxToolResultChars).content;
1227
+ /**
1228
+ * Prefer the post-substitution args when a `{{…}}` placeholder
1229
+ * was resolved in `runTool`. This keeps
1230
+ * `ON_RUN_STEP_COMPLETED.tool_call.args` consistent with what
1231
+ * the tool actually received rather than leaking the template.
1232
+ */
1233
+ const effectiveArgs = resolvedArgsByCallId?.get(toolCallId) ?? call.args;
1234
+ /** Authored outcomes apply to failed calls too (“Search failed for…”);
1235
+ * without one, an error call simply stays unlabeled. */
1236
+ const outcome = resolveToolOutcome(effectiveArgs, readOutcomeFields(toolMessage.artifact), { isError: toolMessage.status === "error" });
1198
1237
  await safeDispatchCustomEvent("on_run_step_completed", { result: {
1199
1238
  id: stepId,
1200
1239
  index: turn,
1201
1240
  type: "tool_call",
1202
1241
  tool_call: {
1203
- args: serializeToolContentBounded(resolvedArgsByCallId?.get(toolCallId) ?? call.args ?? {}, this.maxToolResultChars),
1242
+ args: serializeToolContentBounded(effectiveArgs ?? {}, this.maxToolResultChars),
1204
1243
  name: call.name,
1205
1244
  id: toolCallId,
1206
1245
  output: contentString,
1207
- progress: 1
1246
+ progress: 1,
1247
+ ...outcome != null && { outcome }
1208
1248
  }
1209
1249
  } }, config);
1210
1250
  }
@@ -1253,7 +1293,7 @@ var ToolNode = class extends RunnableCallable {
1253
1293
  resolvedArgs = pre.resolved;
1254
1294
  if (pre.unresolved.length > 0 && call.id != null) unresolvedByCallId.set(call.id, pre.unresolved);
1255
1295
  } else if (registry != null) {
1256
- const { resolved, unresolved } = registry.resolve(registryRunId, originalArgs);
1296
+ const { resolved, unresolved } = registry.resolve(registryRunId, originalArgs, { substituteIntentKey: this.toolDeclaresBusinessIntent(call.name) });
1257
1297
  resolvedArgs = resolved;
1258
1298
  if (unresolved.length > 0 && call.id != null) unresolvedByCallId.set(call.id, unresolved);
1259
1299
  }
@@ -1429,7 +1469,7 @@ var ToolNode = class extends RunnableCallable {
1429
1469
  */
1430
1470
  const applyInputOverride = (entry, nextArgs) => {
1431
1471
  if (registry != null) {
1432
- const { resolved, unresolved } = (preBatchSnapshot ?? { resolve: (args) => registry.resolve(registryRunId, args) }).resolve(nextArgs);
1472
+ const { resolved, unresolved } = (preBatchSnapshot ?? { resolve: (args, options) => registry.resolve(registryRunId, args, options) }).resolve(nextArgs, { substituteIntentKey: this.toolDeclaresBusinessIntent(entry.call.name) });
1433
1473
  entry.args = resolved;
1434
1474
  if (entry.call.id != null) if (unresolved.length > 0) unresolvedByCallId.set(entry.call.id, unresolved);
1435
1475
  else unresolvedByCallId.delete(entry.call.id);
@@ -1890,7 +1930,7 @@ var ToolNode = class extends RunnableCallable {
1890
1930
  ...successRefMeta != null && { additional_kwargs: successRefMeta }
1891
1931
  });
1892
1932
  }
1893
- if (!eagerCompletionDispatchedIds.has(result.toolCallId) && !earlyCompletionDispatchedIds.has(result.toolCallId)) await this.dispatchStepCompleted(result.toolCallId, toolName, request?.args ?? {}, contentString, config, request?.turn);
1933
+ if (!eagerCompletionDispatchedIds.has(result.toolCallId) && !earlyCompletionDispatchedIds.has(result.toolCallId)) await this.dispatchStepCompleted(result.toolCallId, toolName, request?.args ?? {}, contentString, config, request?.turn, resolveToolOutcome(request?.args, outcomeFieldsFromResult(result), { isError: result.status === "error" }));
1894
1934
  postToolBatchEntryByCallId.set(result.toolCallId, {
1895
1935
  toolName,
1896
1936
  toolInput: request?.args ?? {},
@@ -2026,7 +2066,21 @@ var ToolNode = class extends RunnableCallable {
2026
2066
  console.warn("[ToolNode] Failed to convert PostToolBatch injectedMessages:", e instanceof Error ? e.message : e);
2027
2067
  }
2028
2068
  }
2029
- async dispatchStepCompleted(toolCallId, toolName, args, output, config, turn) {
2069
+ /**
2070
+ * Whether `name`'s own schema declares a BUSINESS parameter called
2071
+ * `intent` (declared, and not the injected label contract — see
2072
+ * `isIntentLabelProperty`). Such a parameter must keep participating in
2073
+ * `{{tool…}}` placeholder substitution; only the display label is exempt.
2074
+ */
2075
+ toolDeclaresBusinessIntent(name) {
2076
+ const instance = this.toolMap.get(name);
2077
+ const instanceProp = instance?.schema?.properties?.["intent"] ?? instance?.schema?.shape?.["intent"];
2078
+ if (instanceProp != null) return !isIntentLabelProperty(instanceProp);
2079
+ const defProp = this.toolRegistry?.get(name)?.parameters?.properties?.[INTENT_ARG];
2080
+ if (defProp != null) return !isIntentLabelProperty(defProp);
2081
+ return false;
2082
+ }
2083
+ async dispatchStepCompleted(toolCallId, toolName, args, output, config, turn, outcome) {
2030
2084
  const stepId = this.toolCallStepIds?.get(toolCallId) ?? "";
2031
2085
  if (!stepId) console.warn(`[ToolNode] toolCallStepIds missing entry for toolCallId=${toolCallId} (tool=${toolName}). This indicates a race between the stream consumer and graph execution. Map size: ${this.toolCallStepIds?.size ?? 0}`);
2032
2086
  return await safeDispatchCustomEvent("on_run_step_completed", { result: {
@@ -2038,7 +2092,8 @@ var ToolNode = class extends RunnableCallable {
2038
2092
  name: toolName,
2039
2093
  id: toolCallId,
2040
2094
  output,
2041
- progress: 1
2095
+ progress: 1,
2096
+ ...outcome != null && { outcome }
2042
2097
  }
2043
2098
  } }, config) !== false;
2044
2099
  }
@@ -2051,7 +2106,7 @@ var ToolNode = class extends RunnableCallable {
2051
2106
  */
2052
2107
  async dispatchEarlyToolCompletion(result, request, config) {
2053
2108
  const output = result.status === "error" ? truncateToolResultContent(`Error: ${result.errorMessage ?? "Unknown error"}\n Please fix your mistakes.`, this.maxToolResultChars) : serializeToolOutputWithinLimits(result.content, this.maxToolResultChars).content;
2054
- return this.dispatchStepCompleted(result.toolCallId, request.name, request.args, output, config, request.turn);
2109
+ return this.dispatchStepCompleted(result.toolCallId, request.name, request.args, output, config, request.turn, resolveToolOutcome(request.args, outcomeFieldsFromResult(result), { isError: result.status === "error" }));
2055
2110
  }
2056
2111
  /**
2057
2112
  * Execute a group of direct (in-process) tool calls with interrupt-safe
@@ -2132,6 +2187,8 @@ var ToolNode = class extends RunnableCallable {
2132
2187
  * ToolNode cannot read or wipe each other's entries.
2133
2188
  */
2134
2189
  const resolvedArgsByCallId = /* @__PURE__ */ new Map();
2190
+ /** Per-invocation error-completion ownership — see `ToolErrorOwnership`. */
2191
+ const errorOwnership = createToolErrorOwnership();
2135
2192
  const batchScopeId = config.configurable?.run_id ?? `\0anon-${this.anonBatchCounter++}`;
2136
2193
  const turn = this.toolOutputRegistry?.nextTurn(batchScopeId) ?? 0;
2137
2194
  let outputs;
@@ -2149,6 +2206,7 @@ var ToolNode = class extends RunnableCallable {
2149
2206
  turn,
2150
2207
  batchScopeId,
2151
2208
  resolvedArgsByCallId,
2209
+ errorOwnership,
2152
2210
  additionalContextsSink: directAdditionalContexts,
2153
2211
  runInput: sendState
2154
2212
  });
@@ -2159,7 +2217,7 @@ var ToolNode = class extends RunnableCallable {
2159
2217
  source: "hook"
2160
2218
  }
2161
2219
  })] : [sendOutput];
2162
- await this.handleRunToolCompletions([input.lg_tool_call], [sendOutput], config, resolvedArgsByCallId);
2220
+ await this.handleRunToolCompletions([input.lg_tool_call], [sendOutput], config, resolvedArgsByCallId, errorOwnership);
2163
2221
  } else {
2164
2222
  let messages;
2165
2223
  if (Array.isArray(input)) messages = input;
@@ -2237,7 +2295,7 @@ var ToolNode = class extends RunnableCallable {
2237
2295
  const preBatchSnapshot = this.toolOutputRegistry?.snapshot(batchScopeId);
2238
2296
  if (preBatchSnapshot != null) {
2239
2297
  for (const entry of eventEntries) if (entry.call.id != null) {
2240
- const { resolved, unresolved } = preBatchSnapshot.resolve(entry.call.args);
2298
+ const { resolved, unresolved } = preBatchSnapshot.resolve(entry.call.args, { substituteIntentKey: this.toolDeclaresBusinessIntent(entry.call.name) });
2241
2299
  preResolvedEventArgs.set(entry.call.id, {
2242
2300
  resolved,
2243
2301
  unresolved
@@ -2249,11 +2307,12 @@ var ToolNode = class extends RunnableCallable {
2249
2307
  turn,
2250
2308
  batchScopeId,
2251
2309
  resolvedArgsByCallId,
2310
+ errorOwnership,
2252
2311
  preBatchSnapshot,
2253
2312
  additionalContextsSink: directAdditionalContexts,
2254
2313
  runInput: input
2255
2314
  }) : [];
2256
- if (directCalls.length > 0 && directOutputs.length > 0) await this.handleRunToolCompletions(directCalls, directOutputs, config, resolvedArgsByCallId);
2315
+ if (directCalls.length > 0 && directOutputs.length > 0) await this.handleRunToolCompletions(directCalls, directOutputs, config, resolvedArgsByCallId, errorOwnership);
2257
2316
  const eventResult = eventCalls.length > 0 ? await this.dispatchToolEvents(eventCalls, config, {
2258
2317
  batchIndices: eventIndices,
2259
2318
  turn,
@@ -2284,11 +2343,12 @@ var ToolNode = class extends RunnableCallable {
2284
2343
  turn,
2285
2344
  batchScopeId,
2286
2345
  resolvedArgsByCallId,
2346
+ errorOwnership,
2287
2347
  preBatchSnapshot,
2288
2348
  additionalContextsSink: directAdditionalContexts,
2289
2349
  runInput: input
2290
2350
  });
2291
- await this.handleRunToolCompletions(filteredCalls, toolOutputs, config, resolvedArgsByCallId);
2351
+ await this.handleRunToolCompletions(filteredCalls, toolOutputs, config, resolvedArgsByCallId, errorOwnership);
2292
2352
  outputs = directAdditionalContexts.length > 0 ? [...toolOutputs, new HumanMessage({
2293
2353
  content: directAdditionalContexts.join("\n\n"),
2294
2354
  additional_kwargs: {
@@ -2394,6 +2454,6 @@ function toolsCondition(state, toolNode, invokedToolIds) {
2394
2454
  return END;
2395
2455
  }
2396
2456
  //#endregion
2397
- export { ToolNode, toolsCondition };
2457
+ export { ToolNode, createToolErrorOwnership, toolsCondition };
2398
2458
 
2399
2459
  //# sourceMappingURL=ToolNode.mjs.map