@illuma-ai/agents 1.4.0-alpha.6 → 1.5.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 (800) hide show
  1. package/README.md +62 -0
  2. package/dist/cjs/agents/AgentContext.cjs +274 -67
  3. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  4. package/dist/cjs/common/enum.cjs +44 -13
  5. package/dist/cjs/common/enum.cjs.map +1 -1
  6. package/dist/cjs/graphs/Graph.cjs +182 -5
  7. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  8. package/dist/cjs/graphs/MultiAgentGraph.cjs +152 -1167
  9. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
  10. package/dist/cjs/hooks/HookRegistry.cjs +162 -0
  11. package/dist/cjs/hooks/HookRegistry.cjs.map +1 -0
  12. package/dist/cjs/hooks/executeHooks.cjs +276 -0
  13. package/dist/cjs/hooks/executeHooks.cjs.map +1 -0
  14. package/dist/cjs/hooks/matchers.cjs +256 -0
  15. package/dist/cjs/hooks/matchers.cjs.map +1 -0
  16. package/dist/cjs/hooks/types.cjs +27 -0
  17. package/dist/cjs/hooks/types.cjs.map +1 -0
  18. package/dist/cjs/langchain/google-common.cjs +3 -0
  19. package/dist/cjs/langchain/google-common.cjs.map +1 -0
  20. package/dist/cjs/langchain/index.cjs +86 -0
  21. package/dist/cjs/langchain/index.cjs.map +1 -0
  22. package/dist/cjs/langchain/language_models/chat_models.cjs +3 -0
  23. package/dist/cjs/langchain/language_models/chat_models.cjs.map +1 -0
  24. package/dist/cjs/langchain/messages/tool.cjs +3 -0
  25. package/dist/cjs/langchain/messages/tool.cjs.map +1 -0
  26. package/dist/cjs/langchain/messages.cjs +51 -0
  27. package/dist/cjs/langchain/messages.cjs.map +1 -0
  28. package/dist/cjs/langchain/openai.cjs +3 -0
  29. package/dist/cjs/langchain/openai.cjs.map +1 -0
  30. package/dist/cjs/langchain/prompts.cjs +11 -0
  31. package/dist/cjs/langchain/prompts.cjs.map +1 -0
  32. package/dist/cjs/langchain/runnables.cjs +19 -0
  33. package/dist/cjs/langchain/runnables.cjs.map +1 -0
  34. package/dist/cjs/langchain/tools.cjs +23 -0
  35. package/dist/cjs/langchain/tools.cjs.map +1 -0
  36. package/dist/cjs/langchain/utils/env.cjs +11 -0
  37. package/dist/cjs/langchain/utils/env.cjs.map +1 -0
  38. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +5 -1
  39. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
  40. package/dist/cjs/llm/bedrock/cacheSupport.cjs +55 -0
  41. package/dist/cjs/llm/bedrock/cacheSupport.cjs.map +1 -0
  42. package/dist/cjs/llm/bedrock/index.cjs +61 -33
  43. package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
  44. package/dist/cjs/llm/openai/index.cjs +0 -3
  45. package/dist/cjs/llm/openai/index.cjs.map +1 -1
  46. package/dist/cjs/llm/openai/utils/index.cjs +27 -10
  47. package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
  48. package/dist/cjs/main.cjs +178 -127
  49. package/dist/cjs/main.cjs.map +1 -1
  50. package/dist/cjs/messages/cache.cjs +89 -0
  51. package/dist/cjs/messages/cache.cjs.map +1 -1
  52. package/dist/cjs/messages/contextPruning.cjs +156 -0
  53. package/dist/cjs/messages/contextPruning.cjs.map +1 -0
  54. package/dist/cjs/messages/contextPruningSettings.cjs +53 -0
  55. package/dist/cjs/messages/contextPruningSettings.cjs.map +1 -0
  56. package/dist/cjs/messages/format.cjs +144 -20
  57. package/dist/cjs/messages/format.cjs.map +1 -1
  58. package/dist/cjs/messages/prune.cjs +505 -4
  59. package/dist/cjs/messages/prune.cjs.map +1 -1
  60. package/dist/cjs/run.cjs +141 -1
  61. package/dist/cjs/run.cjs.map +1 -1
  62. package/dist/cjs/tools/BashExecutor.cjs +235 -0
  63. package/dist/cjs/tools/BashExecutor.cjs.map +1 -0
  64. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +297 -0
  65. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -0
  66. package/dist/cjs/tools/CodeExecutor.cjs +44 -47
  67. package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
  68. package/dist/cjs/tools/ProgrammaticToolCalling.cjs +16 -11
  69. package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
  70. package/dist/cjs/tools/ReadFile.cjs +44 -0
  71. package/dist/cjs/tools/ReadFile.cjs.map +1 -0
  72. package/dist/cjs/tools/SkillTool.cjs +51 -0
  73. package/dist/cjs/tools/SkillTool.cjs.map +1 -0
  74. package/dist/cjs/tools/SubagentTool.cjs +93 -0
  75. package/dist/cjs/tools/SubagentTool.cjs.map +1 -0
  76. package/dist/cjs/tools/ToolNode.cjs +450 -24
  77. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  78. package/dist/cjs/tools/search/search.cjs +11 -3
  79. package/dist/cjs/tools/search/search.cjs.map +1 -1
  80. package/dist/cjs/tools/search/tavily-scraper.cjs +189 -0
  81. package/dist/cjs/tools/search/tavily-scraper.cjs.map +1 -0
  82. package/dist/cjs/tools/search/tavily-search.cjs +372 -0
  83. package/dist/cjs/tools/search/tavily-search.cjs.map +1 -0
  84. package/dist/cjs/tools/search/tool.cjs +28 -4
  85. package/dist/cjs/tools/search/tool.cjs.map +1 -1
  86. package/dist/cjs/tools/search/utils.cjs +10 -3
  87. package/dist/cjs/tools/search/utils.cjs.map +1 -1
  88. package/dist/cjs/tools/skillCatalog.cjs +84 -0
  89. package/dist/cjs/tools/skillCatalog.cjs.map +1 -0
  90. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +512 -0
  91. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -0
  92. package/dist/cjs/tools/toolOutputReferences.cjs +670 -0
  93. package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -0
  94. package/dist/cjs/types/agent-cache.cjs +53 -0
  95. package/dist/cjs/types/agent-cache.cjs.map +1 -0
  96. package/dist/cjs/types/graph.cjs.map +1 -1
  97. package/dist/cjs/utils/truncation.cjs +135 -0
  98. package/dist/cjs/utils/truncation.cjs.map +1 -0
  99. package/dist/esm/agents/AgentContext.mjs +274 -67
  100. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  101. package/dist/esm/common/enum.mjs +44 -12
  102. package/dist/esm/common/enum.mjs.map +1 -1
  103. package/dist/esm/graphs/Graph.mjs +182 -5
  104. package/dist/esm/graphs/Graph.mjs.map +1 -1
  105. package/dist/esm/graphs/MultiAgentGraph.mjs +155 -1170
  106. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  107. package/dist/esm/hooks/HookRegistry.mjs +160 -0
  108. package/dist/esm/hooks/HookRegistry.mjs.map +1 -0
  109. package/dist/esm/hooks/executeHooks.mjs +273 -0
  110. package/dist/esm/hooks/executeHooks.mjs.map +1 -0
  111. package/dist/esm/hooks/matchers.mjs +251 -0
  112. package/dist/esm/hooks/matchers.mjs.map +1 -0
  113. package/dist/esm/hooks/types.mjs +25 -0
  114. package/dist/esm/hooks/types.mjs.map +1 -0
  115. package/dist/esm/langchain/google-common.mjs +2 -0
  116. package/dist/esm/langchain/google-common.mjs.map +1 -0
  117. package/dist/esm/langchain/index.mjs +5 -0
  118. package/dist/esm/langchain/language_models/chat_models.mjs +2 -0
  119. package/dist/esm/langchain/language_models/chat_models.mjs.map +1 -0
  120. package/dist/esm/langchain/messages/tool.mjs +2 -0
  121. package/dist/esm/langchain/messages/tool.mjs.map +1 -0
  122. package/dist/esm/langchain/messages.mjs +2 -0
  123. package/dist/esm/langchain/messages.mjs.map +1 -0
  124. package/dist/esm/langchain/openai.mjs +2 -0
  125. package/dist/esm/langchain/openai.mjs.map +1 -0
  126. package/dist/esm/langchain/prompts.mjs +2 -0
  127. package/dist/esm/langchain/prompts.mjs.map +1 -0
  128. package/dist/esm/langchain/runnables.mjs +2 -0
  129. package/dist/esm/langchain/runnables.mjs.map +1 -0
  130. package/dist/esm/langchain/tools.mjs +2 -0
  131. package/dist/esm/langchain/tools.mjs.map +1 -0
  132. package/dist/esm/langchain/utils/env.mjs +2 -0
  133. package/dist/esm/langchain/utils/env.mjs.map +1 -0
  134. package/dist/esm/llm/anthropic/utils/message_inputs.mjs +5 -1
  135. package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
  136. package/dist/esm/llm/bedrock/cacheSupport.mjs +52 -0
  137. package/dist/esm/llm/bedrock/cacheSupport.mjs.map +1 -0
  138. package/dist/esm/llm/bedrock/index.mjs +61 -34
  139. package/dist/esm/llm/bedrock/index.mjs.map +1 -1
  140. package/dist/esm/llm/openai/index.mjs +0 -3
  141. package/dist/esm/llm/openai/index.mjs.map +1 -1
  142. package/dist/esm/llm/openai/utils/index.mjs +27 -10
  143. package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
  144. package/dist/esm/main.mjs +21 -27
  145. package/dist/esm/main.mjs.map +1 -1
  146. package/dist/esm/messages/cache.mjs +89 -0
  147. package/dist/esm/messages/cache.mjs.map +1 -1
  148. package/dist/esm/messages/contextPruning.mjs +154 -0
  149. package/dist/esm/messages/contextPruning.mjs.map +1 -0
  150. package/dist/esm/messages/contextPruningSettings.mjs +50 -0
  151. package/dist/esm/messages/contextPruningSettings.mjs.map +1 -0
  152. package/dist/esm/messages/format.mjs +136 -12
  153. package/dist/esm/messages/format.mjs.map +1 -1
  154. package/dist/esm/messages/prune.mjs +504 -7
  155. package/dist/esm/messages/prune.mjs.map +1 -1
  156. package/dist/esm/run.mjs +141 -1
  157. package/dist/esm/run.mjs.map +1 -1
  158. package/dist/esm/tools/BashExecutor.mjs +227 -0
  159. package/dist/esm/tools/BashExecutor.mjs.map +1 -0
  160. package/dist/esm/tools/BashProgrammaticToolCalling.mjs +288 -0
  161. package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -0
  162. package/dist/esm/tools/CodeExecutor.mjs +44 -48
  163. package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
  164. package/dist/esm/tools/ProgrammaticToolCalling.mjs +17 -12
  165. package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
  166. package/dist/esm/tools/ReadFile.mjs +39 -0
  167. package/dist/esm/tools/ReadFile.mjs.map +1 -0
  168. package/dist/esm/tools/SkillTool.mjs +46 -0
  169. package/dist/esm/tools/SkillTool.mjs.map +1 -0
  170. package/dist/esm/tools/SubagentTool.mjs +86 -0
  171. package/dist/esm/tools/SubagentTool.mjs.map +1 -0
  172. package/dist/esm/tools/ToolNode.mjs +452 -26
  173. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  174. package/dist/esm/tools/search/search.mjs +11 -3
  175. package/dist/esm/tools/search/search.mjs.map +1 -1
  176. package/dist/esm/tools/search/tavily-scraper.mjs +186 -0
  177. package/dist/esm/tools/search/tavily-scraper.mjs.map +1 -0
  178. package/dist/esm/tools/search/tavily-search.mjs +370 -0
  179. package/dist/esm/tools/search/tavily-search.mjs.map +1 -0
  180. package/dist/esm/tools/search/tool.mjs +28 -4
  181. package/dist/esm/tools/search/tool.mjs.map +1 -1
  182. package/dist/esm/tools/search/utils.mjs +10 -3
  183. package/dist/esm/tools/search/utils.mjs.map +1 -1
  184. package/dist/esm/tools/skillCatalog.mjs +82 -0
  185. package/dist/esm/tools/skillCatalog.mjs.map +1 -0
  186. package/dist/esm/tools/subagent/SubagentExecutor.mjs +506 -0
  187. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -0
  188. package/dist/esm/tools/toolOutputReferences.mjs +662 -0
  189. package/dist/esm/tools/toolOutputReferences.mjs.map +1 -0
  190. package/dist/esm/types/agent-cache.mjs +51 -0
  191. package/dist/esm/types/agent-cache.mjs.map +1 -0
  192. package/dist/esm/types/graph.mjs.map +1 -1
  193. package/dist/esm/utils/truncation.mjs +128 -0
  194. package/dist/esm/utils/truncation.mjs.map +1 -0
  195. package/dist/types/agents/AgentContext.d.ts +101 -8
  196. package/dist/types/common/enum.d.ts +39 -12
  197. package/dist/types/common/index.d.ts +0 -1
  198. package/dist/types/graphs/Graph.d.ts +43 -0
  199. package/dist/types/graphs/MultiAgentGraph.d.ts +26 -150
  200. package/dist/types/graphs/index.d.ts +0 -1
  201. package/dist/types/hooks/HookRegistry.d.ts +56 -0
  202. package/dist/types/hooks/executeHooks.d.ts +79 -0
  203. package/dist/types/hooks/index.d.ts +6 -0
  204. package/dist/types/hooks/matchers.d.ts +95 -0
  205. package/dist/types/hooks/types.d.ts +320 -0
  206. package/dist/types/index.d.ts +9 -9
  207. package/dist/types/langchain/google-common.d.ts +1 -0
  208. package/dist/types/langchain/index.d.ts +8 -0
  209. package/dist/types/langchain/language_models/chat_models.d.ts +1 -0
  210. package/dist/types/langchain/messages/tool.d.ts +1 -0
  211. package/dist/types/langchain/messages.d.ts +2 -0
  212. package/dist/types/langchain/openai.d.ts +1 -0
  213. package/dist/types/langchain/prompts.d.ts +1 -0
  214. package/dist/types/langchain/runnables.d.ts +2 -0
  215. package/dist/types/langchain/tools.d.ts +2 -0
  216. package/dist/types/langchain/utils/env.d.ts +1 -0
  217. package/dist/types/llm/bedrock/cacheSupport.d.ts +35 -0
  218. package/dist/types/llm/bedrock/index.d.ts +54 -1
  219. package/dist/types/messages/contextPruning.d.ts +42 -0
  220. package/dist/types/messages/contextPruningSettings.d.ts +44 -0
  221. package/dist/types/messages/format.d.ts +9 -1
  222. package/dist/types/messages/index.d.ts +2 -0
  223. package/dist/types/messages/prune.d.ts +91 -1
  224. package/dist/types/run.d.ts +2 -0
  225. package/dist/types/tools/BashExecutor.d.ts +76 -0
  226. package/dist/types/tools/BashProgrammaticToolCalling.d.ts +72 -0
  227. package/dist/types/tools/CodeExecutor.d.ts +8 -26
  228. package/dist/types/tools/ReadFile.d.ts +28 -0
  229. package/dist/types/tools/SkillTool.d.ts +40 -0
  230. package/dist/types/tools/SubagentTool.d.ts +36 -0
  231. package/dist/types/tools/ToolNode.d.ts +77 -5
  232. package/dist/types/tools/search/tavily-scraper.d.ts +19 -0
  233. package/dist/types/tools/search/tavily-search.d.ts +4 -0
  234. package/dist/types/tools/search/types.d.ts +99 -5
  235. package/dist/types/tools/search/utils.d.ts +2 -2
  236. package/dist/types/tools/skillCatalog.d.ts +19 -0
  237. package/dist/types/tools/subagent/SubagentExecutor.d.ts +137 -0
  238. package/dist/types/tools/subagent/index.d.ts +2 -0
  239. package/dist/types/tools/subagent/types.d.ts +84 -0
  240. package/dist/types/tools/toolOutputReferences.d.ts +236 -0
  241. package/dist/types/types/agent-cache.d.ts +70 -0
  242. package/dist/types/types/graph.d.ts +162 -22
  243. package/dist/types/types/index.d.ts +3 -0
  244. package/dist/types/types/messages.d.ts +26 -0
  245. package/dist/types/types/run.d.ts +22 -0
  246. package/dist/types/types/skill.d.ts +9 -0
  247. package/dist/types/types/tools.d.ts +111 -0
  248. package/dist/types/utils/index.d.ts +1 -3
  249. package/dist/types/utils/truncation.d.ts +70 -0
  250. package/package.json +57 -17
  251. package/src/agents/AgentContext.js.map +1 -0
  252. package/src/agents/AgentContext.test.js.map +1 -0
  253. package/src/agents/AgentContext.ts +321 -78
  254. package/src/agents/__tests__/AgentContext.cacheTtl.live.test.ts +259 -0
  255. package/src/agents/__tests__/AgentContext.crossAgentTier1.live.test.ts +264 -0
  256. package/src/agents/__tests__/AgentContext.crossUserCache.live.test.ts +342 -0
  257. package/src/agents/__tests__/AgentContext.test.js.map +1 -0
  258. package/src/agents/__tests__/AgentContext.test.ts +632 -0
  259. package/src/agents/__tests__/resolveStructuredOutputMode.test.js.map +1 -0
  260. package/src/common/__tests__/enum.test.ts +7 -17
  261. package/src/common/enum.js.map +1 -0
  262. package/src/common/enum.ts +43 -12
  263. package/src/common/index.js.map +1 -0
  264. package/src/common/index.ts +0 -1
  265. package/src/events.js.map +1 -0
  266. package/src/graphs/Graph.js.map +1 -0
  267. package/src/graphs/Graph.ts +222 -2
  268. package/src/graphs/MultiAgentGraph.js.map +1 -0
  269. package/src/graphs/MultiAgentGraph.ts +154 -1466
  270. package/src/graphs/__tests__/MultiAgentGraph.test.ts +91 -0
  271. package/src/graphs/__tests__/structured-output.integration.test.js.map +1 -0
  272. package/src/graphs/__tests__/structured-output.test.js.map +1 -0
  273. package/src/graphs/contextManagement.e2e.test.js.map +1 -0
  274. package/src/graphs/contextManagement.test.js.map +1 -0
  275. package/src/graphs/handoffValidation.test.js.map +1 -0
  276. package/src/graphs/index.js.map +1 -0
  277. package/src/graphs/index.ts +0 -1
  278. package/src/hooks/HookRegistry.ts +208 -0
  279. package/src/hooks/__tests__/HookRegistry.test.ts +190 -0
  280. package/src/hooks/__tests__/compactHooks.test.ts +214 -0
  281. package/src/hooks/__tests__/executeHooks.test.ts +1013 -0
  282. package/src/hooks/__tests__/integration.test.ts +337 -0
  283. package/src/hooks/__tests__/matchers.test.ts +238 -0
  284. package/src/hooks/__tests__/toolHooks.test.ts +665 -0
  285. package/src/hooks/executeHooks.ts +375 -0
  286. package/src/hooks/index.ts +57 -0
  287. package/src/hooks/matchers.ts +280 -0
  288. package/src/hooks/types.ts +404 -0
  289. package/src/index.js.map +1 -0
  290. package/src/index.ts +15 -24
  291. package/src/instrumentation.js.map +1 -0
  292. package/src/langchain/google-common.ts +1 -0
  293. package/src/langchain/index.ts +8 -0
  294. package/src/langchain/language_models/chat_models.ts +1 -0
  295. package/src/langchain/messages/tool.ts +5 -0
  296. package/src/langchain/messages.ts +21 -0
  297. package/src/langchain/openai.ts +1 -0
  298. package/src/langchain/prompts.ts +1 -0
  299. package/src/langchain/runnables.ts +7 -0
  300. package/src/langchain/tools.ts +8 -0
  301. package/src/langchain/utils/env.ts +1 -0
  302. package/src/llm/anthropic/index.js.map +1 -0
  303. package/src/llm/anthropic/types.js.map +1 -0
  304. package/src/llm/anthropic/utils/message_inputs.js.map +1 -0
  305. package/src/llm/anthropic/utils/message_inputs.ts +10 -1
  306. package/src/llm/anthropic/utils/message_outputs.js.map +1 -0
  307. package/src/llm/anthropic/utils/output_parsers.js.map +1 -0
  308. package/src/llm/anthropic/utils/server-tool-inputs.test.ts +436 -0
  309. package/src/llm/anthropic/utils/tools.js.map +1 -0
  310. package/src/llm/bedrock/__tests__/bedrock-caching.test.js.map +1 -0
  311. package/src/llm/bedrock/__tests__/bedrock-caching.test.ts +166 -18
  312. package/src/llm/bedrock/cacheSupport.test.ts +99 -0
  313. package/src/llm/bedrock/cacheSupport.ts +53 -0
  314. package/src/llm/bedrock/index.js.map +1 -0
  315. package/src/llm/bedrock/index.ts +116 -41
  316. package/src/llm/bedrock/types.js.map +1 -0
  317. package/src/llm/bedrock/utils/index.js.map +1 -0
  318. package/src/llm/bedrock/utils/message_inputs.js.map +1 -0
  319. package/src/llm/bedrock/utils/message_outputs.js.map +1 -0
  320. package/src/llm/fake.js.map +1 -0
  321. package/src/llm/google/index.js.map +1 -0
  322. package/src/llm/google/types.js.map +1 -0
  323. package/src/llm/google/utils/common.js.map +1 -0
  324. package/src/llm/google/utils/tools.js.map +1 -0
  325. package/src/llm/google/utils/zod_to_genai_parameters.js.map +1 -0
  326. package/src/llm/openai/index.js.map +1 -0
  327. package/src/llm/openai/types.js.map +1 -0
  328. package/src/llm/openai/utils/index.js.map +1 -0
  329. package/src/llm/openai/utils/index.ts +31 -14
  330. package/src/llm/openai/utils/isReasoningModel.test.js.map +1 -0
  331. package/src/llm/openrouter/index.js.map +1 -0
  332. package/src/llm/openrouter/reasoning.test.js.map +1 -0
  333. package/src/llm/providers.js.map +1 -0
  334. package/src/llm/text.js.map +1 -0
  335. package/src/llm/vertexai/index.js.map +1 -0
  336. package/src/messages/__tests__/contextPruning.test.ts +228 -0
  337. package/src/messages/__tests__/tools.test.js.map +1 -0
  338. package/src/messages/cache.js.map +1 -0
  339. package/src/messages/cache.test.js.map +1 -0
  340. package/src/messages/cache.test.ts +62 -24
  341. package/src/messages/cache.ts +112 -0
  342. package/src/messages/content.js.map +1 -0
  343. package/src/messages/content.test.js.map +1 -0
  344. package/src/messages/contextPruning.ts +191 -0
  345. package/src/messages/contextPruningSettings.ts +90 -0
  346. package/src/messages/core.js.map +1 -0
  347. package/src/messages/ensureThinkingBlock.test.js.map +1 -0
  348. package/src/messages/format.js.map +1 -0
  349. package/src/messages/format.ts +164 -12
  350. package/src/messages/formatAgentMessages.skills.test.ts +413 -0
  351. package/src/messages/formatAgentMessages.test.js.map +1 -0
  352. package/src/messages/formatAgentMessages.tools.test.js.map +1 -0
  353. package/src/messages/formatMessage.test.js.map +1 -0
  354. package/src/messages/ids.js.map +1 -0
  355. package/src/messages/index.js.map +1 -0
  356. package/src/messages/index.ts +2 -0
  357. package/src/messages/labelContentByAgent.test.js.map +1 -0
  358. package/src/messages/prune.js.map +1 -0
  359. package/src/messages/prune.ts +661 -4
  360. package/src/messages/reducer.js.map +1 -0
  361. package/src/messages/shiftIndexTokenCountMap.test.js.map +1 -0
  362. package/src/messages/summarize.js.map +1 -0
  363. package/src/messages/summarize.test.js.map +1 -0
  364. package/src/messages/tools.js.map +1 -0
  365. package/src/mockStream.js.map +1 -0
  366. package/src/prompts/collab.js.map +1 -0
  367. package/src/prompts/index.js.map +1 -0
  368. package/src/prompts/taskmanager.js.map +1 -0
  369. package/src/run.js.map +1 -0
  370. package/src/run.ts +155 -1
  371. package/src/schemas/index.js.map +1 -0
  372. package/src/schemas/schema-preparation.test.js.map +1 -0
  373. package/src/schemas/validate.js.map +1 -0
  374. package/src/schemas/validate.test.js.map +1 -0
  375. package/src/scripts/abort.js.map +1 -0
  376. package/src/scripts/ant_web_search.js.map +1 -0
  377. package/src/scripts/ant_web_search_edge_case.js.map +1 -0
  378. package/src/scripts/ant_web_search_error_edge_case.js.map +1 -0
  379. package/src/scripts/args.js.map +1 -0
  380. package/src/scripts/bedrock-cache-debug.js.map +1 -0
  381. package/src/scripts/bedrock-content-aggregation-test.js.map +1 -0
  382. package/src/scripts/bedrock-merge-test.js.map +1 -0
  383. package/src/scripts/bedrock-parallel-tools-test.js.map +1 -0
  384. package/src/scripts/caching.js.map +1 -0
  385. package/src/scripts/cli.js.map +1 -0
  386. package/src/scripts/cli2.js.map +1 -0
  387. package/src/scripts/cli3.js.map +1 -0
  388. package/src/scripts/cli4.js.map +1 -0
  389. package/src/scripts/cli5.js.map +1 -0
  390. package/src/scripts/code_exec.js.map +1 -0
  391. package/src/scripts/code_exec_files.js.map +1 -0
  392. package/src/scripts/code_exec_multi_session.js.map +1 -0
  393. package/src/scripts/code_exec_ptc.js.map +1 -0
  394. package/src/scripts/code_exec_session.js.map +1 -0
  395. package/src/scripts/code_exec_simple.js.map +1 -0
  396. package/src/scripts/content.js.map +1 -0
  397. package/src/scripts/empty_input.js.map +1 -0
  398. package/src/scripts/handoff-test.js.map +1 -0
  399. package/src/scripts/image.js.map +1 -0
  400. package/src/scripts/memory.js.map +1 -0
  401. package/src/scripts/multi-agent-chain.js.map +1 -0
  402. package/src/scripts/multi-agent-chain.ts +2 -2
  403. package/src/scripts/multi-agent-conditional.js.map +1 -0
  404. package/src/scripts/multi-agent-document-review-chain.js.map +1 -0
  405. package/src/scripts/multi-agent-document-review-chain.ts +2 -2
  406. package/src/scripts/multi-agent-hybrid-flow.js.map +1 -0
  407. package/src/scripts/multi-agent-hybrid-flow.ts +4 -4
  408. package/src/scripts/multi-agent-parallel-start.js.map +1 -0
  409. package/src/scripts/multi-agent-parallel.js.map +1 -0
  410. package/src/scripts/multi-agent-parallel.ts +3 -3
  411. package/src/scripts/multi-agent-sequence.js.map +1 -0
  412. package/src/scripts/multi-agent-sequence.ts +3 -3
  413. package/src/scripts/multi-agent-subagent.ts +246 -0
  414. package/src/scripts/multi-agent-supervisor.js.map +1 -0
  415. package/src/scripts/multi-agent-supervisor.ts +5 -5
  416. package/src/scripts/multi-agent-test.js.map +1 -0
  417. package/src/scripts/parallel-asymmetric-tools-test.js.map +1 -0
  418. package/src/scripts/parallel-full-metadata-test.js.map +1 -0
  419. package/src/scripts/parallel-tools-test.js.map +1 -0
  420. package/src/scripts/poc-multi-agent-comprehensive.ts +8 -8
  421. package/src/scripts/programmatic_exec.js.map +1 -0
  422. package/src/scripts/programmatic_exec_agent.js.map +1 -0
  423. package/src/scripts/search.js.map +1 -0
  424. package/src/scripts/sequential-full-metadata-test.js.map +1 -0
  425. package/src/scripts/sequential-full-metadata-test.ts +2 -2
  426. package/src/scripts/simple.js.map +1 -0
  427. package/src/scripts/single-agent-metadata-test.js.map +1 -0
  428. package/src/scripts/stream.js.map +1 -0
  429. package/src/scripts/subagent-event-driven-debug.ts +190 -0
  430. package/src/scripts/subagent-tools-debug.ts +160 -0
  431. package/src/scripts/test-custom-prompt-key.js.map +1 -0
  432. package/src/scripts/test-custom-prompt-key.ts +3 -3
  433. package/src/scripts/test-handoff-input.js.map +1 -0
  434. package/src/scripts/test-handoff-input.ts +1 -1
  435. package/src/scripts/test-handoff-preamble.js.map +1 -0
  436. package/src/scripts/test-handoff-steering.js.map +1 -0
  437. package/src/scripts/test-handoff-steering.ts +3 -3
  438. package/src/scripts/test-multi-agent-list-handoff.js.map +1 -0
  439. package/src/scripts/test-multi-agent-list-handoff.ts +1 -1
  440. package/src/scripts/test-parallel-agent-labeling.js.map +1 -0
  441. package/src/scripts/test-parallel-agent-labeling.ts +3 -3
  442. package/src/scripts/test-parallel-handoffs.js.map +1 -0
  443. package/src/scripts/test-parallel-handoffs.ts +2 -2
  444. package/src/scripts/test-thinking-handoff-bedrock.js.map +1 -0
  445. package/src/scripts/test-thinking-handoff-bedrock.ts +1 -1
  446. package/src/scripts/test-thinking-handoff.js.map +1 -0
  447. package/src/scripts/test-thinking-handoff.ts +1 -1
  448. package/src/scripts/test-thinking-to-thinking-handoff-bedrock.js.map +1 -0
  449. package/src/scripts/test-thinking-to-thinking-handoff-bedrock.ts +1 -1
  450. package/src/scripts/test-tool-before-handoff-role-order.js.map +1 -0
  451. package/src/scripts/test-tool-before-handoff-role-order.ts +1 -1
  452. package/src/scripts/test-tools-before-handoff.js.map +1 -0
  453. package/src/scripts/test-tools-before-handoff.ts +1 -1
  454. package/src/scripts/test_code_api.js.map +1 -0
  455. package/src/scripts/thinking-bedrock.js.map +1 -0
  456. package/src/scripts/thinking-vertexai.js.map +1 -0
  457. package/src/scripts/thinking.js.map +1 -0
  458. package/src/scripts/tool_search.js.map +1 -0
  459. package/src/scripts/tools.js.map +1 -0
  460. package/src/specs/agent-handoffs-bedrock.integration.test.js.map +1 -0
  461. package/src/specs/agent-handoffs.test.js.map +1 -0
  462. package/src/specs/agent-handoffs.test.ts +26 -483
  463. package/src/specs/anthropic.simple.test.js.map +1 -0
  464. package/src/specs/anthropic.simple.test.ts +61 -0
  465. package/src/specs/azure.simple.test.js.map +1 -0
  466. package/src/specs/cache.simple.test.js.map +1 -0
  467. package/src/specs/custom-event-await.test.js.map +1 -0
  468. package/src/specs/deepseek.simple.test.js.map +1 -0
  469. package/src/specs/emergency-prune.test.js.map +1 -0
  470. package/src/specs/moonshot.simple.test.js.map +1 -0
  471. package/src/specs/multi-agent-summarization.test.ts +396 -0
  472. package/src/specs/observability.integration.test.js.map +1 -0
  473. package/src/specs/openai.simple.test.js.map +1 -0
  474. package/src/specs/openrouter.simple.test.js.map +1 -0
  475. package/src/specs/prune.orphans.test.ts +248 -0
  476. package/src/specs/prune.test.js.map +1 -0
  477. package/src/specs/prune.test.ts +104 -16
  478. package/src/specs/reasoning.test.js.map +1 -0
  479. package/src/specs/spec.utils.js.map +1 -0
  480. package/src/specs/thinking-handoff.test.js.map +1 -0
  481. package/src/specs/thinking-handoff.test.ts +19 -19
  482. package/src/specs/thinking-prune.test.js.map +1 -0
  483. package/src/specs/token-distribution-edge-case.test.js.map +1 -0
  484. package/src/specs/token-memoization.test.js.map +1 -0
  485. package/src/specs/tokens.test.js.map +1 -0
  486. package/src/specs/tool-error.test.js.map +1 -0
  487. package/src/splitStream.js.map +1 -0
  488. package/src/splitStream.test.js.map +1 -0
  489. package/src/stream.js.map +1 -0
  490. package/src/stream.test.js.map +1 -0
  491. package/src/test/mockTools.js.map +1 -0
  492. package/src/tools/BashExecutor.ts +281 -0
  493. package/src/tools/BashProgrammaticToolCalling.ts +397 -0
  494. package/src/tools/BrowserTools.js.map +1 -0
  495. package/src/tools/Calculator.js.map +1 -0
  496. package/src/tools/Calculator.test.js.map +1 -0
  497. package/src/tools/CodeExecutor.js.map +1 -0
  498. package/src/tools/CodeExecutor.ts +62 -54
  499. package/src/tools/ProgrammaticToolCalling.js.map +1 -0
  500. package/src/tools/ProgrammaticToolCalling.ts +29 -14
  501. package/src/tools/ReadFile.ts +39 -0
  502. package/src/tools/SkillTool.ts +46 -0
  503. package/src/tools/StreamingToolCallBuffer.js.map +1 -0
  504. package/src/tools/SubagentTool.ts +100 -0
  505. package/src/tools/ToolNode.js.map +1 -0
  506. package/src/tools/ToolNode.ts +548 -26
  507. package/src/tools/ToolSearch.js.map +1 -0
  508. package/src/tools/__tests__/BashExecutor.test.ts +49 -0
  509. package/src/tools/__tests__/BrowserTools.test.js.map +1 -0
  510. package/src/tools/__tests__/CodeExecutor.test.ts +37 -36
  511. package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.js.map +1 -0
  512. package/src/tools/__tests__/ProgrammaticToolCalling.test.js.map +1 -0
  513. package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +60 -0
  514. package/src/tools/__tests__/ReadFile.test.ts +44 -0
  515. package/src/tools/__tests__/SkillTool.test.ts +442 -0
  516. package/src/tools/__tests__/StreamingToolCallBuffer.test.js.map +1 -0
  517. package/src/tools/__tests__/SubagentExecutor.test.ts +1148 -0
  518. package/src/tools/__tests__/SubagentTool.test.ts +149 -0
  519. package/src/tools/__tests__/ToolApproval.test.js.map +1 -0
  520. package/src/tools/__tests__/ToolNode.outputReferences.test.ts +1438 -0
  521. package/src/tools/__tests__/ToolNode.recovery.test.js.map +1 -0
  522. package/src/tools/__tests__/ToolNode.session.test.js.map +1 -0
  523. package/src/tools/__tests__/ToolSearch.integration.test.js.map +1 -0
  524. package/src/tools/__tests__/ToolSearch.test.js.map +1 -0
  525. package/src/tools/__tests__/annotateMessagesForLLM.test.ts +479 -0
  526. package/src/tools/__tests__/handlers.test.js.map +1 -0
  527. package/src/tools/__tests__/skillCatalog.test.ts +161 -0
  528. package/src/tools/__tests__/subagentHooks.test.ts +210 -0
  529. package/src/tools/__tests__/toolOutputReferences.test.ts +415 -0
  530. package/src/tools/__tests__/truncation-recovery.integration.test.js.map +1 -0
  531. package/src/tools/handlers.js.map +1 -0
  532. package/src/tools/schema.js.map +1 -0
  533. package/src/tools/search/anthropic.js.map +1 -0
  534. package/src/tools/search/content.js.map +1 -0
  535. package/src/tools/search/content.test.js.map +1 -0
  536. package/src/tools/search/firecrawl.js.map +1 -0
  537. package/src/tools/search/format.js.map +1 -0
  538. package/src/tools/search/highlights.js.map +1 -0
  539. package/src/tools/search/index.js.map +1 -0
  540. package/src/tools/search/jina-reranker.test.js.map +1 -0
  541. package/src/tools/search/rerankers.js.map +1 -0
  542. package/src/tools/search/schema.js.map +1 -0
  543. package/src/tools/search/search.js.map +1 -0
  544. package/src/tools/search/search.ts +12 -2
  545. package/src/tools/search/serper-scraper.js.map +1 -0
  546. package/src/tools/search/tavily-scraper.ts +235 -0
  547. package/src/tools/search/tavily-search.ts +424 -0
  548. package/src/tools/search/tavily.test.ts +965 -0
  549. package/src/tools/search/test.js.map +1 -0
  550. package/src/tools/search/tool.js.map +1 -0
  551. package/src/tools/search/tool.ts +36 -2
  552. package/src/tools/search/types.js.map +1 -0
  553. package/src/tools/search/types.ts +133 -8
  554. package/src/tools/search/utils.js.map +1 -0
  555. package/src/tools/search/utils.ts +13 -5
  556. package/src/tools/skillCatalog.ts +126 -0
  557. package/src/tools/subagent/SubagentExecutor.ts +676 -0
  558. package/src/tools/subagent/index.ts +13 -0
  559. package/src/tools/subagent/types.test.ts +70 -0
  560. package/src/tools/subagent/types.ts +115 -0
  561. package/src/tools/toolOutputReferences.ts +825 -0
  562. package/src/types/agent-cache.ts +73 -0
  563. package/src/types/graph.js.map +1 -0
  564. package/src/types/graph.test.js.map +1 -0
  565. package/src/types/graph.ts +171 -20
  566. package/src/types/index.js.map +1 -0
  567. package/src/types/index.ts +3 -0
  568. package/src/types/llm.js.map +1 -0
  569. package/src/types/messages.js.map +1 -0
  570. package/src/types/messages.ts +27 -0
  571. package/src/types/run.js.map +1 -0
  572. package/src/types/run.ts +22 -0
  573. package/src/types/skill.ts +11 -0
  574. package/src/types/stream.js.map +1 -0
  575. package/src/types/tools.js.map +1 -0
  576. package/src/types/tools.ts +118 -0
  577. package/src/utils/__tests__/truncation.test.ts +66 -0
  578. package/src/utils/contextAnalytics.js.map +1 -0
  579. package/src/utils/contextAnalytics.test.js.map +1 -0
  580. package/src/utils/events.js.map +1 -0
  581. package/src/utils/graph.js.map +1 -0
  582. package/src/utils/handlers.js.map +1 -0
  583. package/src/utils/index.js.map +1 -0
  584. package/src/utils/index.ts +1 -3
  585. package/src/utils/llm.js.map +1 -0
  586. package/src/utils/llmConfig.js.map +1 -0
  587. package/src/utils/logging.js.map +1 -0
  588. package/src/utils/misc.js.map +1 -0
  589. package/src/utils/run.js.map +1 -0
  590. package/src/utils/schema.js.map +1 -0
  591. package/src/utils/title.js.map +1 -0
  592. package/src/utils/tokens.js.map +1 -0
  593. package/src/utils/toonFormat.js.map +1 -0
  594. package/src/utils/truncation.ts +154 -0
  595. package/dist/cjs/common/spawnPath.cjs +0 -104
  596. package/dist/cjs/common/spawnPath.cjs.map +0 -1
  597. package/dist/cjs/content/ArtifactStore.cjs +0 -579
  598. package/dist/cjs/content/ArtifactStore.cjs.map +0 -1
  599. package/dist/cjs/content/ContentStore.cjs +0 -638
  600. package/dist/cjs/content/ContentStore.cjs.map +0 -1
  601. package/dist/cjs/content/contentAnalyzer.cjs +0 -91
  602. package/dist/cjs/content/contentAnalyzer.cjs.map +0 -1
  603. package/dist/cjs/content/index.cjs +0 -20
  604. package/dist/cjs/content/index.cjs.map +0 -1
  605. package/dist/cjs/content/mcpAutoCache.cjs +0 -115
  606. package/dist/cjs/content/mcpAutoCache.cjs.map +0 -1
  607. package/dist/cjs/graphs/HandoffRegistry.cjs +0 -143
  608. package/dist/cjs/graphs/HandoffRegistry.cjs.map +0 -1
  609. package/dist/cjs/providers/a2a/A2ACapabilityProvider.cjs +0 -288
  610. package/dist/cjs/providers/a2a/A2ACapabilityProvider.cjs.map +0 -1
  611. package/dist/cjs/providers/a2a/client.cjs +0 -92
  612. package/dist/cjs/providers/a2a/client.cjs.map +0 -1
  613. package/dist/cjs/providers/a2a/config.cjs +0 -38
  614. package/dist/cjs/providers/a2a/config.cjs.map +0 -1
  615. package/dist/cjs/providers/capabilityNaming.cjs +0 -43
  616. package/dist/cjs/providers/capabilityNaming.cjs.map +0 -1
  617. package/dist/cjs/providers/mcp/MCPCapabilityProvider.cjs +0 -244
  618. package/dist/cjs/providers/mcp/MCPCapabilityProvider.cjs.map +0 -1
  619. package/dist/cjs/providers/mcp/config.cjs +0 -42
  620. package/dist/cjs/providers/mcp/config.cjs.map +0 -1
  621. package/dist/cjs/providers/mcp/transport.cjs +0 -65
  622. package/dist/cjs/providers/mcp/transport.cjs.map +0 -1
  623. package/dist/cjs/providers/tools-server/ToolsServerCapabilityProvider.cjs +0 -128
  624. package/dist/cjs/providers/tools-server/ToolsServerCapabilityProvider.cjs.map +0 -1
  625. package/dist/cjs/providers/types.cjs +0 -51
  626. package/dist/cjs/providers/types.cjs.map +0 -1
  627. package/dist/cjs/tools/artifacts/schema.cjs +0 -86
  628. package/dist/cjs/tools/artifacts/schema.cjs.map +0 -1
  629. package/dist/cjs/tools/artifacts/tool.cjs +0 -219
  630. package/dist/cjs/tools/artifacts/tool.cjs.map +0 -1
  631. package/dist/cjs/tools/fileSearch/formatter.cjs +0 -93
  632. package/dist/cjs/tools/fileSearch/formatter.cjs.map +0 -1
  633. package/dist/cjs/tools/fileSearch/ragClient.cjs +0 -102
  634. package/dist/cjs/tools/fileSearch/ragClient.cjs.map +0 -1
  635. package/dist/cjs/tools/fileSearch/schema.cjs +0 -18
  636. package/dist/cjs/tools/fileSearch/schema.cjs.map +0 -1
  637. package/dist/cjs/tools/fileSearch/tool.cjs +0 -155
  638. package/dist/cjs/tools/fileSearch/tool.cjs.map +0 -1
  639. package/dist/cjs/tools/proxyTool.cjs +0 -102
  640. package/dist/cjs/tools/proxyTool.cjs.map +0 -1
  641. package/dist/cjs/utils/childAgentContext.cjs +0 -242
  642. package/dist/cjs/utils/childAgentContext.cjs.map +0 -1
  643. package/dist/cjs/utils/credentials.cjs +0 -142
  644. package/dist/cjs/utils/credentials.cjs.map +0 -1
  645. package/dist/cjs/utils/httpClient.cjs +0 -74
  646. package/dist/cjs/utils/httpClient.cjs.map +0 -1
  647. package/dist/cjs/utils/toolManifest.cjs +0 -100
  648. package/dist/cjs/utils/toolManifest.cjs.map +0 -1
  649. package/dist/esm/common/spawnPath.mjs +0 -95
  650. package/dist/esm/common/spawnPath.mjs.map +0 -1
  651. package/dist/esm/content/ArtifactStore.mjs +0 -576
  652. package/dist/esm/content/ArtifactStore.mjs.map +0 -1
  653. package/dist/esm/content/ContentStore.mjs +0 -635
  654. package/dist/esm/content/ContentStore.mjs.map +0 -1
  655. package/dist/esm/content/contentAnalyzer.mjs +0 -87
  656. package/dist/esm/content/contentAnalyzer.mjs.map +0 -1
  657. package/dist/esm/content/index.mjs +0 -5
  658. package/dist/esm/content/mcpAutoCache.mjs +0 -111
  659. package/dist/esm/content/mcpAutoCache.mjs.map +0 -1
  660. package/dist/esm/graphs/HandoffRegistry.mjs +0 -141
  661. package/dist/esm/graphs/HandoffRegistry.mjs.map +0 -1
  662. package/dist/esm/providers/a2a/A2ACapabilityProvider.mjs +0 -281
  663. package/dist/esm/providers/a2a/A2ACapabilityProvider.mjs.map +0 -1
  664. package/dist/esm/providers/a2a/client.mjs +0 -88
  665. package/dist/esm/providers/a2a/client.mjs.map +0 -1
  666. package/dist/esm/providers/a2a/config.mjs +0 -35
  667. package/dist/esm/providers/a2a/config.mjs.map +0 -1
  668. package/dist/esm/providers/capabilityNaming.mjs +0 -39
  669. package/dist/esm/providers/capabilityNaming.mjs.map +0 -1
  670. package/dist/esm/providers/mcp/MCPCapabilityProvider.mjs +0 -240
  671. package/dist/esm/providers/mcp/MCPCapabilityProvider.mjs.map +0 -1
  672. package/dist/esm/providers/mcp/config.mjs +0 -39
  673. package/dist/esm/providers/mcp/config.mjs.map +0 -1
  674. package/dist/esm/providers/mcp/transport.mjs +0 -63
  675. package/dist/esm/providers/mcp/transport.mjs.map +0 -1
  676. package/dist/esm/providers/tools-server/ToolsServerCapabilityProvider.mjs +0 -126
  677. package/dist/esm/providers/tools-server/ToolsServerCapabilityProvider.mjs.map +0 -1
  678. package/dist/esm/providers/types.mjs +0 -51
  679. package/dist/esm/providers/types.mjs.map +0 -1
  680. package/dist/esm/tools/artifacts/schema.mjs +0 -79
  681. package/dist/esm/tools/artifacts/schema.mjs.map +0 -1
  682. package/dist/esm/tools/artifacts/tool.mjs +0 -213
  683. package/dist/esm/tools/artifacts/tool.mjs.map +0 -1
  684. package/dist/esm/tools/fileSearch/formatter.mjs +0 -90
  685. package/dist/esm/tools/fileSearch/formatter.mjs.map +0 -1
  686. package/dist/esm/tools/fileSearch/ragClient.mjs +0 -98
  687. package/dist/esm/tools/fileSearch/ragClient.mjs.map +0 -1
  688. package/dist/esm/tools/fileSearch/schema.mjs +0 -15
  689. package/dist/esm/tools/fileSearch/schema.mjs.map +0 -1
  690. package/dist/esm/tools/fileSearch/tool.mjs +0 -152
  691. package/dist/esm/tools/fileSearch/tool.mjs.map +0 -1
  692. package/dist/esm/tools/proxyTool.mjs +0 -100
  693. package/dist/esm/tools/proxyTool.mjs.map +0 -1
  694. package/dist/esm/utils/childAgentContext.mjs +0 -237
  695. package/dist/esm/utils/childAgentContext.mjs.map +0 -1
  696. package/dist/esm/utils/credentials.mjs +0 -135
  697. package/dist/esm/utils/credentials.mjs.map +0 -1
  698. package/dist/esm/utils/httpClient.mjs +0 -70
  699. package/dist/esm/utils/httpClient.mjs.map +0 -1
  700. package/dist/esm/utils/toolManifest.mjs +0 -96
  701. package/dist/esm/utils/toolManifest.mjs.map +0 -1
  702. package/dist/types/common/spawnPath.d.ts +0 -59
  703. package/dist/types/content/ArtifactStore.d.ts +0 -223
  704. package/dist/types/content/ContentStore.d.ts +0 -140
  705. package/dist/types/content/contentAnalyzer.d.ts +0 -38
  706. package/dist/types/content/index.d.ts +0 -24
  707. package/dist/types/content/mcpAutoCache.d.ts +0 -89
  708. package/dist/types/content/types.d.ts +0 -75
  709. package/dist/types/graphs/HandoffRegistry.d.ts +0 -97
  710. package/dist/types/providers/a2a/A2ACapabilityProvider.d.ts +0 -89
  711. package/dist/types/providers/a2a/client.d.ts +0 -47
  712. package/dist/types/providers/a2a/config.d.ts +0 -18
  713. package/dist/types/providers/a2a/index.d.ts +0 -6
  714. package/dist/types/providers/a2a/types.d.ts +0 -173
  715. package/dist/types/providers/capabilityNaming.d.ts +0 -25
  716. package/dist/types/providers/index.d.ts +0 -12
  717. package/dist/types/providers/mcp/MCPCapabilityProvider.d.ts +0 -54
  718. package/dist/types/providers/mcp/config.d.ts +0 -20
  719. package/dist/types/providers/mcp/index.d.ts +0 -5
  720. package/dist/types/providers/mcp/transport.d.ts +0 -18
  721. package/dist/types/providers/mcp/types.d.ts +0 -112
  722. package/dist/types/providers/tools-server/ToolsServerCapabilityProvider.d.ts +0 -59
  723. package/dist/types/providers/tools-server/index.d.ts +0 -1
  724. package/dist/types/providers/types.d.ts +0 -184
  725. package/dist/types/tools/artifacts/index.d.ts +0 -3
  726. package/dist/types/tools/artifacts/schema.d.ts +0 -63
  727. package/dist/types/tools/artifacts/tool.d.ts +0 -16
  728. package/dist/types/tools/artifacts/types.d.ts +0 -127
  729. package/dist/types/tools/fileSearch/formatter.d.ts +0 -25
  730. package/dist/types/tools/fileSearch/index.d.ts +0 -5
  731. package/dist/types/tools/fileSearch/ragClient.d.ts +0 -32
  732. package/dist/types/tools/fileSearch/schema.d.ts +0 -13
  733. package/dist/types/tools/fileSearch/tool.d.ts +0 -18
  734. package/dist/types/tools/fileSearch/types.d.ts +0 -139
  735. package/dist/types/tools/proxyTool.d.ts +0 -62
  736. package/dist/types/utils/childAgentContext.d.ts +0 -99
  737. package/dist/types/utils/credentials.d.ts +0 -77
  738. package/dist/types/utils/httpClient.d.ts +0 -46
  739. package/dist/types/utils/toolManifest.d.ts +0 -49
  740. package/src/common/__tests__/spawnPath.test.ts +0 -110
  741. package/src/common/spawnPath.ts +0 -101
  742. package/src/content/ArtifactStore.ts +0 -782
  743. package/src/content/ContentStore.ts +0 -753
  744. package/src/content/contentAnalyzer.ts +0 -105
  745. package/src/content/index.ts +0 -51
  746. package/src/content/mcpAutoCache.ts +0 -185
  747. package/src/content/types.ts +0 -82
  748. package/src/graphs/HandoffRegistry.ts +0 -199
  749. package/src/graphs/__tests__/HandoffRegistry.test.ts +0 -410
  750. package/src/graphs/__tests__/multi-agent-delegate.test.ts +0 -458
  751. package/src/graphs/__tests__/multi-agent-edges.test.ts +0 -276
  752. package/src/graphs/__tests__/multi-agent-nested-subgraph.test.ts +0 -221
  753. package/src/graphs/handoffValidation.test.ts +0 -353
  754. package/src/providers/__tests__/ToolsServerCapabilityProvider.integration.spec.ts +0 -79
  755. package/src/providers/__tests__/ToolsServerCapabilityProvider.test.ts +0 -271
  756. package/src/providers/__tests__/types.test.ts +0 -64
  757. package/src/providers/a2a/A2ACapabilityProvider.ts +0 -384
  758. package/src/providers/a2a/__tests__/A2ACapabilityProvider.integration.spec.ts +0 -345
  759. package/src/providers/a2a/__tests__/A2ACapabilityProvider.test.ts +0 -460
  760. package/src/providers/a2a/client.ts +0 -115
  761. package/src/providers/a2a/config.ts +0 -40
  762. package/src/providers/a2a/index.ts +0 -29
  763. package/src/providers/a2a/types.ts +0 -191
  764. package/src/providers/capabilityNaming.ts +0 -42
  765. package/src/providers/index.ts +0 -68
  766. package/src/providers/mcp/MCPCapabilityProvider.ts +0 -345
  767. package/src/providers/mcp/__tests__/MCPCapabilityProvider.integration.spec.ts +0 -386
  768. package/src/providers/mcp/__tests__/MCPCapabilityProvider.test.ts +0 -371
  769. package/src/providers/mcp/config.ts +0 -45
  770. package/src/providers/mcp/index.ts +0 -21
  771. package/src/providers/mcp/transport.ts +0 -76
  772. package/src/providers/mcp/types.ts +0 -139
  773. package/src/providers/tools-server/ToolsServerCapabilityProvider.ts +0 -249
  774. package/src/providers/tools-server/index.ts +0 -1
  775. package/src/providers/types.ts +0 -204
  776. package/src/scripts/test-bedrock-handoff-autonomous.ts +0 -267
  777. package/src/scripts/test-handoff-preamble.ts +0 -278
  778. package/src/specs/agent-handoffs-bedrock.integration.test.ts +0 -415
  779. package/src/tools/artifacts/__tests__/tool.test.ts +0 -259
  780. package/src/tools/artifacts/index.ts +0 -33
  781. package/src/tools/artifacts/schema.ts +0 -99
  782. package/src/tools/artifacts/tool.ts +0 -289
  783. package/src/tools/artifacts/types.ts +0 -162
  784. package/src/tools/fileSearch/__tests__/tool.test.ts +0 -261
  785. package/src/tools/fileSearch/formatter.ts +0 -129
  786. package/src/tools/fileSearch/index.ts +0 -23
  787. package/src/tools/fileSearch/ragClient.ts +0 -137
  788. package/src/tools/fileSearch/schema.ts +0 -19
  789. package/src/tools/fileSearch/tool.ts +0 -207
  790. package/src/tools/fileSearch/types.ts +0 -149
  791. package/src/tools/proxyTool.ts +0 -166
  792. package/src/utils/__tests__/childAgentContext.test.ts +0 -217
  793. package/src/utils/__tests__/credentials.test.ts +0 -130
  794. package/src/utils/__tests__/httpClient.test.ts +0 -75
  795. package/src/utils/__tests__/toolManifest.test.ts +0 -116
  796. package/src/utils/childAgentContext.ts +0 -259
  797. package/src/utils/credentials.ts +0 -157
  798. package/src/utils/httpClient.ts +0 -92
  799. package/src/utils/toolManifest.ts +0 -109
  800. /package/dist/esm/{content → langchain}/index.mjs.map +0 -0
