@librechat/agents 3.1.68 → 3.1.71-dev.0

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 (192) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +23 -3
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/common/enum.cjs +16 -1
  4. package/dist/cjs/common/enum.cjs.map +1 -1
  5. package/dist/cjs/graphs/Graph.cjs +136 -0
  6. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  7. package/dist/cjs/hooks/HookRegistry.cjs +162 -0
  8. package/dist/cjs/hooks/HookRegistry.cjs.map +1 -0
  9. package/dist/cjs/hooks/executeHooks.cjs +276 -0
  10. package/dist/cjs/hooks/executeHooks.cjs.map +1 -0
  11. package/dist/cjs/hooks/matchers.cjs +256 -0
  12. package/dist/cjs/hooks/matchers.cjs.map +1 -0
  13. package/dist/cjs/hooks/types.cjs +27 -0
  14. package/dist/cjs/hooks/types.cjs.map +1 -0
  15. package/dist/cjs/main.cjs +57 -0
  16. package/dist/cjs/main.cjs.map +1 -1
  17. package/dist/cjs/messages/format.cjs +74 -12
  18. package/dist/cjs/messages/format.cjs.map +1 -1
  19. package/dist/cjs/messages/prune.cjs +9 -2
  20. package/dist/cjs/messages/prune.cjs.map +1 -1
  21. package/dist/cjs/run.cjs +115 -0
  22. package/dist/cjs/run.cjs.map +1 -1
  23. package/dist/cjs/summarization/node.cjs +44 -0
  24. package/dist/cjs/summarization/node.cjs.map +1 -1
  25. package/dist/cjs/tools/BashExecutor.cjs +208 -0
  26. package/dist/cjs/tools/BashExecutor.cjs.map +1 -0
  27. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +287 -0
  28. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -0
  29. package/dist/cjs/tools/CodeExecutor.cjs +0 -9
  30. package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
  31. package/dist/cjs/tools/ProgrammaticToolCalling.cjs +7 -23
  32. package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
  33. package/dist/cjs/tools/ReadFile.cjs +43 -0
  34. package/dist/cjs/tools/ReadFile.cjs.map +1 -0
  35. package/dist/cjs/tools/SkillTool.cjs +50 -0
  36. package/dist/cjs/tools/SkillTool.cjs.map +1 -0
  37. package/dist/cjs/tools/SubagentTool.cjs +92 -0
  38. package/dist/cjs/tools/SubagentTool.cjs.map +1 -0
  39. package/dist/cjs/tools/ToolNode.cjs +746 -174
  40. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  41. package/dist/cjs/tools/ToolSearch.cjs +2 -13
  42. package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
  43. package/dist/cjs/tools/skillCatalog.cjs +84 -0
  44. package/dist/cjs/tools/skillCatalog.cjs.map +1 -0
  45. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +511 -0
  46. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -0
  47. package/dist/cjs/tools/toolOutputReferences.cjs +475 -0
  48. package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -0
  49. package/dist/cjs/utils/truncation.cjs +28 -0
  50. package/dist/cjs/utils/truncation.cjs.map +1 -1
  51. package/dist/esm/agents/AgentContext.mjs +23 -3
  52. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  53. package/dist/esm/common/enum.mjs +15 -2
  54. package/dist/esm/common/enum.mjs.map +1 -1
  55. package/dist/esm/graphs/Graph.mjs +136 -0
  56. package/dist/esm/graphs/Graph.mjs.map +1 -1
  57. package/dist/esm/hooks/HookRegistry.mjs +160 -0
  58. package/dist/esm/hooks/HookRegistry.mjs.map +1 -0
  59. package/dist/esm/hooks/executeHooks.mjs +273 -0
  60. package/dist/esm/hooks/executeHooks.mjs.map +1 -0
  61. package/dist/esm/hooks/matchers.mjs +251 -0
  62. package/dist/esm/hooks/matchers.mjs.map +1 -0
  63. package/dist/esm/hooks/types.mjs +25 -0
  64. package/dist/esm/hooks/types.mjs.map +1 -0
  65. package/dist/esm/main.mjs +13 -2
  66. package/dist/esm/main.mjs.map +1 -1
  67. package/dist/esm/messages/format.mjs +66 -4
  68. package/dist/esm/messages/format.mjs.map +1 -1
  69. package/dist/esm/messages/prune.mjs +9 -2
  70. package/dist/esm/messages/prune.mjs.map +1 -1
  71. package/dist/esm/run.mjs +115 -0
  72. package/dist/esm/run.mjs.map +1 -1
  73. package/dist/esm/summarization/node.mjs +44 -0
  74. package/dist/esm/summarization/node.mjs.map +1 -1
  75. package/dist/esm/tools/BashExecutor.mjs +200 -0
  76. package/dist/esm/tools/BashExecutor.mjs.map +1 -0
  77. package/dist/esm/tools/BashProgrammaticToolCalling.mjs +278 -0
  78. package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -0
  79. package/dist/esm/tools/CodeExecutor.mjs +0 -9
  80. package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
  81. package/dist/esm/tools/ProgrammaticToolCalling.mjs +8 -24
  82. package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
  83. package/dist/esm/tools/ReadFile.mjs +38 -0
  84. package/dist/esm/tools/ReadFile.mjs.map +1 -0
  85. package/dist/esm/tools/SkillTool.mjs +45 -0
  86. package/dist/esm/tools/SkillTool.mjs.map +1 -0
  87. package/dist/esm/tools/SubagentTool.mjs +85 -0
  88. package/dist/esm/tools/SubagentTool.mjs.map +1 -0
  89. package/dist/esm/tools/ToolNode.mjs +748 -176
  90. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  91. package/dist/esm/tools/ToolSearch.mjs +3 -14
  92. package/dist/esm/tools/ToolSearch.mjs.map +1 -1
  93. package/dist/esm/tools/skillCatalog.mjs +82 -0
  94. package/dist/esm/tools/skillCatalog.mjs.map +1 -0
  95. package/dist/esm/tools/subagent/SubagentExecutor.mjs +505 -0
  96. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -0
  97. package/dist/esm/tools/toolOutputReferences.mjs +468 -0
  98. package/dist/esm/tools/toolOutputReferences.mjs.map +1 -0
  99. package/dist/esm/utils/truncation.mjs +27 -1
  100. package/dist/esm/utils/truncation.mjs.map +1 -1
  101. package/dist/types/agents/AgentContext.d.ts +6 -0
  102. package/dist/types/common/enum.d.ts +10 -2
  103. package/dist/types/graphs/Graph.d.ts +23 -0
  104. package/dist/types/hooks/HookRegistry.d.ts +56 -0
  105. package/dist/types/hooks/executeHooks.d.ts +79 -0
  106. package/dist/types/hooks/index.d.ts +6 -0
  107. package/dist/types/hooks/matchers.d.ts +95 -0
  108. package/dist/types/hooks/types.d.ts +320 -0
  109. package/dist/types/index.d.ts +8 -0
  110. package/dist/types/messages/format.d.ts +2 -1
  111. package/dist/types/run.d.ts +2 -0
  112. package/dist/types/summarization/node.d.ts +2 -0
  113. package/dist/types/tools/BashExecutor.d.ts +76 -0
  114. package/dist/types/tools/BashProgrammaticToolCalling.d.ts +72 -0
  115. package/dist/types/tools/ProgrammaticToolCalling.d.ts +4 -9
  116. package/dist/types/tools/ReadFile.d.ts +28 -0
  117. package/dist/types/tools/SkillTool.d.ts +40 -0
  118. package/dist/types/tools/SubagentTool.d.ts +36 -0
  119. package/dist/types/tools/ToolNode.d.ts +109 -4
  120. package/dist/types/tools/ToolSearch.d.ts +2 -2
  121. package/dist/types/tools/skillCatalog.d.ts +19 -0
  122. package/dist/types/tools/subagent/SubagentExecutor.d.ts +137 -0
  123. package/dist/types/tools/subagent/index.d.ts +2 -0
  124. package/dist/types/tools/toolOutputReferences.d.ts +205 -0
  125. package/dist/types/types/graph.d.ts +61 -2
  126. package/dist/types/types/index.d.ts +1 -0
  127. package/dist/types/types/run.d.ts +28 -0
  128. package/dist/types/types/skill.d.ts +9 -0
  129. package/dist/types/types/tools.d.ts +108 -10
  130. package/dist/types/utils/truncation.d.ts +21 -0
  131. package/package.json +5 -1
  132. package/src/agents/AgentContext.ts +26 -2
  133. package/src/common/enum.ts +15 -1
  134. package/src/graphs/Graph.ts +161 -0
  135. package/src/hooks/HookRegistry.ts +208 -0
  136. package/src/hooks/__tests__/HookRegistry.test.ts +190 -0
  137. package/src/hooks/__tests__/compactHooks.test.ts +214 -0
  138. package/src/hooks/__tests__/executeHooks.test.ts +1013 -0
  139. package/src/hooks/__tests__/integration.test.ts +337 -0
  140. package/src/hooks/__tests__/matchers.test.ts +238 -0
  141. package/src/hooks/__tests__/toolHooks.test.ts +669 -0
  142. package/src/hooks/executeHooks.ts +375 -0
  143. package/src/hooks/index.ts +57 -0
  144. package/src/hooks/matchers.ts +280 -0
  145. package/src/hooks/types.ts +404 -0
  146. package/src/index.ts +10 -0
  147. package/src/messages/format.ts +74 -4
  148. package/src/messages/formatAgentMessages.skills.test.ts +334 -0
  149. package/src/messages/prune.ts +9 -2
  150. package/src/run.ts +130 -0
  151. package/src/scripts/multi-agent-subagent.ts +246 -0
  152. package/src/scripts/programmatic_exec.ts +1 -10
  153. package/src/scripts/subagent-event-driven-debug.ts +190 -0
  154. package/src/scripts/subagent-tools-debug.ts +160 -0
  155. package/src/scripts/test_code_api.ts +0 -7
  156. package/src/scripts/tool_search.ts +1 -10
  157. package/src/specs/prune.test.ts +413 -0
  158. package/src/specs/subagent.test.ts +305 -0
  159. package/src/summarization/node.ts +53 -0
  160. package/src/tools/BashExecutor.ts +238 -0
  161. package/src/tools/BashProgrammaticToolCalling.ts +381 -0
  162. package/src/tools/CodeExecutor.ts +0 -11
  163. package/src/tools/ProgrammaticToolCalling.ts +4 -29
  164. package/src/tools/ReadFile.ts +39 -0
  165. package/src/tools/SkillTool.ts +46 -0
  166. package/src/tools/SubagentTool.ts +100 -0
  167. package/src/tools/ToolNode.ts +999 -214
  168. package/src/tools/ToolSearch.ts +3 -19
  169. package/src/tools/__tests__/BashExecutor.test.ts +36 -0
  170. package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts +7 -8
  171. package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +0 -1
  172. package/src/tools/__tests__/ReadFile.test.ts +44 -0
  173. package/src/tools/__tests__/SkillTool.test.ts +442 -0
  174. package/src/tools/__tests__/SubagentExecutor.test.ts +1148 -0
  175. package/src/tools/__tests__/SubagentTool.test.ts +149 -0
  176. package/src/tools/__tests__/ToolNode.outputReferences.test.ts +1395 -0
  177. package/src/tools/__tests__/ToolNode.session.test.ts +12 -12
  178. package/src/tools/__tests__/ToolSearch.integration.test.ts +7 -8
  179. package/src/tools/__tests__/skillCatalog.test.ts +161 -0
  180. package/src/tools/__tests__/subagentHooks.test.ts +215 -0
  181. package/src/tools/__tests__/toolOutputReferences.test.ts +415 -0
  182. package/src/tools/skillCatalog.ts +126 -0
  183. package/src/tools/subagent/SubagentExecutor.ts +676 -0
  184. package/src/tools/subagent/index.ts +13 -0
  185. package/src/tools/toolOutputReferences.ts +590 -0
  186. package/src/types/graph.ts +80 -1
  187. package/src/types/index.ts +1 -0
  188. package/src/types/run.ts +28 -0
  189. package/src/types/skill.ts +11 -0
  190. package/src/types/tools.ts +112 -10
  191. package/src/utils/__tests__/truncation.test.ts +66 -0
  192. package/src/utils/truncation.ts +30 -0