@@ -4,51 +4,32 @@ var tools = require('@langchain/core/tools');
4
4
  var prompts = require('@langchain/core/prompts');
5
5
  var messages = require('@langchain/core/messages');
6
6
  var langgraph = require('@langchain/langgraph');
7
- require('../messages/core.cjs');
8
- require('nanoid');
7
+ var Graph = require('./Graph.cjs');
9
8
  var _enum = require('../common/enum.cjs');
10
- var spawnPath = require('../common/spawnPath.cjs');
11
9
  require('../tools/approval/constants.cjs');
12
- require('../utils/toonFormat.cjs');
13
- var summarize = require('../messages/summarize.cjs');
14
- var Graph = require('./Graph.cjs');
15
- var events = require('../utils/events.cjs');
16
- var logging = require('../utils/logging.cjs');
17
- var childAgentContext = require('../utils/childAgentContext.cjs');
18
10
  var ApprovalGateNode = require('../nodes/ApprovalGateNode.cjs');
19
11
 
20
- // HandoffRegistry no longer needed — handoff tools use synchronous
21
- // browser-tool callback pattern (spawn → wait → return result)
22
12
  /** Pattern to extract instructions from transfer ToolMessage content */
23
- const TRANSFER_INSTRUCTIONS_PATTERN = /(?:Instructions?|Context):\s*(.+)/is;
13
+ const HANDOFF_INSTRUCTIONS_PATTERN = /(?:Instructions?|Context):\s*(.+)/is;
24
14
  /**
25
15
  * MultiAgentGraph extends StandardGraph to support dynamic multi-agent workflows
26
16
  * with handoffs, fan-in/fan-out, and other composable patterns.
27
17
  *
28
18
  * Key behavior:
29
- * - Agents with ONLY transfer edges: Can dynamically route to any transfer destination
30
- * - Agents with ONLY sequence edges: Always follow their sequence edges
31
- * - Agents with BOTH: Use Command for exclusive routing (transfer OR sequence, not both)
32
- * - If transfer occurs: Only the transfer destination executes
33
- * - If no transfer: Sequence edges execute (potentially in parallel)
19
+ * - Agents with ONLY handoff edges: Can dynamically route to any handoff destination
20
+ * - Agents with ONLY direct edges: Always follow their direct edges
21
+ * - Agents with BOTH: Use Command for exclusive routing (handoff OR direct, not both)
22
+ * - If handoff occurs: Only the handoff destination executes
23
+ * - If no handoff: Direct edges execute (potentially in parallel)
34
24
  *
35
- * This enables the common pattern where an agent either transfers (one-way)
36
- * OR continues its workflow (sequence edges), but not both simultaneously.
25
+ * This enables the common pattern where an agent either delegates (handoff)
26
+ * OR continues its workflow (direct edges), but not both simultaneously.
37
27
  */