@@ -0,0 +1,76 @@
1
+ import { DynamicStructuredTool } from '@langchain/core/tools';
2
+ import type * as t from '@/types';
3
+ import { Constants } from '@/common';
4
+ export declare const BashExecutionToolSchema: {
5
+ readonly type: "object";
6
+ readonly properties: {
7
+ readonly command: {
8
+ readonly type: "string";
9
+ readonly description: "The bash command or script to execute.\n- The environment is stateless; variables and state don't persist between executions.\n- Generated files from previous executions are automatically available in \"/mnt/data/\".\n- Files from previous executions are automatically available and can be modified in place.\n- Input code **IS ALREADY** displayed to the user, so **DO NOT** repeat it in your response unless asked.\n- Output code **IS NOT** displayed to the user, so **DO** write all desired output explicitly.\n- IMPORTANT: You MUST explicitly print/output ALL results you want the user to see.\n- Use `echo`, `printf`, or `cat` for all outputs.";
10
+ };
11
+ readonly args: {
12
+ readonly type: "array";
13
+ readonly items: {
14
+ readonly type: "string";
15
+ };
16
+ readonly description: "Additional arguments to execute the command with. This should only be used if the input command requires additional arguments to run.";
17
+ };
18
+ };
19
+ readonly required: readonly ["command"];
20
+ };
21
+ export declare const BashExecutionToolDescription: string;
22
+ /**
23
+ * Supplemental prompt documenting the tool-output reference feature.
24
+ *
25
+ * Hosts should append this (separated by a blank line) to the base
26
+ * {@link BashExecutionToolDescription} only when
27
+ * `RunConfig.toolOutputReferences.enabled` is `true`. When the feature
28
+ * is disabled, including this text would tell the LLM to emit
29
+ * `{{tool0turn0}}` placeholders that pass through unsubstituted and
30
+ * leak into the shell.
31
+ */
32
+ export declare const BashToolOutputReferencesGuide: string;
33
+ /**
34
+ * Composes the bash tool description, optionally appending the
35
+ * tool-output references guide. Hosts that enable
36
+ * `RunConfig.toolOutputReferences` should pass `enableToolOutputReferences: true`
37
+ * when registering the tool so the LLM learns the `{{…}}` syntax it
38
+ * will actually be able to use.
39
+ */
40
+ export declare function buildBashExecutionToolDescription(options?: {
41
+ enableToolOutputReferences?: boolean;
42
+ }): string;
43
+ export declare const BashExecutionToolName = Constants.BASH_TOOL;
44
+ /**
45
+ * Default bash tool definition using the base description.
46
+ *
47
+ * When `RunConfig.toolOutputReferences.enabled` is `true`, build a
48
+ * reference-aware description with
49
+ * {@link buildBashExecutionToolDescription}
50
+ * (`{ enableToolOutputReferences: true }`) and construct a custom
51
+ * definition using it — using this constant as-is leaves the LLM
52
+ * unaware of the `{{tool<i>turn<n>}}` syntax.
53
+ */
54
+ export declare const BashExecutionToolDefinition: {
55
+ readonly name: Constants.BASH_TOOL;
56
+ readonly description: string;
57
+ readonly schema: {
58
+ readonly type: "object";
59
+ readonly properties: {
60
+ readonly command: {
61
+ readonly type: "string";
62
+ readonly description: "The bash command or script to execute.\n- The environment is stateless; variables and state don't persist between executions.\n- Generated files from previous executions are automatically available in \"/mnt/data/\".\n- Files from previous executions are automatically available and can be modified in place.\n- Input code **IS ALREADY** displayed to the user, so **DO NOT** repeat it in your response unless asked.\n- Output code **IS NOT** displayed to the user, so **DO** write all desired output explicitly.\n- IMPORTANT: You MUST explicitly print/output ALL results you want the user to see.\n- Use `echo`, `printf`, or `cat` for all outputs.";
63
+ };
64
+ readonly args: {
65
+ readonly type: "array";
66
+ readonly items: {
67
+ readonly type: "string";
68
+ };
69
+ readonly description: "Additional arguments to execute the command with. This should only be used if the input command requires additional arguments to run.";
70
+ };
71
+ };
72
+ readonly required: readonly ["command"];
73
+ };
74
+ };
75
+ declare function createBashExecutionTool(params?: t.BashExecutionToolParams): DynamicStructuredTool;
76
+ export { createBashExecutionTool };
@@ -0,0 +1,72 @@
1
+ import { DynamicStructuredTool } from '@langchain/core/tools';
2
+ import type * as t from '@/types';
3
+ import { Constants } from '@/common';
4
+ export declare const BashProgrammaticToolCallingSchema: {
5
+ readonly type: "object";
6
+ readonly properties: {
7
+ readonly code: {
8
+ readonly type: "string";
9
+ readonly minLength: 1;
10
+ readonly description: "Bash code that calls tools programmatically. Tools are available as bash functions.\n\nCRITICAL - STATELESS EXECUTION:\nEach call is a fresh bash shell. Variables and state do NOT persist between calls.\nYou MUST complete your entire workflow in ONE code block.\nDO NOT split work across multiple calls expecting to reuse variables.\n\nEach tool function accepts a JSON string as its argument.\nExample: tool_name '{\"key\": \"value\"}'\n\nExample (Complete workflow in one call):\n # Query data and process\n data=$(query_database '{\"sql\": \"SELECT * FROM users\"}')\n echo \"$data\" | jq '.[] | .name'\n\nExample (Parallel calls):\n web_search '{\"query\": \"SF weather\"}' > /tmp/sf.txt &\n web_search '{\"query\": \"NY weather\"}' > /tmp/ny.txt &\n wait\n echo \"SF: $(cat /tmp/sf.txt)\"\n echo \"NY: $(cat /tmp/ny.txt)\"\n\nRules:\n- EVERYTHING in one call—no state persists between executions\n- Tools are pre-defined as bash functions—DO NOT redefine them\n- Each tool function accepts a JSON string argument\n- Only echo/printf output returns to the model\n- Generated files are automatically available in /mnt/data/ for subsequent executions";
11
+ };
12
+ readonly timeout: {
13
+ readonly type: "integer";
14
+ readonly minimum: 1000;
15
+ readonly maximum: 300000;
16
+ readonly default: 60000;
17
+ readonly description: "Maximum execution time in milliseconds. Default: 60 seconds. Max: 5 minutes.";
18
+ };
19
+ };
20
+ readonly required: readonly ["code"];
21
+ };
22
+ export declare const BashProgrammaticToolCallingName = Constants.BASH_PROGRAMMATIC_TOOL_CALLING;
23
+ export declare const BashProgrammaticToolCallingDescription: string;
24
+ export declare const BashProgrammaticToolCallingDefinition: {
25
+ readonly name: Constants.BASH_PROGRAMMATIC_TOOL_CALLING;
26
+ readonly description: string;
27
+ readonly schema: {
28
+ readonly type: "object";
29
+ readonly properties: {
30
+ readonly code: {
31
+ readonly type: "string";
32
+ readonly minLength: 1;
33
+ readonly description: "Bash code that calls tools programmatically. Tools are available as bash functions.\n\nCRITICAL - STATELESS EXECUTION:\nEach call is a fresh bash shell. Variables and state do NOT persist between calls.\nYou MUST complete your entire workflow in ONE code block.\nDO NOT split work across multiple calls expecting to reuse variables.\n\nEach tool function accepts a JSON string as its argument.\nExample: tool_name '{\"key\": \"value\"}'\n\nExample (Complete workflow in one call):\n # Query data and process\n data=$(query_database '{\"sql\": \"SELECT * FROM users\"}')\n echo \"$data\" | jq '.[] | .name'\n\nExample (Parallel calls):\n web_search '{\"query\": \"SF weather\"}' > /tmp/sf.txt &\n web_search '{\"query\": \"NY weather\"}' > /tmp/ny.txt &\n wait\n echo \"SF: $(cat /tmp/sf.txt)\"\n echo \"NY: $(cat /tmp/ny.txt)\"\n\nRules:\n- EVERYTHING in one call—no state persists between executions\n- Tools are pre-defined as bash functions—DO NOT redefine them\n- Each tool function accepts a JSON string argument\n- Only echo/printf output returns to the model\n- Generated files are automatically available in /mnt/data/ for subsequent executions";
34
+ };
35
+ readonly timeout: {
36
+ readonly type: "integer";
37
+ readonly minimum: 1000;
38
+ readonly maximum: 300000;
39
+ readonly default: 60000;
40
+ readonly description: "Maximum execution time in milliseconds. Default: 60 seconds. Max: 5 minutes.";
41
+ };
42
+ };
43
+ readonly required: readonly ["code"];
44
+ };
45
+ };
46
+ /**
47
+ * Normalizes a tool name to a valid bash function identifier.
48
+ * 1. Replace hyphens, spaces, dots with underscores
49
+ * 2. Remove any other invalid characters
50
+ * 3. Prefix with underscore if starts with number
51
+ * 4. Append `_tool` if it's a bash reserved word
52
+ */
53
+ export declare function normalizeToBashIdentifier(name: string): string;
54
+ /**
55
+ * Extracts tool names that are actually called in the bash code.
56
+ * Bash functions are invoked as commands (no parentheses), so we match
57
+ * the normalized name as a word boundary.
58
+ */
59
+ export declare function extractUsedBashToolNames(code: string, toolNameMap: Map<string, string>): Set<string>;
60
+ /**
61
+ * Filters tool definitions to only include tools actually used in the bash code.
62
+ */
63
+ export declare function filterBashToolsByUsage(toolDefs: t.LCTool[], code: string, debug?: boolean): t.LCTool[];
64
+ /**
65
+ * Creates a Bash Programmatic Tool Calling tool for multi-tool orchestration.
66
+ *
67
+ * This tool enables AI agents to write bash scripts that orchestrate multiple
68
+ * tool calls programmatically via the remote Code API, reducing LLM round-trips.
69
+ *
70
+ * The tool map must be provided at runtime via config.toolCall (injected by ToolNode).
71
+ */
72
+ export declare function createBashProgrammaticToolCallingTool(initParams?: t.BashProgrammaticToolCallingParams): DynamicStructuredTool;
@@ -75,21 +75,19 @@ export declare function filterToolsByUsage(toolDefs: t.LCTool[], code: string, d
75
75
  * Fetches files from a previous session to make them available for the current execution.
76
76
  * Files are returned as CodeEnvFile references to be included in the request.
77
77
  * @param baseUrl - The base URL for the Code API
78
- * @param apiKey - The API key for authentication
79
78
  * @param sessionId - The session ID to fetch files from
80
79
  * @param proxy - Optional HTTP proxy URL
81
80
  * @returns Array of CodeEnvFile references, or empty array if fetch fails
82
81
  */
83
- export declare function fetchSessionFiles(baseUrl: string, apiKey: string, sessionId: string, proxy?: string): Promise<t.CodeEnvFile[]>;
82
+ export declare function fetchSessionFiles(baseUrl: string, sessionId: string, proxy?: string): Promise<t.CodeEnvFile[]>;
84
83
  /**
85
84
  * Makes an HTTP request to the Code API.
86
85
  * @param endpoint - The API endpoint URL
87
- * @param apiKey - The API key for authentication
88
86
  * @param body - The request body
89
87
  * @param proxy - Optional HTTP proxy URL
90
88
  * @returns The parsed API response
91
89
  */
92
- export declare function makeRequest(endpoint: string, apiKey: string, body: Record<string, unknown>, proxy?: string): Promise<t.ProgrammaticExecutionResponse>;
90
+ export declare function makeRequest(endpoint: string, body: Record<string, unknown>, proxy?: string): Promise<t.ProgrammaticExecutionResponse>;
93
91
  /**
94
92
  * Unwraps tool responses that may be formatted as tuples or content blocks.
95
93
  * MCP tools return [content, artifacts], we need to extract the raw data.
@@ -121,14 +119,11 @@ export declare function formatCompletedResponse(response: t.ProgrammaticExecutio
121
119
  *
122
120
  * The tool map must be provided at runtime via config.configurable.toolMap.
123
121
  *
124
- * @param params - Configuration parameters (apiKey, baseUrl, maxRoundTrips, proxy)
122
+ * @param params - Configuration parameters (baseUrl, maxRoundTrips, proxy)
125
123
  * @returns A LangChain DynamicStructuredTool for programmatic tool calling
126
124
  *
127
125
  * @example
128
- * const ptcTool = createProgrammaticToolCallingTool({
129
- * apiKey: process.env.CODE_API_KEY,
130
- * maxRoundTrips: 20
131
- * });
126
+ * const ptcTool = createProgrammaticToolCallingTool({ maxRoundTrips: 20 });
132
127
  *
133
128
  * const [output, artifact] = await ptcTool.invoke(
134
129
  * { code, tools },
@@ -0,0 +1,28 @@
1
+ import { Constants } from '@/common';
2
+ export declare const ReadFileToolName = Constants.READ_FILE;
3
+ export declare 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.";
4
+ export declare const ReadFileToolSchema: {
5
+ readonly type: "object";
6
+ readonly properties: {
7
+ readonly file_path: {
8
+ readonly type: "string";
9
+ readonly 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.";
10
+ };
11
+ };
12
+ readonly required: readonly ["file_path"];
13
+ };
14
+ export declare const ReadFileToolDefinition: {
15
+ readonly name: Constants.READ_FILE;
16
+ readonly description: "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.";
17
+ readonly parameters: {
18
+ readonly type: "object";
19
+ readonly properties: {
20
+ readonly file_path: {
21
+ readonly type: "string";
22
+ readonly 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.";
23
+ };
24
+ };
25
+ readonly required: readonly ["file_path"];
26
+ };
27
+ readonly responseFormat: "content_and_artifact";
28
+ };
@@ -0,0 +1,40 @@
1
+ import { Constants } from '@/common';
2
+ export declare const SkillToolName = Constants.SKILL_TOOL;
3
+ export declare 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.";
4
+ /**
5
+ * JSON Schema for the SkillTool parameters.
6
+ * Single source of truth used by both SkillToolDefinition (LCTool registry)
7
+ * and createSkillTool() (DynamicStructuredTool instance).
8
+ */
9
+ export declare const SkillToolSchema: {
10
+ readonly type: "object";
11
+ readonly properties: {
12
+ readonly skillName: {
13
+ readonly type: "string";
14
+ readonly 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.";
15
+ };
16
+ readonly args: {
17
+ readonly type: "string";
18
+ readonly description: "Optional freeform arguments string passed to the skill.";
19
+ };
20
+ };
21
+ readonly required: readonly ["skillName"];
22
+ };
23
+ export declare const SkillToolDefinition: {
24
+ readonly name: Constants.SKILL_TOOL;
25
+ readonly description: "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.";
26
+ readonly parameters: {
27
+ readonly type: "object";
28
+ readonly properties: {
29
+ readonly skillName: {
30
+ readonly type: "string";
31
+ readonly 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.";
32
+ };
33
+ readonly args: {
34
+ readonly type: "string";
35
+ readonly description: "Optional freeform arguments string passed to the skill.";
36
+ };
37
+ };
38
+ readonly required: readonly ["skillName"];
39
+ };
40
+ };
@@ -0,0 +1,36 @@
1
+ import { Constants } from '@/common';
2
+ import type { SubagentConfig } from '@/types';
3
+ import type { JsonSchemaType, LCTool } from '@/types/tools';
4
+ export declare const SubagentToolName = Constants.SUBAGENT;
5
+ export declare 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 \u2014 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.";
6
+ export declare const SubagentToolSchema: {
7
+ readonly type: "object";
8
+ readonly properties: {
9
+ readonly description: {
10
+ readonly type: "string";
11
+ readonly description: "Complete task description for the subagent. This is the ONLY information it receives — include all necessary context, requirements, and constraints.";
12
+ };
13
+ readonly subagent_type: {
14
+ readonly type: "string";
15
+ readonly description: "Which subagent type to delegate to. Must be one of the available types.";
16
+ };
17
+ };
18
+ readonly required: string[];
19
+ };
20
+ export declare const SubagentToolDefinition: LCTool;
21
+ /**
22
+ * Build the name, schema, and description params for `tool()` from available configs.
23
+ * Used by `Graph.createAgentNode()` when constructing the runtime tool instance.
24
+ * Extends `SubagentToolSchema` by populating `subagent_type.enum` dynamically.
25
+ */
26
+ export declare function buildSubagentToolParams(configs: SubagentConfig[]): {
27
+ name: string;
28
+ schema: JsonSchemaType;
29
+ description: string;
30
+ };
31
+ /**
32
+ * Create a SubagentTool LCTool definition with dynamic enum and description
33
+ * populated from the available subagent configs.
34
+ * Used for the tool registry in event-driven mode.
35
+ */
36
+ export declare function createSubagentToolDefinition(configs: SubagentConfig[]): LCTool;
@@ -2,8 +2,25 @@ import { ToolCall } from '@langchain/core/messages/tool';
2
2
  import { END, Command, MessagesAnnotation } from '@langchain/langgraph';
3
3
  import type { RunnableConfig } from '@langchain/core/runnables';
4
4
  import type { BaseMessage } from '@langchain/core/messages';
5
+ import type { ResolvedArgsByCallId } from '@/tools/toolOutputReferences';
5
6
  import type * as t from '@/types';
6
7
  import { RunnableCallable } from '@/utils';
8
+ import { ToolOutputReferenceRegistry } from '@/tools/toolOutputReferences';
9
+ /**
10
+ * Per-call batch context for `runTool`. Bundles every optional
11
+ * batch-scoped value the method needs so the signature stays at
12
+ * three positional parameters even as new context fields are added.
13
+ */
14
+ type RunToolBatchContext = {
15
+ /** Position of this call within the parent ToolNode batch. */
16
+ batchIndex?: number;
17
+ /** Batch turn shared across every call in the batch. */
18
+ turn?: number;
19
+ /** Registry partition scope (run id or anonymous batch id). */
20
+ batchScopeId?: string;
21
+ /** Batch-local sink for post-substitution args. */
22
+ resolvedArgsByCallId?: ResolvedArgsByCallId;
23
+ };
7
24
  export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
8
25
  private toolMap;
9
26
  private loadRuntimeTools?;
@@ -28,7 +45,38 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
28
45
  private directToolNames?;
29
46
  /** Maximum characters allowed in a single tool result before truncation. */
30
47
  private maxToolResultChars;
31
- constructor({ tools, toolMap, name, tags, errorHandler, toolCallStepIds, handleToolErrors, loadRuntimeTools, toolRegistry, sessions, eventDrivenMode, agentId, directToolNames, maxContextTokens, maxToolResultChars, }: t.ToolNodeConstructorParams);
48
+ /** Hook registry for PreToolUse/PostToolUse lifecycle hooks */
49
+ private hookRegistry?;
50
+ /**
51
+ * Registry of tool outputs keyed by `tool<idx>turn<turn>`.
52
+ *
53
+ * Populated only when `toolOutputReferences.enabled` is true. The
54
+ * registry owns the run-scoped state (turn counter, last-seen runId,
55
+ * warn-once memo, stored outputs), so sharing a single instance
56
+ * across multiple ToolNodes in a run lets cross-agent `{{…}}`
57
+ * references resolve — which is why multi-agent graphs pass the
58
+ * *same* instance to every ToolNode they compile rather than each
59
+ * ToolNode building its own.
60
+ */
61
+ private toolOutputRegistry?;
62
+ /**
63
+ * Monotonic counter used to mint a unique scope id for anonymous
64
+ * batches (ones invoked without a `run_id` in
65
+ * `config.configurable`). Each such batch gets its own registry
66
+ * partition so concurrent anonymous invocations can't delete each
67
+ * other's in-flight state.
68
+ */
69
+ private anonBatchCounter;
70
+ constructor({ tools, toolMap, name, tags, errorHandler, toolCallStepIds, handleToolErrors, loadRuntimeTools, toolRegistry, sessions, eventDrivenMode, agentId, directToolNames, maxContextTokens, maxToolResultChars, hookRegistry, toolOutputReferences, toolOutputRegistry, }: t.ToolNodeConstructorParams);
71
+ /**
72
+ * Returns the run-scoped tool output registry, or `undefined` when
73
+ * the feature is disabled.
74
+ *
75
+ * @internal Exposed for test observation only. Host code should rely
76
+ * on `{{tool<i>turn<n>}}` substitution at tool-invocation time and
77
+ * not mutate the registry directly.
78
+ */
79
+ _unsafeGetToolOutputRegistry(): ToolOutputReferenceRegistry | undefined;
32
80
  /**
33
81
  * Returns cached programmatic tools, computing once on first access.
34
82
  * Single iteration builds both toolMap and toolDefs simultaneously.
@@ -40,9 +88,36 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
40
88
  */
41
89
  getToolUsageCounts(): ReadonlyMap<string, number>;
42
90
  /**
43
- * Runs a single tool call with error handling
91
+ * Runs a single tool call with error handling.
92
+ *
93
+ * `batchIndex` is the tool's position within the current ToolNode
94
+ * batch and, together with `this.currentTurn`, forms the key used to
95
+ * register the output for future `{{tool<idx>turn<turn>}}`
96
+ * substitutions. Omit when no registration should occur.
97
+ */
98
+ protected runTool(call: ToolCall, config: RunnableConfig, batchContext?: RunToolBatchContext): Promise<BaseMessage | Command>;
99
+ /**
100
+ * Finalizes the LLM-visible content for a tool call and (when a
101
+ * `refKey` is provided) registers the full, raw output under that
102
+ * key.
103
+ *
104
+ * @param llmContent The content string the LLM will see. This is
105
+ * the already-truncated, post-hook view; the annotation is
106
+ * applied on top of it.
107
+ * @param registryContent The full, untruncated output to store in
108
+ * the registry so `{{tool<i>turn<n>}}` substitutions deliver the
109
+ * complete payload. Ignored when `refKey` is undefined.
110
+ * @param refKey Precomputed `tool<i>turn<n>` key, or undefined when
111
+ * the output is not to be registered (errors, disabled feature,
112
+ * unavailable batch/turn).
113
+ * @param unresolved Placeholder keys that did not resolve; appended
114
+ * as `[unresolved refs: …]` so the LLM can self-correct.
115
+ *
116
+ * `refKey` is passed in (rather than built from `this.currentTurn`)
117
+ * so parallel `invoke()` calls on the same ToolNode cannot race on
118
+ * the shared turn field.
44
119
  */
45
- protected runTool(call: ToolCall, config: RunnableConfig): Promise<BaseMessage | Command>;
120
+ private applyOutputReference;
46
121
  /**
47
122
  * Builds code session context for injection into event-driven tool calls.
48
123
  * Mirrors the session injection logic in runTool() for direct execution.
@@ -61,16 +136,45 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
61
136
  * By handling completions here in graph context (rather than in the
62
137
  * stream consumer via ToolEndHandler), the race between the stream
63
138
  * consumer and graph execution is eliminated.
139
+ *
140
+ * @param resolvedArgsByCallId Per-batch resolved-args sink populated
141
+ * by `runTool`. Threaded as a local map (instead of instance state)
142
+ * so concurrent batches cannot read each other's entries.
64
143
  */
65
144
  private handleRunToolCompletions;
66
145
  /**
67
146
  * Dispatches tool calls to the host via ON_TOOL_EXECUTE event and returns raw ToolMessages.
68
147
  * Core logic for event-driven execution, separated from output shaping.
148
+ *
149
+ * Hook lifecycle (when `hookRegistry` is set):
150
+ * 1. **PreToolUse** fires per call in parallel before dispatch. Denied
151
+ * calls produce error ToolMessages and fire **PermissionDenied**;
152
+ * surviving calls proceed with optional `updatedInput`.
153
+ * 2. Surviving calls are dispatched to the host via `ON_TOOL_EXECUTE`.
154
+ * 3. **PostToolUse** / **PostToolUseFailure** fire per result. Post hooks
155
+ * can replace tool output via `updatedOutput`.
156
+ * 4. Injected messages from results are collected and returned alongside
157
+ * ToolMessages (appended AFTER to respect provider ordering).
69
158
  */
70
159
  private dispatchToolEvents;
160
+ private dispatchStepCompleted;
161
+ /**
162
+ * Converts InjectedMessage instances to LangChain HumanMessage objects.
163
+ * Both 'user' and 'system' roles become HumanMessage to avoid provider
164
+ * rejections (Anthropic/Google reject non-leading SystemMessages).
165
+ * The original role is preserved in additional_kwargs for downstream consumers.
166
+ */
167
+ private convertInjectedMessages;
71
168
  /**
72
169
  * Execute all tool calls via ON_TOOL_EXECUTE event dispatch.
73
- * Used in event-driven mode where the host handles actual tool execution.
170
+ * Injected messages are placed AFTER ToolMessages to respect provider
171
+ * message ordering (AIMessage tool_calls must be immediately followed
172
+ * by their ToolMessage results).
173
+ *
174
+ * `batchIndices` mirrors `toolCalls` and carries each call's position
175
+ * within the parent batch. `turn` is the per-`run()` batch index
176
+ * captured locally by the caller. Both are threaded so concurrent
177
+ * invocations cannot race on shared mutable state.
74
178
  */
75
179
  private executeViaEvent;
76
180
  protected run(input: any, config: RunnableConfig): Promise<T>;
@@ -78,3 +182,4 @@ export declare class ToolNode<T = any> extends RunnableCallable<T, T> {
78
182
  private isMessagesState;
79
183
  }
80
184
  export declare function toolsCondition<T extends string>(state: BaseMessage[] | typeof MessagesAnnotation.State, toolNode: T, invokedToolIds?: Set<string>): T | typeof END;
185
+ export {};
@@ -211,11 +211,11 @@ declare function formatServerListing(tools: t.ToolMetadata[], serverNames: strin
211
211
  *
212
212
  * @example
213
213
  * // Option 1: Code interpreter mode (regex via sandbox)
214
- * const tool = createToolSearch({ apiKey, toolRegistry });
214
+ * const tool = createToolSearch({ toolRegistry });
215
215
  * await tool.invoke({ query: 'expense.*report' });
216
216
  *
217
217
  * @example
218
- * // Option 2: Local mode (safe substring search, no API key needed)
218
+ * // Option 2: Local mode (safe substring search)
219
219
  * const tool = createToolSearch({ mode: 'local', toolRegistry });
220
220
  * await tool.invoke({ query: 'expense' });
221
221
  */
@@ -0,0 +1,19 @@
1
+ import type { SkillCatalogEntry } from '@/types';
2
+ export type SkillCatalogOptions = {
3
+ /** Total context window in tokens. Default: 200_000 */
4
+ contextWindowTokens?: number;
5
+ /** Fraction of context budget for catalog. Default: 0.01 (1%) */
6
+ budgetPercent?: number;
7
+ /** Max chars per entry description. Default: 250 */
8
+ maxEntryChars?: number;
9
+ /** Descriptions below this length trigger names-only fallback. Default: 20 */
10
+ minDescLength?: number;
11
+ /** Approximate chars per token for budget calculation. Default: 4 */
12
+ charsPerToken?: number;
13
+ };
14
+ /**
15
+ * Formats a skill catalog for injection into agent context.
16
+ * Uses a truncation ladder: full descriptions, proportional truncation, names-only.
17
+ * Returns empty string for empty input.
18
+ */
19
+ export declare function formatSkillCatalog(skills: SkillCatalogEntry[], opts?: SkillCatalogOptions): string;
@@ -0,0 +1,137 @@
1
+ import type { BaseMessage } from '@langchain/core/messages';
2
+ import type { AgentInputs, StandardGraphInput, ResolvedSubagentConfig, SubagentConfig, TokenCounter } from '@/types';
3
+ import type { HookRegistry } from '@/hooks';
4
+ import type { AgentContext } from '@/agents/AgentContext';
5
+ import type { StandardGraph } from '@/graphs/Graph';
6
+ import type { HandlerRegistry } from '@/events';
7
+ export type SubagentExecuteParams = {
8
+ description: string;
9
+ subagentType: string;
10
+ threadId?: string;
11
+ /**
12
+ * Parent-side `tool_call_id` of the `subagent` tool invocation that
13
+ * triggered this execution. Surfaced on {@link SubagentUpdateEvent} so
14
+ * hosts can correlate child updates back to the originating tool call
15
+ * without relying on event ordering heuristics.
16
+ */
17
+ parentToolCallId?: string;
18
+ };
19
+ export type SubagentExecuteResult = {
20
+ content: string;
21
+ messages: BaseMessage[];
22
+ };
23
+ /**
24
+ * Factory that constructs a child graph for subagent execution. Injected
25
+ * rather than imported so that `SubagentExecutor` does not have a runtime
26
+ * dependency on `StandardGraph` — this avoids a circular dependency between
27
+ * `src/graphs/Graph.ts` and `src/tools/subagent/` that would otherwise break
28
+ * Rollup's chunking under `preserveModules`.
29
+ */
30
+ export type ChildGraphFactory = (input: StandardGraphInput) => StandardGraph;
31
+ export type SubagentExecutorOptions = {
32
+ configs: Map<string, ResolvedSubagentConfig>;
33
+ parentSignal?: AbortSignal;
34
+ hookRegistry?: HookRegistry;
35
+ parentRunId: string;
36
+ parentAgentId?: string;
37
+ tokenCounter?: TokenCounter;
38
+ /** Remaining nesting budget. 0 or negative blocks execution. */
39
+ maxDepth?: number;
40
+ /**
41
+ * Factory for constructing the isolated child graph. Callers pass
42
+ * `(input) => new StandardGraph(input)` — injected to break a circular
43
+ * module dependency.
44
+ */
45
+ createChildGraph: ChildGraphFactory;
46
+ /**
47
+ * Parent's event handler registry. When provided, child-graph events are
48
+ * forwarded through this registry so hosts can:
49
+ * (a) execute event-driven tools (`ON_TOOL_EXECUTE` routed to parent's handler),
50
+ * (b) surface child activity to a UI via wrapped {@link GraphEvents.ON_SUBAGENT_UPDATE}.
51
+ * When omitted, the child runs fully isolated (legacy behavior).
52
+ *
53
+ * Can be a direct `HandlerRegistry` or a zero-arg getter — use the getter
54
+ * form when the registry is assigned to the graph AFTER the executor is
55
+ * constructed (the current `Run.create` flow sets `handlerRegistry`
56
+ * post-`createWorkflow`, so `createAgentNode` must capture lazily).
57
+ */
58
+ parentHandlerRegistry?: HandlerRegistry | (() => HandlerRegistry | undefined);
59
+ };
60
+ export declare class SubagentExecutor {
61
+ private readonly configs;
62
+ private readonly parentSignal?;
63
+ private readonly hookRegistry?;
64
+ private readonly parentRunId;
65
+ private readonly parentAgentId?;
66
+ private readonly tokenCounter?;
67
+ private readonly maxDepth;
68
+ private readonly createChildGraph;
69
+ private readonly resolveParentHandlerRegistry?;
70
+ constructor(options: SubagentExecutorOptions);
71
+ /** Snapshot of the parent's registry at the moment a subagent is dispatched. */
72
+ private getParentHandlerRegistry;
73
+ execute(params: SubagentExecuteParams): Promise<SubagentExecuteResult>;
74
+ /**
75
+ * Emits a single {@link GraphEvents.ON_SUBAGENT_UPDATE} envelope through the
76
+ * parent's handler registry. Silent no-op when no parent registry is set.
77
+ * Errors are swallowed — update events are observational.
78
+ */
79
+ private emitSubagentUpdate;
80
+ /**
81
+ * Builds a BaseCallbackHandler that intercepts the child graph's custom
82
+ * events. Routing rules:
83
+ * - `ON_TOOL_EXECUTE` → forwarded as-is to the parent's ON_TOOL_EXECUTE
84
+ * handler (so event-driven tools work identically for child and parent).
85
+ * - `ON_RUN_STEP` / `ON_RUN_STEP_DELTA` / `ON_RUN_STEP_COMPLETED` /
86
+ * `ON_MESSAGE_DELTA` / `ON_REASONING_DELTA` → wrapped in a
87
+ * {@link GraphEvents.ON_SUBAGENT_UPDATE} envelope with a human-readable
88
+ * label, delivered to the parent's subagent-update handler.
89
+ * - Everything else → ignored (keeps parent's UI scoped to the events it
90
+ * cares about; host apps can extend by registering more phases).
91
+ */
92
+ private createForwarderCallback;
93
+ }
94
+ /**
95
+ * Produces a short single-line label for an arbitrary forwarded child event.
96
+ * Used to populate {@link SubagentUpdateEvent.label} so the host UI can show
97
+ * a compact status ticker without parsing the raw payload.
98
+ */
99
+ export declare function summarizeEvent(eventName: string, data: unknown): string;
100
+ /**
101
+ * Walk messages from last to first, returning the text content of the most
102
+ * recent AIMessage that has any. Non-text blocks (tool_use, thinking,
103
+ * redacted_thinking, tool_result) are stripped. If the last AIMessage is
104
+ * pure tool_use (e.g. the subagent hit `maxTurns` mid-tool-call), the walk
105
+ * continues to earlier AIMessages so partial progress is salvaged — this
106
+ * matches Claude Code's behavior in `agentToolUtils.finalizeAgentTool`.
107
+ * Returns "Task completed" only when no AIMessage in the history contains
108
+ * any text.
109
+ */
110
+ export declare function filterSubagentResult(messages: BaseMessage[]): string;
111
+ /**
112
+ * Resolve self-spawn configs by filling in agentInputs from the parent context.
113
+ * Returns configs with agentInputs guaranteed present. Throws on duplicate
114
+ * `type` values to prevent silent config shadowing.
115
+ */
116
+ export declare function resolveSubagentConfigs(configs: SubagentConfig[], parentContext: AgentContext): ResolvedSubagentConfig[];
117
+ /**
118
+ * Build child AgentInputs from a resolved config, stripping nesting and
119
+ * (optionally) event-driven fields. When `allowNested: true`, the child's
120
+ * `maxSubagentDepth` is decremented so that depth is consumed as the call
121
+ * chain deepens across graph boundaries — the parent's executor-level check
122
+ * alone cannot see into the child graph's separate executor.
123
+ *
124
+ * When `keepToolDefinitions` is `true`, the child retains the parent's
125
+ * `toolDefinitions` so event-driven tools remain usable. This is only safe
126
+ * when the caller has wired a forwarder for `ON_TOOL_EXECUTE` to a
127
+ * registered handler — otherwise the child will hang on tool dispatch.
128
+ *
129
+ * @remarks Advanced utility: exported primarily for testing and by
130
+ * {@link SubagentExecutor}. Host applications configuring subagents should
131
+ * not need to call this directly — it is invoked internally when a subagent
132
+ * tool is dispatched. The depth-countdown contract (parent's `maxDepth` in,
133
+ * child's decremented `maxSubagentDepth` on the returned inputs) is the
134
+ * mechanism that bounds nesting across graph boundaries; callers must
135
+ * respect it.
136
+ */
137
+ export declare function buildChildInputs(config: ResolvedSubagentConfig, childAgentId: string, parentMaxDepth: number, keepToolDefinitions?: boolean): AgentInputs;
@@ -0,0 +1,2 @@
1
+ export { SubagentExecutor, filterSubagentResult, resolveSubagentConfigs, buildChildInputs, summarizeEvent, } from './SubagentExecutor';
2
+ export type { SubagentExecuteParams, SubagentExecuteResult, SubagentExecutorOptions, ChildGraphFactory, } from './SubagentExecutor';