38
28
  class MultiAgentGraph extends Graph.StandardGraph {
39
29
  edges;
40
30
  startingNodes = new Set();
41
- sequenceEdges = [];
42
- transferEdges = [];
31
+ directEdges = [];
43
32
  handoffEdges = [];
44
- /**
45
- * Lazily populated registry of compiled subgraphs, keyed by agentId.
46
- * Handoff tools are created in the constructor but reference subgraphs
47
- * that are only created in createWorkflow(). This Map bridges that gap —
48
- * tools capture the Map reference in their closure, and createWorkflow()
49
- * populates it before any tool invocation occurs.
50
- */
51
- subgraphRegistry = new Map();
52
33
  /**
53
34
  * Map of agentId to parallel group info.
54
35
  * Contains groupId (incrementing number reflecting execution order) for agents in parallel groups.
@@ -60,63 +41,76 @@ class MultiAgentGraph extends Graph.StandardGraph {
60
41
  * - summarizer: undefined (sequential, order 2)
61
42
  */
62
43
  agentParallelGroups = new Map();
63
- /**
64
- * Tracks the ID of the last agent that produced output.
65
- * Used by auto-continuation to know which agent's context to preserve after handoff.
66
- */
67
- lastActiveAgentId;
68
- /**
69
- * Registry for async handoff execution.
70
- * Enables autonomous orchestration: spawn children non-blocking,
71
- * orchestrator stays alive to reason and collect results when ready.
72
- */
73
- // HandoffRegistry removed — handoff tools are synchronous (callback pattern)
74
- /**
75
- * When set, the graph routes START to this agent instead of the default starting nodes.
76
- * Enables multi-turn resumption: follow-up messages go to the agent that last handled
77
- * the conversation rather than restarting from the root/router agent.
78
- */
79
- resumeFromAgentId;
80
44
  constructor(input) {
81
45
  super(input);
82
46
  this.edges = input.edges;
83
- this.resumeFromAgentId = input.resumeFromAgentId;
47
+ this.validateEdgeAgents();
84
48
  this.categorizeEdges();
85
49
  this.analyzeGraph();
86
- this.createTransferTools();
87
50
  this.createHandoffTools();
88
- logging.mlog(`[MultiAgentGraph] Constructor complete: ${this.agentContexts.size} agents, ${this.edges.length} edges`);
89
51
  }
90
52
  /**
91
- * Categorize edges into handoff, transfer, and sequence types
53
+ * Fails fast when an edge references an agent that is not in
54
+ * `agentContexts`. Without this check, the underlying LangGraph
55
+ * `StateGraph.compile()` would throw the opaque
56
+ * `Found edge ending at unknown node "<id>"` error after graph
57
+ * construction — far from the true root cause.
58
+ *
59
+ * This catches the common misuse of passing `edges` into a multi-agent
60
+ * config without also passing the corresponding sub-agent configs in
61
+ * `agents` (e.g. a host that forgot to pre-load handoff targets).
92
62
  */
93
- categorizeEdges() {
63
+ validateEdgeAgents() {
64
+ const known = new Set(this.agentContexts.keys());
65
+ const unknown = new Set();
94
66
  for (const edge of this.edges) {
95
- if (edge.edgeType === _enum.EdgeType.HANDOFF) {
96
- this.handoffEdges.push(edge);
67
+ const participants = [
68
+ ...(Array.isArray(edge.from) ? edge.from : [edge.from]),
69
+ ...(Array.isArray(edge.to) ? edge.to : [edge.to]),
70
+ ];
71
+ for (const id of participants) {
72
+ if (typeof id === 'string' && !known.has(id)) {
73
+ unknown.add(id);
74
+ }
97
75
  }
98
- else if (edge.edgeType === _enum.EdgeType.SEQUENCE) {
99
- this.sequenceEdges.push(edge);
76
+ }
77
+ if (unknown.size === 0) {
78
+ return;
79
+ }
80
+ const missing = Array.from(unknown)
81
+ .map((id) => `"${id}"`)
82
+ .join(', ');
83
+ throw new Error(`MultiAgentGraph: edges reference agent(s) not present in agents: [${missing}]. ` +
84
+ 'Ensure every agent referenced by an edge is also included in the `agents` array, ' +
85
+ 'or filter orphaned edges before constructing the graph.');
86
+ }
87
+ /**
88
+ * Categorize edges into handoff and direct types
89
+ */
90
+ categorizeEdges() {
91
+ for (const edge of this.edges) {
92
+ // Default behavior: edges with conditions or explicit 'handoff' type are handoff edges
93
+ // Edges with explicit 'direct' type or multi-destination without conditions are direct edges
94
+ if (edge.edgeType === _enum.EdgeType.DIRECT) {
95
+ this.directEdges.push(edge);
100
96
  }
101
- else if (edge.edgeType === _enum.EdgeType.TRANSFER ||
102
- edge.condition != null) {
103
- this.transferEdges.push(edge);
97
+ else if (edge.edgeType === _enum.EdgeType.HANDOFF || edge.condition != null) {
98
+ this.handoffEdges.push(edge);
104
99
  }
105
100
  else {
106
- // Default: single-to-single edges are transfer, single-to-multiple are sequence
101
+ // Default: single-to-single edges are handoff, single-to-multiple are direct
107
102
  const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
108
103
  const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
109
104
  if (sources.length === 1 && destinations.length > 1) {
110
- // Fan-out pattern defaults to sequence
111
- this.sequenceEdges.push(edge);
105
+ // Fan-out pattern defaults to direct
106
+ this.directEdges.push(edge);
112
107
  }
113
108
  else {
114
- // Everything else defaults to transfer
115
- this.transferEdges.push(edge);
109
+ // Everything else defaults to handoff
110
+ this.handoffEdges.push(edge);
116
111
  }
117
112
  }
118
113
  }
119
- logging.mlog(`[MultiAgentGraph] Edge categorization: ${this.handoffEdges.length} handoff, ${this.transferEdges.length} transfer, ${this.sequenceEdges.length} sequence (of ${this.edges.length} total)`);
120
114
  }
121
115
  /**
122
116
  * Analyze graph structure to determine starting nodes and connections
@@ -138,7 +132,6 @@ class MultiAgentGraph extends Graph.StandardGraph {
138
132
  if (this.startingNodes.size === 0 && this.agentContexts.size > 0) {
139
133
  this.startingNodes.add(this.agentContexts.keys().next().value);
140
134
  }
141
- logging.mlog(`[MultiAgentGraph] Starting nodes identified: [${Array.from(this.startingNodes).join(', ')}]`);
142
135
  // Determine if graph has parallel execution capability
143
136
  this.computeParallelCapability();
144
137
  }
@@ -174,8 +167,8 @@ class MultiAgentGraph extends Graph.StandardGraph {
174
167
  if (visited.has(current))
175
168
  continue;
176
169
  visited.add(current);
177
- // Find sequence edges from this node
178
- for (const edge of this.sequenceEdges) {
170
+ // Find direct edges from this node
171
+ for (const edge of this.directEdges) {
179
172
  const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
180
173
  if (!sources.includes(current))
181
174
  continue;
@@ -202,8 +195,8 @@ class MultiAgentGraph extends Graph.StandardGraph {
202
195
  }
203
196
  }
204
197
  }
205
- // Also follow transfer and handoff edges for traversal (they don't create parallel groups)
206
- for (const edge of [...this.transferEdges, ...this.handoffEdges]) {
198
+ // Also follow handoff edges for traversal (but they don't create parallel groups)
199
+ for (const edge of this.handoffEdges) {
207
200
  const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
208
201
  if (!sources.includes(current))
209
202
  continue;
@@ -224,14 +217,6 @@ class MultiAgentGraph extends Graph.StandardGraph {
224
217
  getParallelGroupId(agentId) {
225
218
  return this.agentParallelGroups.get(agentId);
226
219
  }
227
- /**
228
- * Returns the ID of the last agent that produced output.
229
- * Used by auto-continuation to determine which agent's context to preserve
230
- * when a response is truncated after an agent handoff.
231
- */
232
- getLastActiveAgentId() {
233
- return this.lastActiveAgentId;
234
- }
235
220
  /**
236
221
  * Override to indicate this is a multi-agent graph.
237
222
  * Enables agentId to be included in RunStep for frontend agent labeling.
@@ -246,59 +231,45 @@ class MultiAgentGraph extends Graph.StandardGraph {
246
231
  return this.agentParallelGroups.get(agentId);
247
232
  }
248
233
  /**
249
- * Create transfer tools for agents based on transfer edges only.
250
- * Transfer tools return Command for one-way routing — parent exits, child takes over.
234
+ * Create handoff tools for agents based on handoff edges only
251
235
  */
252
- createTransferTools() {
253
- const transfersByAgent = new Map();
254
- for (const edge of this.transferEdges) {
236
+ createHandoffTools() {
237
+ // Group handoff edges by source agent(s)
238
+ const handoffsByAgent = new Map();
239
+ // Only process handoff edges for tool creation
240
+ for (const edge of this.handoffEdges) {
255
241
  const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
256
242
  sources.forEach((source) => {
257
- if (!transfersByAgent.has(source)) {
258
- transfersByAgent.set(source, []);
243
+ if (!handoffsByAgent.has(source)) {
244
+ handoffsByAgent.set(source, []);
259
245
  }
260
- transfersByAgent.get(source).push(edge);
246
+ handoffsByAgent.get(source).push(edge);
261
247
  });
262
248
  }
263
- for (const [agentId, edges] of transfersByAgent) {
249
+ // Create handoff tools for each agent
250
+ for (const [agentId, edges] of handoffsByAgent) {
264
251
  const agentContext = this.agentContexts.get(agentId);
265
252
  if (!agentContext)
266
253
  continue;
267
- const transferTools = [];
254
+ // Create handoff tools for this agent's outgoing edges
255
+ const handoffTools = [];
268
256
  const sourceAgentName = agentContext.name ?? agentId;
269
257
  for (const edge of edges) {
270
- transferTools.push(...this.createTransferToolsForEdge(edge, agentId, sourceAgentName));
258
+ handoffTools.push(...this.createHandoffToolsForEdge(edge, agentId, sourceAgentName));
271
259
  }
272
260
  if (!agentContext.graphTools) {
273
261
  agentContext.graphTools = [];
274
262
  }
275
- agentContext.graphTools.push(...transferTools);
276
- logging.mlog(`[MultiAgentGraph] Transfer tools for "${agentId}": [${transferTools.map((t) => t.name).join(', ')}]`);
277
- // Inject orchestration guidance for agents with transfer tools
278
- const childDescs = edges.flatMap((e) => {
279
- const dests = Array.isArray(e.to) ? e.to : [e.to];
280
- return dests.map((d) => {
281
- const ctx = this.agentContexts.get(d);
282
- const name = ctx?.name ?? d;
283
- const desc = ctx?.description ? ` — ${ctx.description}` : '';
284
- return `${name}${desc}`;
285
- });
286
- });
287
- const guidance = this.buildOrchestratorGuidance(childDescs, transferTools.length);
288
- const existing = agentContext.additionalInstructions ?? '';
289
- agentContext.additionalInstructions = existing
290
- ? `${existing}\n\n${guidance}`
291
- : guidance;
263
+ agentContext.graphTools.push(...handoffTools);
292
264
  }
293
265
  }
294
266
  /**
295
- * Create transfer tools for an edge (handles multiple destinations).
296
- * Transfer tools return Command for one-way routing parent exits, child takes over.
297
- * @param edge - The graph edge defining the transfer
298
- * @param sourceAgentId - The ID of the agent that will perform the transfer
267
+ * Create handoff tools for an edge (handles multiple destinations)
268
+ * @param edge - The graph edge defining the handoff
269
+ * @param sourceAgentId - The ID of the agent that will perform the handoff
299
270
  * @param sourceAgentName - The human-readable name of the source agent
300
271
  */
301
- createTransferToolsForEdge(edge, sourceAgentId, sourceAgentName) {
272
+ createHandoffToolsForEdge(edge, sourceAgentId, sourceAgentName) {
302
273
  const tools$1 = [];
303
274
  const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
304
275
  /** If there's a condition, create a single conditional handoff tool */
@@ -306,10 +277,8 @@ class MultiAgentGraph extends Graph.StandardGraph {
306
277
  const toolName = 'conditional_transfer';
307
278
  const toolDescription = edge.description ?? 'Conditionally transfer control based on state';
308
279
  /** Check if we have a prompt for handoff input */
309
- const hasTransferInput = edge.prompt != null && typeof edge.prompt === 'string';
310
- const transferInputDescription = hasTransferInput
311
- ? edge.prompt
312
- : undefined;
280
+ const hasHandoffInput = edge.prompt != null && typeof edge.prompt === 'string';
281
+ const handoffInputDescription = hasHandoffInput ? edge.prompt : undefined;
313
282
  const promptKey = edge.promptKey ?? 'instructions';
314
283
  tools$1.push(tools.tool(async (rawInput, config) => {
315
284
  const input = rawInput;
@@ -333,7 +302,7 @@ class MultiAgentGraph extends Graph.StandardGraph {
333
302
  destination = Array.isArray(result) ? result[0] : destinations[0];
334
303
  }
335
304
  let content = `Conditionally transferred to ${destination}`;
336
- if (hasTransferInput &&
305
+ if (hasHandoffInput &&
337
306
  promptKey in input &&
338
307
  input[promptKey] != null) {
339
308
  content += `\n\n${promptKey.charAt(0).toUpperCase() + promptKey.slice(1)}: ${input[promptKey]}`;
@@ -356,13 +325,13 @@ class MultiAgentGraph extends Graph.StandardGraph {
356
325
  });
357
326
  }, {
358
327
  name: toolName,
359
- schema: hasTransferInput
328
+ schema: hasHandoffInput
360
329
  ? {
361
330
  type: 'object',
362
331
  properties: {
363
332
  [promptKey]: {
364
333
  type: 'string',
365
- description: transferInputDescription,
334
+ description: handoffInputDescription,
366
335
  },
367
336
  },
368
337
  required: [],
@@ -375,12 +344,10 @@ class MultiAgentGraph extends Graph.StandardGraph {
375
344
  /** Create individual tools for each destination */
376
345
  for (const destination of destinations) {
377
346
  const toolName = `${_enum.Constants.LC_TRANSFER_TO_}${destination}`;
378
- const destContext = this.agentContexts.get(destination);
379
- const toolDescription = edge.description ??
380
- this.buildDefaultTransferDescription(destContext, destination);
347
+ const toolDescription = edge.description ?? `Transfer control to agent '${destination}'`;
381
348
  /** Check if we have a prompt for handoff input */
382
- const hasTransferInput = edge.prompt != null && typeof edge.prompt === 'string';
383
- const transferInputDescription = hasTransferInput
349
+ const hasHandoffInput = edge.prompt != null && typeof edge.prompt === 'string';
350
+ const handoffInputDescription = hasHandoffInput
384
351
  ? edge.prompt
385
352
  : undefined;
386
353
  const promptKey = edge.promptKey ?? 'instructions';
@@ -389,7 +356,7 @@ class MultiAgentGraph extends Graph.StandardGraph {
389
356
  const toolCallId = config?.toolCall?.id ??
390
357
  'unknown';
391
358
  let content = `Successfully transferred to ${destination}`;
392
- if (hasTransferInput &&
359
+ if (hasHandoffInput &&
393
360
  promptKey in input &&
394
361
  input[promptKey] != null) {
395
362
  content += `\n\n${promptKey.charAt(0).toUpperCase() + promptKey.slice(1)}: ${input[promptKey]}`;
@@ -466,13 +433,13 @@ class MultiAgentGraph extends Graph.StandardGraph {
466
433
  });
467
434
  }, {
468
435
  name: toolName,
469
- schema: hasTransferInput
436
+ schema: hasHandoffInput
470
437
  ? {
471
438
  type: 'object',
472
439
  properties: {
473
440
  [promptKey]: {
474
441
  type: 'string',
475
- description: transferInputDescription,
442
+ description: handoffInputDescription,
476
443
  },
477
444
  },
478
445
  required: [],
@@ -484,630 +451,12 @@ class MultiAgentGraph extends Graph.StandardGraph {
484
451
  }
485
452
  return tools$1;
486
453
  }
487
- /**
488
- * Builds orchestration guidance injected into the system message of agents
489
- * that have handoff or transfer tools (i.e., orchestrator agents).
490
- *
491
- * Implements two orchestration primitives:
492
- * - Execution bias guidance injected into the system prompt
493
- * - Multi-round autonomous execution for dependent tasks
494
- *
495
- * Handoff tools are synchronous (browser-tool callback pattern): spawn the
496
- * child, await completion, return the real text as the tool output. Parallel
497
- * handoff tool calls in one turn run concurrently via LangGraph's ToolNode,
498
- * so independent children run in parallel without explicit orchestration.
499
- *
500
- * @param childDescs - Display names (with optional descriptions) of child agents
501
- * @param toolCount - Number of handoff/transfer tools available
502
- */
503
- buildOrchestratorGuidance(childDescs, toolCount) {
504
- return [
505
- '## Agent Orchestration',
506
- '',
507
- `You have ${toolCount} specialist agent(s) available for delegation:`,
508
- ...childDescs.map((d) => `- ${d}`),
509
- '',
510
- '## Execution Bias',
511
- 'If the user asks you to do the work, start doing it in the same turn.',
512
- 'Use a real tool call or concrete action first when the task is actionable; do not stop at a plan or promise-to-act reply.',
513
- 'Commentary-only turns are incomplete when tools are available and the next action is clear.',
514
- 'If the work will take multiple steps or a while to finish, send one short progress update before or while acting.',
515
- '',
516
- '## How Delegation Works',
517
- 'Each handoff tool call spawns a sub-agent, waits for it to complete, and returns the real result directly — like a function call.',
518
- 'Independent tasks MAY be called in parallel (multiple handoff tool calls in one turn). They run concurrently and all results return together.',
519
- 'Dependent tasks MUST be sequential: call one agent, get the result, then call the next agent using that real data.',
520
- '',
521
- '## Agent Isolation',
522
- "Sub-agents CANNOT see your conversation or the user's original message. They ONLY see what you write in the `instructions` parameter.",
523
- "When writing instructions, include ALL data the agent needs. Copy exact values from the user's message — email addresses, names, URLs, dates, numbers.",
524
- 'When delegating follow-up work, include the real data from prior agent results directly in the instructions text.',
525
- 'Do NOT re-delegate a task that was already completed. If you have the data, pass it directly.',
526
- ].join('\n');
527
- }
528
- /**
529
- * Builds subagent context instructions injected into child agents that are
530
- * handoff destinations. This tells the child agent it is a subagent with
531
- * a focused task.
532
- *
533
- * @param orchestratorName - Display name of the parent orchestrator agent
534
- */
535
- buildChildAgentContext(orchestratorName) {
536
- return [
537
- '# Subagent Context',
538
- '',
539
- `You are a **subagent** spawned by the ${orchestratorName} for a specific task.`,
540
- '',
541
- '## Your Role',
542
- "- Complete this task. That's your entire purpose.",
543
- `- You are NOT the ${orchestratorName}. Don't try to be.`,
544
- '',
545
- '## Rules',
546
- '1. **Stay focused** - Do your assigned task, nothing else',
547
- `2. **Complete the task** - Your final message will be automatically reported to the ${orchestratorName}`,
548
- "3. **Don't initiate** - No heartbeats, no proactive actions, no side quests",
549
- "4. **Be ephemeral** - You may be terminated after task completion. That's fine.",
550
- '',
551
- '## Output Format',
552
- 'When complete, your final response should include:',
553
- '- What you accomplished or found',
554
- `- Any relevant details the ${orchestratorName} should know`,
555
- '- Keep it concise but informative',
556
- '',
557
- "## What You DON'T Do",
558
- `- NO user conversations (that's ${orchestratorName}'s job)`,
559
- '- NO external messages (email, tweets, etc.) unless explicitly tasked with a specific recipient/channel',
560
- '- NO cron jobs or persistent state',
561
- `- NO pretending to be the ${orchestratorName}`,
562
- ].join('\n');
563
- }
564
- /**
565
- * Builds a meaningful default description for a transfer tool when no explicit
566
- * edge.description is provided. Uses the destination agent's name and description
567
- * so the LLM can make informed routing decisions.
568
- * @param destContext - AgentContext of the destination agent (may be undefined)
569
- * @param destinationId - Raw agent ID (fallback when context unavailable)
570
- */
571
- buildDefaultTransferDescription(destContext, destinationId) {
572
- const displayName = destContext?.name ?? destinationId;
573
- const agentDescription = destContext?.description;
574
- if (agentDescription != null && agentDescription !== '') {
575
- return `Transfer to "${displayName}": ${agentDescription}`;
576
- }
577
- return `Transfer control to "${displayName}"`;
578
- }
579
- /**
580
- * Create handoff tools for agents based on handoff edges.
581
- * Handoff tools invoke child agent subgraphs inline and return the result
582
- * as a string to the parent agent's context. Unlike transfer tools (which
583
- * return Command for one-way routing), handoff tools execute the child,
584
- * extract the final text, and return it within the parent's agent loop.
585
- *
586
- * This enables the supervisor pattern: parent calls child → gets result → thinks → calls another.
587
- */
588
- createHandoffTools() {
589
- const handoffsByAgent = new Map();
590
- for (const edge of this.handoffEdges) {
591
- const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
592
- sources.forEach((source) => {
593
- if (!handoffsByAgent.has(source)) {
594
- handoffsByAgent.set(source, []);
595
- }
596
- handoffsByAgent.get(source).push(edge);
597
- });
598
- }
599
- for (const [agentId, edges] of handoffsByAgent) {
600
- const agentContext = this.agentContexts.get(agentId);
601
- if (!agentContext)
602
- continue;
603
- const handoffTools = [];
604
- for (const edge of edges) {
605
- handoffTools.push(...this.createHandoffToolsForEdge(edge, agentId));
606
- }
607
- if (!agentContext.graphTools) {
608
- agentContext.graphTools = [];
609
- }
610
- agentContext.graphTools.push(...handoffTools);
611
- // No collect_results tool needed — handoff tools use the browser-tool
612
- // callback pattern: spawn child, wait for completion, return real result.
613
- // The LLM naturally gets child results as tool return values.
614
- logging.mlog(`[MultiAgentGraph] Handoff tools for "${agentId}": [${handoffTools.map((t) => t.name).join(', ')}]`);
615
- // Inject autonomous orchestration guidance for agents with handoff tools.
616
- const childDescs = edges.flatMap((e) => {
617
- const dests = Array.isArray(e.to) ? e.to : [e.to];
618
- return dests.map((d) => {
619
- const ctx = this.agentContexts.get(d);
620
- const name = ctx?.name ?? d;
621
- const desc = ctx?.description ? ` — ${ctx.description}` : '';
622
- return `${name}${desc}`;
623
- });
624
- });
625
- const orchestrationGuidance = this.buildOrchestratorGuidance(childDescs, handoffTools.length);
626
- const existing = agentContext.additionalInstructions ?? '';
627
- agentContext.additionalInstructions = existing
628
- ? `${existing}\n\n${orchestrationGuidance}`
629
- : orchestrationGuidance;
630
- // Inject subagent context into each child/destination agent.
631
- // This tells child agents they are subagents with a focused task — stay focused,
632
- // execute (don't plan), and return results to the orchestrator.
633
- const orchestratorName = agentContext.name ?? agentId;
634
- const childAgentContext = this.buildChildAgentContext(orchestratorName);
635
- for (const edge of edges) {
636
- const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
637
- for (const destId of dests) {
638
- const destCtx = this.agentContexts.get(destId);
639
- if (!destCtx)
640
- continue;
641
- const existingChild = destCtx.additionalInstructions ?? '';
642
- // Avoid duplicate injection if agent is destination of multiple edges
643
- if (existingChild.includes('# Subagent Context'))
644
- continue;
645
- destCtx.additionalInstructions = existingChild
646
- ? `${existingChild}\n\n${childAgentContext}`
647
- : childAgentContext;
648
- }
649
- }
650
- }
651
- }
652
- /**
653
- * Create handoff tools for an edge (handles multiple destinations).
654
- * Each handoff tool spawns the child agent's compiled subgraph asynchronously
655
- * and returns immediately. The orchestrator uses `collect_results` to retrieve
656
- * outputs and `check_agents` to monitor status — a push-based autonomous
657
- * orchestration pattern.
658
- *
659
- * @param edge - The graph edge defining the handoff
660
- * @param sourceAgentId - The ID of the parent/supervisor agent
661
- */
662
- createHandoffToolsForEdge(edge, sourceAgentId) {
663
- const tools$1 = [];
664
- const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
665
- const maxResultChars = edge.maxResultChars ?? _enum.DEFAULT_HANDOFF_MAX_RESULT_CHARS;
666
- for (const destination of destinations) {
667
- const toolName = `${_enum.Constants.LC_HANDOFF_TO_}${destination}`;
668
- const destContext = this.agentContexts.get(destination);
669
- const toolDescription = edge.description ??
670
- this.buildDefaultHandoffDescription(destContext, destination);
671
- /**
672
- * Always include an instructions parameter so the orchestrator can
673
- * pass scoped task descriptions to each child agent. Without this,
674
- * the child gets no context about what to do.
675
- */
676
- const promptKey = edge.promptKey ?? 'instructions';
677
- const destDesc = destContext?.description;
678
- const promptInputDescription = edge.prompt ??
679
- (destDesc
680
- ? `Task instructions for this agent (${destDesc}). Describe exactly what it should do.`
681
- : 'Specific task instructions for this agent. Describe exactly what it should do and what data to use.');
682
- /** Capture registry reference — Map populated in createWorkflow() */
683
- const subgraphReg = this.subgraphRegistry;
684
- tools$1.push(tools.tool(async (rawInput, config) => {
685
- const input = rawInput;
686
- const subgraph = subgraphReg.get(destination);
687
- if (!subgraph) {
688
- throw new Error(`Handoff target "${destination}" subgraph not found in registry. ` +
689
- 'This is a bug: createWorkflow() should have populated the subgraph registry.');
690
- }
691
- /**
692
- * Per-spawn unique key = the orchestrator's tool_call.id.
693
- * LangChain's ToolNode passes `config.toolCall.id` to the tool
694
- * function; this is the same id the frontend sees on the parent's
695
- * handoff content part, so the UI can match each AgentHandoff
696
- * indicator to its own sidebar task without collision when the
697
- * same agent is invoked multiple times.
698
- */
699
- const toolCallCfg = config?.toolCall;
700
- const spawnKey = toolCallCfg?.id ??
701
- `${destination}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
702
- /**
703
- * Hierarchical spawnPath: parent's spawnPath (from metadata) + this spawnKey.
704
- * Root invocations have empty parentSpawnPath. Threaded through childConfig
705
- * so nested handoffs/sequences inherit the full ancestry.
706
- * See docs/multi-agent-nesting-architecture.md §4.
707
- */
708
- const parentMetadata = config?.metadata;
709
- const parentSpawnPath = typeof parentMetadata?.spawnPath === 'string'
710
- ? parentMetadata.spawnPath
711
- : '';
712
- const childSpawnPath = spawnPath.buildSpawnPath(parentSpawnPath, spawnKey);
713
- const childDepth = spawnPath.spawnPathDepth(childSpawnPath);
714
- /**
715
- * Child agent message construction — three modes:
716
- *
717
- * 1. Default (isolated-session pattern): Child gets ONLY the orchestrator's
718
- * task instructions as a single HumanMessage. No parent conversation
719
- * leaks. Orchestrator controls exactly what context the child sees.
720
- *
721
- * 2. Passthrough (edge.passthrough = true): Child gets the full parent
722
- * conversation + orchestrator's instructions appended. Use this when
723
- * the child needs the full user context (e.g., a transfer-like handoff).
724
- *
725
- * 3. Fallback: If no instructions provided AND not passthrough, child
726
- * gets the agent's description as its task.
727
- */
728
- const taskDescription = promptKey in input && input[promptKey] != null
729
- ? String(input[promptKey])
730
- : '';
731
- let childMessages;
732
- if (edge.passthrough) {
733
- // Passthrough: full parent context + instructions appended
734
- const state = langgraph.getCurrentTaskInput();
735
- childMessages = MultiAgentGraph.prepareHandoffMessages([
736
- ...state.messages,
737
- ]);
738
- if (taskDescription) {
739
- childMessages.push(new messages.HumanMessage(taskDescription));
740
- }
741
- }
742
- else {
743
- // Default: isolated — only orchestrator's instructions
744
- const fallbackTask = destContext?.description ?? 'Complete your assigned task.';
745
- childMessages = [
746
- new messages.HumanMessage(taskDescription || fallbackTask),
747
- ];
748
- }
749
- const childState = {
750
- messages: childMessages,
751
- };
752
- const childContext = this.agentContexts.get(destination);
753
- const destName = destContext?.name ?? destination;
754
- logging.mlog(`[MultiAgentGraph] Handoff "${sourceAgentId}" -> "${destination}" SPAWN (async)\n` +
755
- ` messages: ${childMessages.length}\n` +
756
- ` childTools: ${childContext?.tools?.length ?? 0} instances\n` +
757
- ` childToolDefs: ${childContext?.toolDefinitions?.length ?? 0} definitions`);
758
- /**
759
- * Dispatch transition BEFORE spawning the child subgraph so that
760
- * callbacks.js sets multiAgentTrace.isMultiAgent = true before the
761
- * child's ON_RUN_STEP events fire. spawnKey lets the UI create a
762
- * distinct sidebar task for this specific invocation.
763
- */
764
- logging.mlog(`[MultiAgentGraph] Handoff SPAWN "${sourceAgentId}" -> "${destination}" spawnKey=${spawnKey}`);
765
- await events.safeDispatchCustomEvent(_enum.GraphEvents.ON_AGENT_TRANSITION, {
766
- sourceAgentId: sourceAgentId,
767
- sourceAgentName: this.agentContexts.get(sourceAgentId)?.name ?? sourceAgentId,
768
- destinationAgentId: destination,
769
- destinationAgentName: destName,
770
- edgeType: _enum.EdgeType.HANDOFF,
771
- timestamp: Date.now(),
772
- spawnKey,
773
- spawnPath: childSpawnPath,
774
- parentSpawnPath: parentSpawnPath || null,
775
- spawnDepth: childDepth,
776
- }, config);
777
- /**
778
- * Child events need to carry spawnKey so callbacks.js can route
779
- * them to the correct child aggregator. LangChain propagates
780
- * `metadata` and `tags` from the parent config to all descendants,
781
- * so everything dispatched inside subgraph.invoke will have
782
- * metadata.spawnKey populated on the event's runtime metadata.
783
- */
784
- const childConfig = {
785
- ...(config ?? {}),
786
- metadata: {
787
- ...(config?.metadata ?? {}),
788
- spawnKey,
789
- spawnAgentId: destination,
790
- /** Hierarchical identity — see spawnPath.ts */
791
- spawnPath: childSpawnPath,
792
- parentSpawnPath: parentSpawnPath || null,
793
- spawnDepth: childDepth,
794
- },
795
- tags: [
796
- ...(config?.tags ?? []),
797
- `spawn:${spawnKey}`,
798
- `depth:${childDepth}`,
799
- ],
800
- };
801
- /**
802
- * Callback pattern: spawn child, WAIT for completion, return real
803
- * result. The parent naturally sees child results in its tool
804
- * return, so no manual "collect_results" step is needed.
805
- *
806
- * Parallelism still works: when the LLM emits multiple handoff
807
- * tool calls in one response, LangGraph runs all tool functions
808
- * concurrently. Each waits for its child. All results land in
809
- * the LLM's next turn together.
810
- */
811
- const spawnedAt = Date.now();
812
- try {
813
- const result = await subgraph.invoke(childState, childConfig);
814
- const durationMs = Date.now() - spawnedAt;
815
- const resultText = MultiAgentGraph.extractHandoffResult(result.messages, destination);
816
- const truncated = MultiAgentGraph.truncateHandoffResult(resultText, maxResultChars);
817
- logging.mlog(`[MultiAgentGraph] Handoff COMPLETED "${sourceAgentId}" -> "${destination}" ` +
818
- `spawnKey=${spawnKey} (${durationMs}ms, ${truncated.length} chars)`);
819
- /** Dispatch completion event for UI update — carries spawnKey so
820
- * the frontend can mark the correct sidebar task as completed. */
821
- events.safeDispatchCustomEvent(_enum.GraphEvents.ON_AGENT_TRANSITION, {
822
- sourceAgentId: destination,
823
- sourceAgentName: destName,
824
- destinationAgentId: sourceAgentId,
825
- destinationAgentName: this.agentContexts.get(sourceAgentId)?.name ??
826
- sourceAgentId,
827
- edgeType: _enum.EdgeType.HANDOFF,
828
- timestamp: Date.now(),
829
- isCompletion: true,
830
- durationMs,
831
- resultLength: truncated.length,
832
- spawnKey,
833
- spawnPath: childSpawnPath,
834
- parentSpawnPath: parentSpawnPath || null,
835
- spawnDepth: childDepth,
836
- }, config).catch(() => {
837
- /* best-effort event dispatch */
838
- });
839
- return truncated;
840
- }
841
- catch (err) {
842
- const durationMs = Date.now() - spawnedAt;
843
- const errMsg = err instanceof Error ? err.message : String(err);
844
- // EPIPE from console.debug is non-fatal
845
- if (errMsg.includes('EPIPE')) {
846
- logging.mwarn(`[MultiAgentGraph] Child "${destination}" hit EPIPE (non-fatal) spawnKey=${spawnKey}`);
847
- events.safeDispatchCustomEvent(_enum.GraphEvents.ON_AGENT_TRANSITION, {
848
- sourceAgentId: destination,
849
- sourceAgentName: destName,
850
- destinationAgentId: sourceAgentId,
851
- destinationAgentName: this.agentContexts.get(sourceAgentId)?.name ??
852
- sourceAgentId,
853
- edgeType: _enum.EdgeType.HANDOFF,
854
- timestamp: Date.now(),
855
- isCompletion: true,
856
- durationMs,
857
- spawnKey,
858
- spawnPath: childSpawnPath,
859
- parentSpawnPath: parentSpawnPath || null,
860
- spawnDepth: childDepth,
861
- }, config).catch(() => {
862
- /* best-effort */
863
- });
864
- return `Agent "${destName}" completed but output was lost due to stream closure.`;
865
- }
866
- console.error(`[MultiAgentGraph] Handoff FAILED "${sourceAgentId}" -> "${destination}" ` +
867
- `spawnKey=${spawnKey} (${durationMs}ms): ${errMsg}`);
868
- events.safeDispatchCustomEvent(_enum.GraphEvents.ON_AGENT_TRANSITION, {
869
- sourceAgentId: destination,
870
- sourceAgentName: destName,
871
- destinationAgentId: sourceAgentId,
872
- destinationAgentName: this.agentContexts.get(sourceAgentId)?.name ??
873
- sourceAgentId,
874
- edgeType: _enum.EdgeType.HANDOFF,
875
- timestamp: Date.now(),
876
- isCompletion: true,
877
- durationMs,
878
- spawnKey,
879
- spawnPath: childSpawnPath,
880
- parentSpawnPath: parentSpawnPath || null,
881
- spawnDepth: childDepth,
882
- error: errMsg,
883
- }, config).catch(() => {
884
- /* best-effort */
885
- });
886
- return `Agent "${destName}" failed after ${durationMs}ms: ${errMsg}`;
887
- }
888
- }, {
889
- name: toolName,
890
- schema: {
891
- type: 'object',
892
- properties: {
893
- [promptKey]: {
894
- type: 'string',
895
- description: promptInputDescription,
896
- },
897
- },
898
- required: [promptKey],
899
- },
900
- description: toolDescription,
901
- }));
902
- }
903
- return tools$1;
904
- }
905
- /**
906
- * Extract the final text result from a child agent's output messages.
907
- * Walks backwards to find the last AIMessage with text content.
908
- * Handles both string content and array content (multi-modal messages).
909
- * @param messages - The child agent's output messages
910
- * @param agentId - The child agent ID (for fallback message)
911
- */
912
- static extractHandoffResult(messages, agentId) {
913
- for (let i = messages.length - 1; i >= 0; i--) {
914
- const msg = messages[i];
915
- if (msg.getType() !== 'ai')
916
- continue;
917
- const content = msg.content;
918
- if (typeof content === 'string' && content.trim()) {
919
- return content.trim();
920
- }
921
- /** Handle array content (multi-modal messages with text blocks) */
922
- if (Array.isArray(content)) {
923
- const textParts = content
924
- .filter((block) => typeof block === 'object' &&
925
- block !== null &&
926
- 'type' in block &&
927
- block.type === 'text' &&
928
- 'text' in block &&
929
- typeof block.text === 'string')
930
- .map((block) => block.text);
931
- const text = textParts.join('\n').trim();
932
- if (text)
933
- return text;
934
- }
935
- }
936
- return `[Agent "${agentId}" completed but produced no text output]`;
937
- }
938
- /**
939
- * Truncate handoff result using head/tail strategy (60/40 split).
940
- * Preserves the beginning (key findings) and end (conclusions).
941
- * Matches the TaskTool.truncateResult pattern used by host orchestrators.
942
- * @param result - The full result text
943
- * @param maxChars - Maximum allowed characters
944
- */
945
- static truncateHandoffResult(result, maxChars) {
946
- if (!result || result.length <= maxChars) {
947
- return result;
948
- }
949
- const truncationNotice = '\n\n[... handoff output truncated — middle section omitted to fit parent context ...]\n\n';
950
- const available = maxChars - truncationNotice.length;
951
- if (available <= 0) {
952
- return result.substring(0, maxChars);
953
- }
954
- const headSize = Math.floor(available * 0.6);
955
- const tailSize = available - headSize;
956
- return (result.substring(0, headSize) +
957
- truncationNotice +
958
- result.substring(result.length - tailSize));
959
- }
960
- /**
961
- * Build a meaningful default description for a handoff tool.
962
- * @param destContext - AgentContext of the destination agent
963
- * @param destinationId - Raw agent ID (fallback)
964
- */
965
- buildDefaultHandoffDescription(destContext, destinationId) {
966
- const displayName = destContext?.name ?? destinationId;
967
- const agentDescription = destContext?.description;
968
- if (agentDescription != null && agentDescription !== '') {
969
- return `Hand off task to "${displayName}": ${agentDescription}. The agent will execute and return its result.`;
970
- }
971
- return `Hand off task to "${displayName}" and receive its result.`;
972
- }
973
454
  /**
974
455
  * Create a complete agent subgraph (similar to createReactAgent)
975
456
  */
976
457
  createAgentSubgraph(agentId) {
977
- /**
978
- * Scoped subgraph build for handoff targets.
979
- *
980
- * If the handoff target has outgoing sequence/transfer edges (e.g. a
981
- * "researcher" agent with its own sequence `[researcher → prod_assistant]`),
982
- * we compile a mini-StateGraph containing the agent and all agents reachable
983
- * from it via non-handoff edges. This way, when the parent hands off to
984
- * researcher via `subgraph.invoke()`, the nested sequence runs to completion
985
- * before the result is returned to the parent.
986
- *
987
- * Fast path: if no downstream agents are reachable, fall back to the
988
- * previous single-node behavior (`createAgentNode`).
989
- *
990
- * See docs/multi-agent-nesting-architecture.md §6.
991
- */
992
- const reachable = this.computeReachableViaNonHandoff(agentId);
993
- if (reachable.size === 1) {
994
- return this.createAgentNode(agentId);
995
- }
996
- logging.mlog(`[MultiAgentGraph] Scoped subgraph for "${agentId}": ${reachable.size} nodes [${Array.from(reachable).join(', ')}]`);
997
- return this.buildScopedSubgraph(agentId, reachable);
998
- }
999
- /**
1000
- * BFS from `rootAgentId` across sequence + transfer edges (NOT handoff edges).
1001
- * Returns the set of agents reachable in this agent's "local workflow".
1002
- */
1003
- computeReachableViaNonHandoff(rootAgentId) {
1004
- const reachable = new Set([rootAgentId]);
1005
- const queue = [rootAgentId];
1006
- const localEdges = [...this.sequenceEdges, ...this.transferEdges];
1007
- while (queue.length > 0) {
1008
- const current = queue.shift();
1009
- for (const edge of localEdges) {
1010
- const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
1011
- if (!sources.includes(current))
1012
- continue;
1013
- const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
1014
- for (const dest of dests) {
1015
- if (!reachable.has(dest) && this.agentContexts.has(dest)) {
1016
- reachable.add(dest);
1017
- queue.push(dest);
1018
- }
1019
- }
1020
- }
1021
- }
1022
- return reachable;
1023
- }
1024
- /**
1025
- * Build a compiled scoped StateGraph containing `agentIds` as nodes, rooted
1026
- * at `rootAgentId`. Linear sequence edges where both endpoints are in scope
1027
- * are wired directly; nodes with no outgoing in-scope edges route to END.
1028
- *
1029
- * Each node is wrapped around the per-agent `createAgentNode` compiled
1030
- * workflow (agent + tools loop) to preserve isolated tool context.
1031
- */
1032
- buildScopedSubgraph(rootAgentId, agentIds) {
1033
- const StateAnnotation = langgraph.Annotation.Root({
1034
- messages: langgraph.Annotation({
1035
- reducer: langgraph.messagesStateReducer,
1036
- default: () => [],
1037
- }),
1038
- });
1039
- const builder = new langgraph.StateGraph(StateAnnotation);
1040
- // Precompile each scoped agent's inner workflow and wrap as a node.
1041
- //
1042
- // Two different isolation strategies depending on position:
1043
- //
1044
- // • ROOT node (the handoff target itself): receives the parent
1045
- // orchestrator's handoff frame. Use `prepareHandoffMessages` — drops
1046
- // orphaned tool_use, compacts paired tool calls, guarantees trailing
1047
- // HumanMessage for Bedrock/VertexAI compatibility. The root needs
1048
- // orchestrator context because it's responding to the handoff.
1049
- //
1050
- // • DOWNSTREAM nodes (sequence targets of the root): run as FULLY
1051
- // ISOLATED child sessions. They receive only:
1052
- // [original user request, synthetic HumanMessage describing what
1053
- // the upstream agent produced and asking them to act]
1054
- // No raw tool_use / tool_result blocks from the upstream agent —
1055
- // prevents schema confusion when a downstream agent sees noisy
1056
- // upstream context and produces malformed tool_use JSON.
1057
- //
1058
- // Each wrapper returns only the DELTA (new messages produced by the
1059
- // inner invoke), not the prepared input — otherwise messagesStateReducer
1060
- // would double-append the synthetic instruction into the scoped state.
1061
- for (const aid of agentIds) {
1062
- const inner = this.createAgentNode(aid);
1063
- const isRoot = aid === rootAgentId;
1064
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1065
- builder.addNode(aid, async (state, config) => {
1066
- const prepared = isRoot
1067
- ? MultiAgentGraph.prepareHandoffMessages(state.messages)
1068
- : MultiAgentGraph.prepareIsolatedChildMessages(state.messages);
1069
- logging.mlog(`[MultiAgentGraph] scoped node "${aid}" entering (isRoot=${isRoot}, stateMessages=${state.messages.length}, prepared=${prepared.length})`);
1070
- const result = await inner.invoke({ ...state, messages: prepared }, config);
1071
- // Return only the messages the inner node appended beyond its input,
1072
- // so messagesStateReducer doesn't duplicate the synthetic wrapper
1073
- // prompt into the scoped state.
1074
- const delta = result.messages.length > prepared.length
1075
- ? result.messages.slice(prepared.length)
1076
- : result.messages;
1077
- return { messages: delta };
1078
- });
1079
- }
1080
- // START → root
1081
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1082
- // @ts-ignore — LangGraph string typing is too strict for dynamic agent ids
1083
- builder.addEdge(langgraph.START, rootAgentId);
1084
- // Wire sequence edges in scope (linear chain support)
1085
- const hasOutgoing = new Set();
1086
- for (const edge of this.sequenceEdges) {
1087
- const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
1088
- const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
1089
- for (const source of sources) {
1090
- if (!agentIds.has(source))
1091
- continue;
1092
- for (const dest of dests) {
1093
- if (!agentIds.has(dest))
1094
- continue;
1095
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1096
- // @ts-ignore
1097
- builder.addEdge(source, dest);
1098
- hasOutgoing.add(source);
1099
- }
1100
- }
1101
- }
1102
- // Leaves (no outgoing in-scope edges) route to END
1103
- for (const aid of agentIds) {
1104
- if (!hasOutgoing.has(aid)) {
1105
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1106
- // @ts-ignore
1107
- builder.addEdge(aid, langgraph.END);
1108
- }
1109
- }
1110
- return builder.compile(this.compileOptions);
458
+ /** This is essentially the same as `createAgentNode` from `StandardGraph` */
459
+ return this.createAgentNode(agentId);
1111
460
  }
1112
461
  /**
1113
462
  * Detects if the current agent is receiving a handoff and processes the messages accordingly.
@@ -1121,23 +470,7 @@ class MultiAgentGraph extends Graph.StandardGraph {
1121
470
  * @param agentId - The agent ID to check for handoff reception
1122
471
  * @returns Object with filtered messages, extracted instructions, source agent, and parallel siblings
1123
472
  */
1124
- /**
1125
- * Prepare messages for a handoff child agent. See
1126
- * {@link prepareHandoffMessagesUtil} for the full implementation and
1127
- * semantics — this static method is a thin delegate preserved for
1128
- * backward compatibility with existing call sites and unit tests.
1129
- */
1130
- static prepareHandoffMessages(messages) {
1131
- return childAgentContext.prepareHandoffMessages(messages);
1132
- }
1133
- /**
1134
- * Build an isolated message context for a downstream scoped-subgraph
1135
- * node. See {@link prepareIsolatedChildMessagesUtil} for details.
1136
- */
1137
- static prepareIsolatedChildMessages(messages) {
1138
- return childAgentContext.prepareIsolatedChildMessages(messages);
1139
- }
1140
- processTransferReception(messages$1, agentId) {
473
+ processHandoffReception(messages$1, agentId) {
1141
474
  if (messages$1.length === 0)
1142
475
  return null;
1143
476
  /**
@@ -1166,9 +499,8 @@ class MultiAgentGraph extends Graph.StandardGraph {
1166
499
  destinationAgent = toolName.replace(_enum.Constants.LC_TRANSFER_TO_, '');
1167
500
  }
1168
501
  else if (isConditionalTransfer) {
1169
- const transferDest = candidateMsg.additional_kwargs.handoff_destination;
1170
- destinationAgent =
1171
- typeof transferDest === 'string' ? transferDest : null;
502
+ const handoffDest = candidateMsg.additional_kwargs.handoff_destination;
503
+ destinationAgent = typeof handoffDest === 'string' ? handoffDest : null;
1172
504
  }
1173
505
  /** Check if this transfer targets our agent */
1174
506
  if (destinationAgent === agentId) {
@@ -1184,7 +516,7 @@ class MultiAgentGraph extends Graph.StandardGraph {
1184
516
  const contentStr = typeof toolMessage.content === 'string'
1185
517
  ? toolMessage.content
1186
518
  : JSON.stringify(toolMessage.content);
1187
- const instructionsMatch = contentStr.match(TRANSFER_INSTRUCTIONS_PATTERN);
519
+ const instructionsMatch = contentStr.match(HANDOFF_INSTRUCTIONS_PATTERN);
1188
520
  const instructions = instructionsMatch?.[1]?.trim() ?? null;
1189
521
  /** Extract source agent name from additional_kwargs */
1190
522
  const handoffSourceName = toolMessage.additional_kwargs.handoff_source_name;
@@ -1242,13 +574,9 @@ class MultiAgentGraph extends Graph.StandardGraph {
1242
574
  if (hasTransferCalls) {
1243
575
  if (remainingToolCalls.length > 0 ||
1244
576
  (typeof aiMsg.content === 'string' && aiMsg.content.trim())) {
1245
- /** Keep the message but without transfer tool calls.
1246
- * Trim trailing whitespace to prevent Bedrock validation errors. */
1247
- const trimmedContent = typeof aiMsg.content === 'string'
1248
- ? aiMsg.content.trimEnd()
1249
- : aiMsg.content;
577
+ /** Keep the message but without transfer tool calls */
1250
578
  const filteredAiMsg = new messages.AIMessage({
1251
- content: trimmedContent,
579
+ content: aiMsg.content,
1252
580
  tool_calls: remainingToolCalls,
1253
581
  id: aiMsg.id,
1254
582
  });
@@ -1262,107 +590,15 @@ class MultiAgentGraph extends Graph.StandardGraph {
1262
590
  /** Keep all other messages */
1263
591
  filteredMessages.push(msg);
1264
592
  }
1265
- /**
1266
- * Flatten tool call/result pairs into text summaries for handoff.
1267
- *
1268
- * When agent A uses tools and then hands off to agent B, agent B may not
1269
- * have the same tools configured. Providers like Bedrock require toolConfig
1270
- * when tool_use/tool_result blocks are in the message history. Converting
1271
- * tool interactions to text summaries avoids this and reduces context bloat.
1272
- *
1273
- * Strategy: Walk through messages and merge each (AIMessage-with-tool_calls +
1274
- * following ToolMessages) group into a single AIMessage containing the original
1275
- * text plus a textual summary of the tool interaction. This preserves proper
1276
- * message role ordering (human/assistant alternation).
1277
- */
1278
- const compactedMessages = [];
1279
- for (let i = 0; i < filteredMessages.length; i++) {
1280
- const msg = filteredMessages[i];
1281
- const msgType = msg.getType();
1282
- if (msgType === 'ai') {
1283
- const aiMsg = msg;
1284
- const toolCalls = aiMsg.tool_calls;
1285
- if (toolCalls && toolCalls.length > 0) {
1286
- /** Extract text content from the AIMessage */
1287
- const textContent = typeof aiMsg.content === 'string'
1288
- ? aiMsg.content
1289
- : Array.isArray(aiMsg.content)
1290
- ? aiMsg.content
1291
- .filter((b) => typeof b === 'object' &&
1292
- b.type === 'text' &&
1293
- 'text' in b)
1294
- .map((b) => b.text)
1295
- .join('\n')
1296
- : '';
1297
- /** Collect tool_call_ids so we can match following ToolMessages */
1298
- const callIds = new Set(toolCalls.map((tc) => tc.id).filter(Boolean));
1299
- /** Build summary of what tools were called */
1300
- const callSummaries = toolCalls.map((tc) => `[Called "${tc.name}"]`);
1301
- /** Consume following ToolMessages that belong to this AI message */
1302
- const resultSummaries = [];
1303
- while (i + 1 < filteredMessages.length) {
1304
- const next = filteredMessages[i + 1];
1305
- if (next.getType() !== 'tool')
1306
- break;
1307
- const toolMsg = next;
1308
- if (!callIds.has(toolMsg.tool_call_id))
1309
- break;
1310
- /** Extract and summarize the tool result */
1311
- const rawContent = typeof toolMsg.content === 'string'
1312
- ? toolMsg.content
1313
- : Array.isArray(toolMsg.content)
1314
- ? toolMsg.content
1315
- .filter((b) => typeof b === 'object' &&
1316
- 'text' in b &&
1317
- typeof b.text ===
1318
- 'string')
1319
- .map((b) => b.text)
1320
- .join('\n')
1321
- : JSON.stringify(toolMsg.content);
1322
- const summary = rawContent.length > 500
1323
- ? rawContent.split('\n')[0] + ' [truncated for handoff]'
1324
- : rawContent;
1325
- resultSummaries.push(`[Tool "${toolMsg.name}" returned: ${summary}]`);
1326
- i++; // Skip this ToolMessage in the outer loop
1327
- }
1328
- /** Merge everything into a single AIMessage */
1329
- const parts = [
1330
- textContent,
1331
- ...callSummaries,
1332
- ...resultSummaries,
1333
- ].filter(Boolean);
1334
- /** Bedrock rejects messages with trailing whitespace */
1335
- const mergedContent = (parts.join('\n') || '[Agent processed tools]').trimEnd();
1336
- compactedMessages.push(new messages.AIMessage({
1337
- content: mergedContent,
1338
- id: aiMsg.id,
1339
- }));
1340
- continue;
1341
- }
1342
- }
1343
- /** Skip orphaned ToolMessages (their AI parent was already handled above,
1344
- * or they belong to a transfer that was already filtered out) */
1345
- if (msgType === 'tool') {
1346
- continue;
1347
- }
1348
- /** Trim trailing whitespace on AI messages to prevent Bedrock validation errors */
1349
- if (msgType === 'ai' &&
1350
- typeof msg.content === 'string' &&
1351
- msg.content !== msg.content.trimEnd()) {
1352
- compactedMessages.push(new messages.AIMessage({ content: msg.content.trimEnd(), id: msg.id }));
1353
- continue;
1354
- }
1355
- compactedMessages.push(msg);
1356
- }
1357
593
  return {
1358
- filteredMessages: compactedMessages,
594
+ filteredMessages,
1359
595
  instructions,
1360
596
  sourceAgentName,
1361
597
  parallelSiblings,
1362
598
  };
1363
599
  }
1364
600
  /**
1365
- * Create the multi-agent workflow with handoffs, transfers, and sequences
601
+ * Create the multi-agent workflow with dynamic handoffs
1366
602
  */
1367
603
  createWorkflow() {
1368
604
  const StateAnnotation = langgraph.Annotation.Root({
@@ -1385,119 +621,53 @@ class MultiAgentGraph extends Graph.StandardGraph {
1385
621
  }),
1386
622
  });
1387
623
  const builder = new langgraph.StateGraph(StateAnnotation);
1388
- /**
1389
- * Identify agents that are ONLY handoff destinations (not transfer/sequence
1390
- * destinations and not starting nodes). These agents are invoked inline via
1391
- * subgraph.invoke() inside handoff tools — they must NOT be added as
1392
- * top-level nodes in the parent graph because LangGraph validates that all
1393
- * nodes are reachable from START via edges.
1394
- */
1395
- const handoffOnlyDestinations = new Set();
1396
- const transferOrSequenceDestinations = new Set();
1397
- for (const edge of this.handoffEdges) {
1398
- const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
1399
- dests.forEach((d) => handoffOnlyDestinations.add(d));
1400
- }
1401
- for (const edge of [...this.transferEdges, ...this.sequenceEdges]) {
1402
- const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
1403
- dests.forEach((d) => transferOrSequenceDestinations.add(d));
1404
- }
1405
- // Remove agents that are also transfer/sequence destinations or starting nodes
1406
- for (const d of transferOrSequenceDestinations) {
1407
- handoffOnlyDestinations.delete(d);
1408
- }
1409
- for (const startNode of this.startingNodes) {
1410
- handoffOnlyDestinations.delete(startNode);
1411
- }
1412
- /**
1413
- * Nested-sequence expansion: for each handoff-only target, its downstream
1414
- * sequence/transfer agents MUST also become handoff-only — they exist only
1415
- * inside the target's scoped subgraph, not at top level. Without this,
1416
- * those downstream nodes would be added as top-level orphans and LangGraph
1417
- * would fail compilation (UNREACHABLE_NODE).
1418
- *
1419
- * See docs/multi-agent-nesting-architecture.md §6.
1420
- */
1421
- const nestedHandoffOnly = new Set();
1422
- for (const target of handoffOnlyDestinations) {
1423
- const reachable = this.computeReachableViaNonHandoff(target);
1424
- for (const agent of reachable) {
1425
- if (agent === target)
1426
- continue;
1427
- // Skip if this agent is legitimately a top-level starting node
1428
- if (this.startingNodes.has(agent))
1429
- continue;
1430
- nestedHandoffOnly.add(agent);
1431
- }
1432
- }
1433
- for (const agent of nestedHandoffOnly) {
1434
- handoffOnlyDestinations.add(agent);
1435
- }
1436
- if (nestedHandoffOnly.size > 0) {
1437
- logging.mlog(`[MultiAgentGraph] Nested handoff-only (scoped subgraph downstream): [${Array.from(nestedHandoffOnly).join(', ')}]`);
1438
- }
1439
- if (handoffOnlyDestinations.size > 0) {
1440
- logging.mlog(`[MultiAgentGraph] Handoff-only children (subgraph only, no top-level node): [${Array.from(handoffOnlyDestinations).join(', ')}]`);
1441
- }
1442
- // Add agents as nodes — skip handoff-only children (they exist as subgraphs only)
624
+ // Add all agents as complete subgraphs
1443
625
  for (const [agentId] of this.agentContexts) {
1444
626
  // Get all possible destinations for this agent
1445
- const transferDestinations = new Set();
1446
- const sequenceDestinations = new Set();
1447
- // Check transfer edges for destinations
1448
- for (const edge of this.transferEdges) {
627
+ const handoffDestinations = new Set();
628
+ const directDestinations = new Set();
629
+ // Check handoff edges for destinations
630
+ for (const edge of this.handoffEdges) {
1449
631
  const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
1450
632
  if (sources.includes(agentId) === true) {
1451
633
  const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
1452
- dests.forEach((dest) => transferDestinations.add(dest));
634
+ dests.forEach((dest) => handoffDestinations.add(dest));
1453
635
  }
1454
636
  }
1455
- // Check sequence edges for destinations
1456
- for (const edge of this.sequenceEdges) {
637
+ // Check direct edges for destinations
638
+ for (const edge of this.directEdges) {
1457
639
  const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
1458
640
  if (sources.includes(agentId) === true) {
1459
641
  const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
1460
- dests.forEach((dest) => sequenceDestinations.add(dest));
642
+ dests.forEach((dest) => directDestinations.add(dest));
1461
643
  }
1462
644
  }
1463
- /** Check if this agent has BOTH transfer and sequence edges */
1464
- const hasTransferEdges = transferDestinations.size > 0;
1465
- const hasSequenceEdges = sequenceDestinations.size > 0;
1466
- const needsCommandRouting = hasTransferEdges && hasSequenceEdges;
645
+ /** Check if this agent has BOTH handoff and direct edges */
646
+ const hasHandoffEdges = handoffDestinations.size > 0;
647
+ const hasDirectEdges = directDestinations.size > 0;
648
+ const needsCommandRouting = hasHandoffEdges && hasDirectEdges;
1467
649
  /** Collect all possible destinations for this agent */
1468
650
  const allDestinations = new Set([
1469
- ...transferDestinations,
1470
- ...sequenceDestinations,
651
+ ...handoffDestinations,
652
+ ...directDestinations,
1471
653
  ]);
1472
- if (transferDestinations.size > 0 || sequenceDestinations.size === 0) {
654
+ if (handoffDestinations.size > 0 || directDestinations.size === 0) {
1473
655
  allDestinations.add(langgraph.END);
1474
656
  }
1475
657
  /** Agent subgraph (includes agent + tools) */
1476
658
  const agentSubgraph = this.createAgentSubgraph(agentId);
1477
- /** Register subgraph for handoff tools (lazy reference resolution) */
1478
- this.subgraphRegistry.set(agentId, agentSubgraph);
1479
- /**
1480
- * Handoff-only children are invoked inline via subgraph.invoke() — they
1481
- * don't need a top-level node. Adding them would cause LangGraph to reject
1482
- * the graph because no edge routes to them (UNREACHABLE_NODE).
1483
- */
1484
- if (handoffOnlyDestinations.has(agentId)) {
1485
- continue;
1486
- }
1487
659
  /** Wrapper function that handles agentMessages channel, handoff reception, and conditional routing */
1488
660
  const agentWrapper = async (state, config) => {
1489
- logging.mlog(`[MultiAgentGraph] Agent "${agentId}" wrapper ENTRY (messages: ${state.messages.length}, needsCommandRouting: ${needsCommandRouting})`);
1490
661
  let result;
1491
662
  /**
1492
- * Check if this agent is receiving a transfer.
663
+ * Check if this agent is receiving a handoff.
1493
664
  * If so, filter out the transfer messages and inject instructions as preamble.
1494
665
  * This prevents the receiving agent from seeing the transfer as "completed work"
1495
666
  * and prematurely producing an end token.
1496
667
  */
1497
- const transferContext = this.processTransferReception(state.messages, agentId);
1498
- if (transferContext !== null) {
1499
- const { filteredMessages, instructions, sourceAgentName, parallelSiblings, } = transferContext;
1500
- logging.mlog(`[MultiAgentGraph] Agent "${agentId}" receiving transfer from "${sourceAgentName}" (instructions: ${instructions != null}, parallelSiblings: ${parallelSiblings.length})`);
668
+ const handoffContext = this.processHandoffReception(state.messages, agentId);
669
+ if (handoffContext !== null) {
670
+ const { filteredMessages, instructions, sourceAgentName, parallelSiblings, } = handoffContext;
1501
671
  /**
1502
672
  * Set handoff context on the receiving agent.
1503
673
  * Uses pre-computed graph position for depth and parallel info.
@@ -1611,124 +781,24 @@ class MultiAgentGraph extends Graph.StandardGraph {
1611
781
  else {
1612
782
  result = await agentSubgraph.invoke(state, config);
1613
783
  }
1614
- /** Track the last agent that produced output for continuation support */
1615
- this.lastActiveAgentId = agentId;
1616
- logging.mlog(`[MultiAgentGraph] Agent "${agentId}" wrapper EXIT (result messages: ${result.messages.length})`);
1617
- /** If agent has both transfer and sequence edges, use Command for exclusive routing */
784
+ /** If agent has both handoff and direct edges, use Command for exclusive routing */
1618
785
  if (needsCommandRouting) {
1619
- /** Check if a transfer occurred */
786
+ /** Check if a handoff occurred */
1620
787
  const lastMessage = result.messages[result.messages.length - 1];
1621
788
  if (lastMessage != null &&
1622
789
  lastMessage.getType() === 'tool' &&
1623
790
  typeof lastMessage.name === 'string' &&
1624
791
  lastMessage.name.startsWith(_enum.Constants.LC_TRANSFER_TO_)) {
1625
- /** Transfer occurred - extract destination and navigate there exclusively */
1626
- const transferDest = lastMessage.name.replace(_enum.Constants.LC_TRANSFER_TO_, '');
1627
- logging.mlog(`[MultiAgentGraph] Command routing: "${agentId}" -> transfer to "${transferDest}" (sequence edges skipped: [${Array.from(sequenceDestinations).join(', ')}])`);
1628
- /** Validate destination agent exists */
1629
- if (!this.agentContexts.has(transferDest)) {
1630
- const availableAgents = Array.from(this.agentContexts.keys()).join(', ');
1631
- console.error(`[MultiAgentGraph] Transfer to non-existent agent "${transferDest}". Available: ${availableAgents}`);
1632
- /** Return error to model so it can self-correct */
1633
- const errorMsg = new messages.ToolMessage({
1634
- content: `Transfer failed: agent "${transferDest}" does not exist. Available agents: ${availableAgents}. Please choose a valid agent to transfer to.`,
1635
- tool_call_id: lastMessage.tool_call_id,
1636
- name: lastMessage.name,
1637
- });
1638
- errorMsg.status = 'error';
1639
- return {
1640
- messages: [...result.messages, errorMsg],
1641
- };
1642
- }
1643
- /** Pre-handoff context compaction: if receiving agent has smaller budget */
1644
- const receiverContext = this.agentContexts.get(transferDest);
1645
- const senderContext = this.agentContexts.get(agentId);
1646
- if (receiverContext?.maxContextTokens != null &&
1647
- senderContext?.tokenCounter != null &&
1648
- receiverContext.maxContextTokens > 0) {
1649
- let currentSize = 0;
1650
- for (const msg of result.messages) {
1651
- currentSize += senderContext.tokenCounter(msg);
1652
- }
1653
- const receiverBudget = receiverContext.maxContextTokens;
1654
- if (currentSize > receiverBudget * 0.7) {
1655
- logging.mwarn(`[MultiAgentGraph] Pre-handoff compaction: context (${currentSize} tokens) exceeds ` +
1656
- `70% of receiver "${transferDest}" budget (${receiverBudget} tokens)`);
1657
- /** Generate handoff briefing */
1658
- const senderName = senderContext.name ?? agentId;
1659
- if (senderContext.summarizeCallback) {
1660
- try {
1661
- const briefingResult = await summarize.summarize(result.messages, async (prompt, _maxTokens) => senderContext.summarizeCallback([
1662
- new messages.HumanMessage(prompt),
1663
- ]), {
1664
- tokenCounter: senderContext.tokenCounter,
1665
- summaryBudget: Math.floor(receiverBudget * 0.2),
1666
- isMultiAgent: true,
1667
- agentWorkflowState: {
1668
- currentAgentId: transferDest,
1669
- agentChain: [agentId, transferDest],
1670
- pendingAgents: [],
1671
- },
1672
- });
1673
- const briefingMsg = new messages.SystemMessage(`[Handoff Briefing from "${senderName}"]\n${briefingResult.summary}`);
1674
- /** Replace messages with briefing + last 3 messages */
1675
- const keepCount = Math.min(3, result.messages.length);
1676
- result = {
1677
- ...result,
1678
- messages: [
1679
- briefingMsg,
1680
- ...result.messages.slice(result.messages.length - keepCount),
1681
- ],
1682
- };
1683
- console.info(`[MultiAgentGraph] Pre-handoff compaction complete: ${currentSize} tokens → briefing + ${keepCount} messages`);
1684
- }
1685
- catch (compactErr) {
1686
- console.error('[MultiAgentGraph] Pre-handoff compaction failed:', compactErr);
1687
- /** Continue without compaction — let receiver handle the overflow */
1688
- }
1689
- }
1690
- else {
1691
- /** No summary callback — use emergency summary */
1692
- const emergencySummary = summarize.createEmergencySummary(result.messages);
1693
- const briefingMsg = new messages.SystemMessage(`[Handoff Briefing from "${senderName}" — Emergency]\n${emergencySummary}`);
1694
- const keepCount = Math.min(3, result.messages.length);
1695
- result = {
1696
- ...result,
1697
- messages: [
1698
- briefingMsg,
1699
- ...result.messages.slice(result.messages.length - keepCount),
1700
- ],
1701
- };
1702
- }
1703
- }
1704
- }
1705
- await events.safeDispatchCustomEvent(_enum.GraphEvents.ON_AGENT_TRANSITION, {
1706
- sourceAgentId: agentId,
1707
- sourceAgentName: this.agentContexts.get(agentId)?.name ?? agentId,
1708
- destinationAgentId: transferDest,
1709
- destinationAgentName: this.agentContexts.get(transferDest)?.name ?? transferDest,
1710
- edgeType: _enum.EdgeType.TRANSFER,
1711
- timestamp: Date.now(),
1712
- }, config);
792
+ /** Handoff occurred - extract destination and navigate there exclusively */
793
+ const handoffDest = lastMessage.name.replace(_enum.Constants.LC_TRANSFER_TO_, '');
1713
794
  return new langgraph.Command({
1714
795
  update: result,
1715
- goto: transferDest,
796
+ goto: handoffDest,
1716
797
  });
1717
798
  }
1718
799
  else {
1719
- /** No transfer - proceed with sequence edges */
1720
- logging.mlog(`[MultiAgentGraph] Command routing: "${agentId}" -> no transfer, following sequence edges: [${Array.from(sequenceDestinations).join(', ')}]`);
1721
- const directDests = Array.from(sequenceDestinations);
1722
- for (const dest of directDests) {
1723
- await events.safeDispatchCustomEvent(_enum.GraphEvents.ON_AGENT_TRANSITION, {
1724
- sourceAgentId: agentId,
1725
- sourceAgentName: this.agentContexts.get(agentId)?.name ?? agentId,
1726
- destinationAgentId: dest,
1727
- destinationAgentName: this.agentContexts.get(dest)?.name ?? dest,
1728
- edgeType: _enum.EdgeType.SEQUENCE,
1729
- timestamp: Date.now(),
1730
- }, config);
1731
- }
800
+ /** No handoff - proceed with direct edges */
801
+ const directDests = Array.from(directDestinations);
1732
802
  if (directDests.length === 1) {
1733
803
  return new langgraph.Command({
1734
804
  update: result,
@@ -1744,30 +814,7 @@ class MultiAgentGraph extends Graph.StandardGraph {
1744
814
  }
1745
815
  }
1746
816
  }
1747
- /**
1748
- * No Command routing needed — dispatch ON_AGENT_TRANSITION for all
1749
- * destinations so callbacks.js can register child agents for event
1750
- * isolation BEFORE they start streaming.
1751
- */
1752
- const allDests = new Set([
1753
- ...transferDestinations,
1754
- ...sequenceDestinations,
1755
- ]);
1756
- if (allDests.size > 0) {
1757
- const edgeType = hasTransferEdges
1758
- ? _enum.EdgeType.TRANSFER
1759
- : _enum.EdgeType.SEQUENCE;
1760
- for (const dest of allDests) {
1761
- await events.safeDispatchCustomEvent(_enum.GraphEvents.ON_AGENT_TRANSITION, {
1762
- sourceAgentId: agentId,
1763
- sourceAgentName: this.agentContexts.get(agentId)?.name ?? agentId,
1764
- destinationAgentId: dest,
1765
- destinationAgentName: this.agentContexts.get(dest)?.name ?? dest,
1766
- edgeType,
1767
- timestamp: Date.now(),
1768
- }, config);
1769
- }
1770
- }
817
+ /** No special routing needed - return state normally */
1771
818
  return result;
1772
819
  };
1773
820
  /** Wrapped agent as a node with its possible destinations */
@@ -1775,85 +822,36 @@ class MultiAgentGraph extends Graph.StandardGraph {
1775
822
  ends: Array.from(allDestinations),
1776
823
  });
1777
824
  }
1778
- /**
1779
- * Add starting edges from START to entry agent(s).
1780
- *
1781
- * Multi-turn resumption: when `resumeFromAgentId` is set and refers to a
1782
- * valid agent in this graph, START routes exclusively to that agent so
1783
- * follow-up messages continue where the previous turn left off.
1784
- *
1785
- * Default behavior (no resume): static edges to all starting nodes,
1786
- * preserving parallel execution for graphs with multiple entry points.
1787
- */
1788
- const validResumeAgent = this.resumeFromAgentId != null &&
1789
- this.agentContexts.has(this.resumeFromAgentId);
1790
- if (validResumeAgent) {
1791
- const resumeAgentId = this.resumeFromAgentId;
1792
- logging.mlog(`[MultiAgentGraph] Multi-turn resumption: routing START → "${resumeAgentId}" (skipping default starting nodes: [${Array.from(this.startingNodes).join(', ')}])`);
1793
- /**
1794
- * Build route map containing both the resume agent and default starting
1795
- * nodes. This is required by LangGraph — all possible destinations must
1796
- * be declared even if the router always picks one.
1797
- */
1798
- const allPossibleStarts = new Set([...this.startingNodes, resumeAgentId]);
1799
- const routeMap = {};
1800
- for (const nodeId of allPossibleStarts) {
1801
- routeMap[nodeId] = nodeId;
1802
- }
1803
- builder.addConditionalEdges(langgraph.START, () => resumeAgentId, routeMap);
1804
- }
1805
- else {
1806
- if (this.resumeFromAgentId != null) {
1807
- logging.mwarn(`[MultiAgentGraph] resumeFromAgentId "${this.resumeFromAgentId}" not found in graph — falling back to default starting nodes`);
1808
- }
1809
- for (const startNode of this.startingNodes) {
1810
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1811
- /** @ts-ignore */
1812
- builder.addEdge(langgraph.START, startNode);
1813
- }
825
+ // Add starting edges for all starting nodes
826
+ for (const startNode of this.startingNodes) {
827
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
828
+ /** @ts-ignore */
829
+ builder.addEdge(langgraph.START, startNode);
1814
830
  }
1815
831
  /**
1816
- * Add approval gate nodes for sequence edges with approvalGate config.
1817
- * Gates are inserted between source and destination agents.
1818
- * They ALWAYS fire regardless of ExecutionContext.
832
+ * Add approval-gate nodes for sequence edges that declare an approvalGate
833
+ * config (Ranger-only feature, not present upstream). Gates fire
834
+ * regardless of ExecutionContext and sit between source and destination.
1819
835
  */
1820
836
  const gatedEdges = new Set();
1821
- for (const edge of this.sequenceEdges) {
1822
- if (!edge.approvalGate) {
837
+ for (const edge of this.directEdges) {
838
+ if (!edge.approvalGate)
1823
839
  continue;
1824
- }
1825
840
  const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
1826
841
  const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
1827
842
  for (const source of sources) {
1828
843
  for (const dest of destinations) {
1829
844
  const gateNodeId = ApprovalGateNode.getApprovalGateNodeId(edge.approvalGate.gateId);
1830
- const onDeny = edge.approvalGate.onDeny ?? 'stop';
1831
- // Add the gate node
1832
845
  const gateNode = ApprovalGateNode.createApprovalGateNode(edge.approvalGate, source, dest);
1833
846
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1834
847
  /** @ts-ignore */
1835
848
  builder.addNode(gateNodeId, gateNode);
1836
- // Wire: source → gate
1837
849
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1838
850
  /** @ts-ignore */
1839
851
  builder.addEdge(source, gateNodeId);
1840
- // Wire: gate → destination (always, since approval is handled
1841
- // by the interrupt/resume mechanism — if denied, the host
1842
- // can choose not to resume, or resume with approved=false
1843
- // and the gate returns empty state)
1844
- if (onDeny === 'skip') {
1845
- // Conditional edge: approved → destination, denied → END
1846
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1847
- /** @ts-ignore */
1848
- builder.addEdge(gateNodeId, dest);
1849
- }
1850
- else {
1851
- // Direct edge to destination — denial stops via non-resume or
1852
- // the host terminates the graph
1853
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1854
- /** @ts-ignore */
1855
- builder.addEdge(gateNodeId, dest);
1856
- }
852
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
853
+ /** @ts-ignore */
854
+ builder.addEdge(gateNodeId, dest);
1857
855
  }
1858
856
  }
1859
857
  gatedEdges.add(edge);
@@ -1861,26 +859,14 @@ class MultiAgentGraph extends Graph.StandardGraph {
1861
859
  /**
1862
860
  * Add sequence edges for automatic transitions
1863
861
  * Group edges by destination to handle fan-in scenarios
1864
- * Skip edges that have approval gates (already handled above)
862
+ * (Skip edges that already have an approval gate above.)
1865
863
  */
1866
864
  const edgesByDestination = new Map();
1867
- for (const edge of this.sequenceEdges) {
1868
- if (gatedEdges.has(edge)) {
1869
- continue;
1870
- }
1871
- /**
1872
- * Skip sequence edges where either endpoint lives only inside a scoped
1873
- * handoff subgraph. Those edges are wired inside `buildScopedSubgraph`,
1874
- * not at the top level — adding them here would reference non-existent
1875
- * top-level nodes and fail compilation.
1876
- */
1877
- const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
1878
- const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
1879
- const anyEndpointHandoffOnly = [...sources, ...dests].some((n) => handoffOnlyDestinations.has(n));
1880
- if (anyEndpointHandoffOnly) {
865
+ for (const edge of this.directEdges) {
866
+ if (gatedEdges.has(edge))
1881
867
  continue;
1882
- }
1883
- for (const destination of dests) {
868
+ const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
869
+ for (const destination of destinations) {
1884
870
  if (!edgesByDestination.has(destination)) {
1885
871
  edgesByDestination.set(destination, []);
1886
872
  }
@@ -1967,18 +953,17 @@ class MultiAgentGraph extends Graph.StandardGraph {
1967
953
  for (const edge of edges) {
1968
954
  const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
1969
955
  for (const source of sources) {
1970
- /** Check if this source node has both transfer and sequence edges */
1971
- const sourceTransferEdges = this.transferEdges.filter((e) => {
956
+ /** Check if this source node has both handoff and direct edges */
957
+ const sourceHandoffEdges = this.handoffEdges.filter((e) => {
1972
958
  const eSources = Array.isArray(e.from) ? e.from : [e.from];
1973
959
  return eSources.includes(source);
1974
960
  });
1975
- const sourceSequenceEdges = this.sequenceEdges.filter((e) => {
961
+ const sourceDirectEdges = this.directEdges.filter((e) => {
1976
962
  const eSources = Array.isArray(e.from) ? e.from : [e.from];
1977
963
  return eSources.includes(source);
1978
964
  });
1979
965
  /** Skip adding edge if source uses Command routing (has both types) */
1980
- if (sourceTransferEdges.length > 0 &&
1981
- sourceSequenceEdges.length > 0) {
966
+ if (sourceHandoffEdges.length > 0 && sourceDirectEdges.length > 0) {
1982
967
  continue;
1983
968
  }
1984
969
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment