@librechat/agents 3.4.7 → 3.5.1

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 (924) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +0 -356
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/agents/projection.cjs +0 -9
  4. package/dist/cjs/agents/projection.cjs.map +1 -1
  5. package/dist/cjs/common/constants.cjs +0 -26
  6. package/dist/cjs/common/constants.cjs.map +1 -1
  7. package/dist/cjs/common/enum.cjs +0 -85
  8. package/dist/cjs/common/enum.cjs.map +1 -1
  9. package/dist/cjs/events.cjs +0 -14
  10. package/dist/cjs/events.cjs.map +1 -1
  11. package/dist/cjs/graphs/Graph.cjs +1 -909
  12. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  13. package/dist/cjs/graphs/MultiAgentGraph.cjs +7 -272
  14. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
  15. package/dist/cjs/graphs/applyGraphRuntimeConfig.cjs.map +1 -1
  16. package/dist/cjs/graphs/createGraph.cjs.map +1 -1
  17. package/dist/cjs/hitl/askUserQuestion.cjs +0 -53
  18. package/dist/cjs/hitl/askUserQuestion.cjs.map +1 -1
  19. package/dist/cjs/hitl/askUserQuestions.cjs +0 -20
  20. package/dist/cjs/hitl/askUserQuestions.cjs.map +1 -1
  21. package/dist/cjs/hitl/askUserQuestionsInterrupt.cjs +0 -6
  22. package/dist/cjs/hitl/askUserQuestionsInterrupt.cjs.map +1 -1
  23. package/dist/cjs/hooks/HookRegistry.cjs +0 -127
  24. package/dist/cjs/hooks/HookRegistry.cjs.map +1 -1
  25. package/dist/cjs/hooks/createToolPolicyHook.cjs +0 -38
  26. package/dist/cjs/hooks/createToolPolicyHook.cjs.map +1 -1
  27. package/dist/cjs/hooks/createWorkspacePolicyHook.cjs +0 -77
  28. package/dist/cjs/hooks/createWorkspacePolicyHook.cjs.map +1 -1
  29. package/dist/cjs/hooks/executeHooks.cjs +0 -79
  30. package/dist/cjs/hooks/executeHooks.cjs.map +1 -1
  31. package/dist/cjs/hooks/index.cjs +0 -16
  32. package/dist/cjs/hooks/index.cjs.map +1 -1
  33. package/dist/cjs/hooks/matchers.cjs +0 -104
  34. package/dist/cjs/hooks/matchers.cjs.map +1 -1
  35. package/dist/cjs/hooks/types.cjs +0 -8
  36. package/dist/cjs/hooks/types.cjs.map +1 -1
  37. package/dist/cjs/instrumentation.cjs +0 -14
  38. package/dist/cjs/instrumentation.cjs.map +1 -1
  39. package/dist/cjs/langfuse.cjs +0 -75
  40. package/dist/cjs/langfuse.cjs.map +1 -1
  41. package/dist/cjs/langfuseConfig.cjs.map +1 -1
  42. package/dist/cjs/langfuseRuntimeContext.cjs +0 -13
  43. package/dist/cjs/langfuseRuntimeContext.cjs.map +1 -1
  44. package/dist/cjs/langfuseRuntimeScope.cjs +0 -4
  45. package/dist/cjs/langfuseRuntimeScope.cjs.map +1 -1
  46. package/dist/cjs/langfuseSpanRegistry.cjs +0 -28
  47. package/dist/cjs/langfuseSpanRegistry.cjs.map +1 -1
  48. package/dist/cjs/langfuseToolOutputTracing.cjs +0 -3
  49. package/dist/cjs/langfuseToolOutputTracing.cjs.map +1 -1
  50. package/dist/cjs/langfuseTraceShaping.cjs +0 -74
  51. package/dist/cjs/langfuseTraceShaping.cjs.map +1 -1
  52. package/dist/cjs/llm/anthropic/index.cjs +0 -3
  53. package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
  54. package/dist/cjs/llm/anthropic/types.cjs.map +1 -1
  55. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +1 -111
  56. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
  57. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +0 -1
  58. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
  59. package/dist/cjs/llm/anthropic/utils/stream_events.cjs +0 -8
  60. package/dist/cjs/llm/anthropic/utils/stream_events.cjs.map +1 -1
  61. package/dist/cjs/llm/anthropic/utils/tools.cjs.map +1 -1
  62. package/dist/cjs/llm/bedrock/cachePoints.cjs.map +1 -1
  63. package/dist/cjs/llm/bedrock/index.cjs +1 -95
  64. package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
  65. package/dist/cjs/llm/bedrock/toolCache.cjs.map +1 -1
  66. package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +0 -78
  67. package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
  68. package/dist/cjs/llm/bedrock/utils/message_outputs.cjs +0 -24
  69. package/dist/cjs/llm/bedrock/utils/message_outputs.cjs.map +1 -1
  70. package/dist/cjs/llm/contextOverflowRecovery.cjs +0 -62
  71. package/dist/cjs/llm/contextOverflowRecovery.cjs.map +1 -1
  72. package/dist/cjs/llm/fake.cjs.map +1 -1
  73. package/dist/cjs/llm/google/index.cjs +2 -21
  74. package/dist/cjs/llm/google/index.cjs.map +1 -1
  75. package/dist/cjs/llm/google/utils/common.cjs +0 -35
  76. package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
  77. package/dist/cjs/llm/init.cjs +0 -9
  78. package/dist/cjs/llm/init.cjs.map +1 -1
  79. package/dist/cjs/llm/invoke.cjs +1 -270
  80. package/dist/cjs/llm/invoke.cjs.map +1 -1
  81. package/dist/cjs/llm/mistral/index.cjs.map +1 -1
  82. package/dist/cjs/llm/openai/index.cjs +0 -99
  83. package/dist/cjs/llm/openai/index.cjs.map +1 -1
  84. package/dist/cjs/llm/openai/streamMetadata.cjs +0 -21
  85. package/dist/cjs/llm/openai/streamMetadata.cjs.map +1 -1
  86. package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
  87. package/dist/cjs/llm/openrouter/index.cjs +0 -1
  88. package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
  89. package/dist/cjs/llm/openrouter/toolCache.cjs +0 -6
  90. package/dist/cjs/llm/openrouter/toolCache.cjs.map +1 -1
  91. package/dist/cjs/llm/preempt.cjs +0 -75
  92. package/dist/cjs/llm/preempt.cjs.map +1 -1
  93. package/dist/cjs/llm/providers.cjs.map +1 -1
  94. package/dist/cjs/llm/request.cjs +0 -10
  95. package/dist/cjs/llm/request.cjs.map +1 -1
  96. package/dist/cjs/llm/stream/chunkAdapters.cjs +0 -62
  97. package/dist/cjs/llm/stream/chunkAdapters.cjs.map +1 -1
  98. package/dist/cjs/llm/stream/smoother.cjs +0 -58
  99. package/dist/cjs/llm/stream/smoother.cjs.map +1 -1
  100. package/dist/cjs/llm/streamLimits.cjs +4 -293
  101. package/dist/cjs/llm/streamLimits.cjs.map +1 -1
  102. package/dist/cjs/llm/truncation.cjs +0 -36
  103. package/dist/cjs/llm/truncation.cjs.map +1 -1
  104. package/dist/cjs/llm/vertexai/index.cjs +0 -330
  105. package/dist/cjs/llm/vertexai/index.cjs.map +1 -1
  106. package/dist/cjs/messages/alternation.cjs +0 -43
  107. package/dist/cjs/messages/alternation.cjs.map +1 -1
  108. package/dist/cjs/messages/anthropicToolCache.cjs +0 -45
  109. package/dist/cjs/messages/anthropicToolCache.cjs.map +1 -1
  110. package/dist/cjs/messages/assistantPhase.cjs +0 -12
  111. package/dist/cjs/messages/assistantPhase.cjs.map +1 -1
  112. package/dist/cjs/messages/budget.cjs +0 -9
  113. package/dist/cjs/messages/budget.cjs.map +1 -1
  114. package/dist/cjs/messages/cache.cjs +0 -172
  115. package/dist/cjs/messages/cache.cjs.map +1 -1
  116. package/dist/cjs/messages/content.cjs +0 -9
  117. package/dist/cjs/messages/content.cjs.map +1 -1
  118. package/dist/cjs/messages/contextPruning.cjs +0 -15
  119. package/dist/cjs/messages/contextPruning.cjs.map +1 -1
  120. package/dist/cjs/messages/contextPruningSettings.cjs +0 -3
  121. package/dist/cjs/messages/contextPruningSettings.cjs.map +1 -1
  122. package/dist/cjs/messages/core.cjs +0 -48
  123. package/dist/cjs/messages/core.cjs.map +1 -1
  124. package/dist/cjs/messages/format.cjs +1 -345
  125. package/dist/cjs/messages/format.cjs.map +1 -1
  126. package/dist/cjs/messages/handoffCue.cjs +0 -36
  127. package/dist/cjs/messages/handoffCue.cjs.map +1 -1
  128. package/dist/cjs/messages/ids.cjs.map +1 -1
  129. package/dist/cjs/messages/injected.cjs +0 -33
  130. package/dist/cjs/messages/injected.cjs.map +1 -1
  131. package/dist/cjs/messages/langchain.cjs +0 -14
  132. package/dist/cjs/messages/langchain.cjs.map +1 -1
  133. package/dist/cjs/messages/prune.cjs +1 -184
  134. package/dist/cjs/messages/prune.cjs.map +1 -1
  135. package/dist/cjs/messages/recency.cjs +0 -32
  136. package/dist/cjs/messages/recency.cjs.map +1 -1
  137. package/dist/cjs/messages/reducer.cjs +0 -30
  138. package/dist/cjs/messages/reducer.cjs.map +1 -1
  139. package/dist/cjs/messages/tools.cjs +0 -14
  140. package/dist/cjs/messages/tools.cjs.map +1 -1
  141. package/dist/cjs/openai/index.cjs.map +1 -1
  142. package/dist/cjs/prompts/activityLabel.cjs +9 -79
  143. package/dist/cjs/prompts/activityLabel.cjs.map +1 -1
  144. package/dist/cjs/responses/index.cjs.map +1 -1
  145. package/dist/cjs/run.cjs +2 -538
  146. package/dist/cjs/run.cjs.map +1 -1
  147. package/dist/cjs/session/AgentSession.cjs +1 -17
  148. package/dist/cjs/session/AgentSession.cjs.map +1 -1
  149. package/dist/cjs/session/JsonlSessionStore.cjs.map +1 -1
  150. package/dist/cjs/session/handlers.cjs +0 -7
  151. package/dist/cjs/session/handlers.cjs.map +1 -1
  152. package/dist/cjs/session/ids.cjs.map +1 -1
  153. package/dist/cjs/session/messageSerialization.cjs +0 -4
  154. package/dist/cjs/session/messageSerialization.cjs.map +1 -1
  155. package/dist/cjs/stream.cjs +1 -93
  156. package/dist/cjs/stream.cjs.map +1 -1
  157. package/dist/cjs/summarization/index.cjs +0 -27
  158. package/dist/cjs/summarization/index.cjs.map +1 -1
  159. package/dist/cjs/summarization/node.cjs +0 -273
  160. package/dist/cjs/summarization/node.cjs.map +1 -1
  161. package/dist/cjs/tools/BashExecutor.cjs +0 -35
  162. package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
  163. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +0 -24
  164. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
  165. package/dist/cjs/tools/Calculator.cjs.map +1 -1
  166. package/dist/cjs/tools/CodeExecutor.cjs +0 -13
  167. package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
  168. package/dist/cjs/tools/CodeSessionFileSummary.cjs.map +1 -1
  169. package/dist/cjs/tools/ProgrammaticToolCalling.cjs +0 -101
  170. package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
  171. package/dist/cjs/tools/ReadFile.cjs.map +1 -1
  172. package/dist/cjs/tools/SkillTool.cjs +0 -5
  173. package/dist/cjs/tools/SkillTool.cjs.map +1 -1
  174. package/dist/cjs/tools/SubagentTool.cjs +0 -10
  175. package/dist/cjs/tools/SubagentTool.cjs.map +1 -1
  176. package/dist/cjs/tools/ToolNode.cjs +6 -1038
  177. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  178. package/dist/cjs/tools/ToolSearch.cjs +0 -179
  179. package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
  180. package/dist/cjs/tools/cloudflare/CloudflareBridgeRuntime.cjs.map +1 -1
  181. package/dist/cjs/tools/cloudflare/CloudflareProgrammaticToolCalling.cjs.map +1 -1
  182. package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs +0 -39
  183. package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs.map +1 -1
  184. package/dist/cjs/tools/cloudflare/CloudflareSandboxTools.cjs.map +1 -1
  185. package/dist/cjs/tools/eagerEventExecution.cjs +0 -6
  186. package/dist/cjs/tools/eagerEventExecution.cjs.map +1 -1
  187. package/dist/cjs/tools/handlers.cjs +1 -41
  188. package/dist/cjs/tools/handlers.cjs.map +1 -1
  189. package/dist/cjs/tools/intentArg.cjs +1 -132
  190. package/dist/cjs/tools/intentArg.cjs.map +1 -1
  191. package/dist/cjs/tools/local/CompileCheckTool.cjs +0 -25
  192. package/dist/cjs/tools/local/CompileCheckTool.cjs.map +1 -1
  193. package/dist/cjs/tools/local/FileCheckpointer.cjs +0 -23
  194. package/dist/cjs/tools/local/FileCheckpointer.cjs.map +1 -1
  195. package/dist/cjs/tools/local/LocalCodingTools.cjs +0 -80
  196. package/dist/cjs/tools/local/LocalCodingTools.cjs.map +1 -1
  197. package/dist/cjs/tools/local/LocalExecutionEngine.cjs +0 -126
  198. package/dist/cjs/tools/local/LocalExecutionEngine.cjs.map +1 -1
  199. package/dist/cjs/tools/local/LocalExecutionTools.cjs.map +1 -1
  200. package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +0 -12
  201. package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -1
  202. package/dist/cjs/tools/local/attachments.cjs +0 -44
  203. package/dist/cjs/tools/local/attachments.cjs.map +1 -1
  204. package/dist/cjs/tools/local/bashAst.cjs +0 -16
  205. package/dist/cjs/tools/local/bashAst.cjs.map +1 -1
  206. package/dist/cjs/tools/local/editStrategies.cjs +0 -14
  207. package/dist/cjs/tools/local/editStrategies.cjs.map +1 -1
  208. package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs.map +1 -1
  209. package/dist/cjs/tools/local/syntaxCheck.cjs +0 -31
  210. package/dist/cjs/tools/local/syntaxCheck.cjs.map +1 -1
  211. package/dist/cjs/tools/local/textEncoding.cjs +0 -11
  212. package/dist/cjs/tools/local/textEncoding.cjs.map +1 -1
  213. package/dist/cjs/tools/local/workspaceFS.cjs +0 -33
  214. package/dist/cjs/tools/local/workspaceFS.cjs.map +1 -1
  215. package/dist/cjs/tools/ptcTimeout.cjs.map +1 -1
  216. package/dist/cjs/tools/schema.cjs +0 -8
  217. package/dist/cjs/tools/schema.cjs.map +1 -1
  218. package/dist/cjs/tools/search/anthropic.cjs +0 -9
  219. package/dist/cjs/tools/search/anthropic.cjs.map +1 -1
  220. package/dist/cjs/tools/search/content.cjs.map +1 -1
  221. package/dist/cjs/tools/search/crw-scraper.cjs +0 -33
  222. package/dist/cjs/tools/search/crw-scraper.cjs.map +1 -1
  223. package/dist/cjs/tools/search/crw-search.cjs +0 -2
  224. package/dist/cjs/tools/search/crw-search.cjs.map +1 -1
  225. package/dist/cjs/tools/search/firecrawl.cjs +0 -25
  226. package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
  227. package/dist/cjs/tools/search/format.cjs +0 -30
  228. package/dist/cjs/tools/search/format.cjs.map +1 -1
  229. package/dist/cjs/tools/search/highlights.cjs +0 -16
  230. package/dist/cjs/tools/search/highlights.cjs.map +1 -1
  231. package/dist/cjs/tools/search/keenable-scraper.cjs +0 -8
  232. package/dist/cjs/tools/search/keenable-scraper.cjs.map +1 -1
  233. package/dist/cjs/tools/search/keenable-search.cjs +0 -7
  234. package/dist/cjs/tools/search/keenable-search.cjs.map +1 -1
  235. package/dist/cjs/tools/search/rerankers.cjs +0 -35
  236. package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
  237. package/dist/cjs/tools/search/schema.cjs +0 -1
  238. package/dist/cjs/tools/search/schema.cjs.map +1 -1
  239. package/dist/cjs/tools/search/search.cjs +1 -14
  240. package/dist/cjs/tools/search/search.cjs.map +1 -1
  241. package/dist/cjs/tools/search/serper-scraper.cjs +0 -46
  242. package/dist/cjs/tools/search/serper-scraper.cjs.map +1 -1
  243. package/dist/cjs/tools/search/tavily-scraper.cjs.map +1 -1
  244. package/dist/cjs/tools/search/tavily-search.cjs.map +1 -1
  245. package/dist/cjs/tools/search/tool.cjs +0 -25
  246. package/dist/cjs/tools/search/tool.cjs.map +1 -1
  247. package/dist/cjs/tools/search/utils.cjs +0 -8
  248. package/dist/cjs/tools/search/utils.cjs.map +1 -1
  249. package/dist/cjs/tools/skillCatalog.cjs +0 -6
  250. package/dist/cjs/tools/skillCatalog.cjs.map +1 -1
  251. package/dist/cjs/tools/streamedToolCallSeals.cjs +0 -6
  252. package/dist/cjs/tools/streamedToolCallSeals.cjs.map +1 -1
  253. package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs +0 -2
  254. package/dist/cjs/tools/subagent/SubagentExecutionRegistry.cjs.map +1 -1
  255. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +3 -213
  256. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
  257. package/dist/cjs/tools/subagent/SubagentReplay.cjs.map +1 -1
  258. package/dist/cjs/tools/subagent/childGraphConfig.cjs +0 -4
  259. package/dist/cjs/tools/subagent/childGraphConfig.cjs.map +1 -1
  260. package/dist/cjs/tools/subagent/runtimeLimits.cjs.map +1 -1
  261. package/dist/cjs/tools/toolOutputReferences.cjs +1 -322
  262. package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -1
  263. package/dist/cjs/types/hitl.cjs +0 -5
  264. package/dist/cjs/types/hitl.cjs.map +1 -1
  265. package/dist/cjs/utils/callbacks.cjs.map +1 -1
  266. package/dist/cjs/utils/errors.cjs +14 -165
  267. package/dist/cjs/utils/errors.cjs.map +1 -1
  268. package/dist/cjs/utils/events.cjs +0 -10
  269. package/dist/cjs/utils/events.cjs.map +1 -1
  270. package/dist/cjs/utils/graph.cjs.map +1 -1
  271. package/dist/cjs/utils/handlers.cjs +0 -3
  272. package/dist/cjs/utils/handlers.cjs.map +1 -1
  273. package/dist/cjs/utils/llm.cjs +0 -1
  274. package/dist/cjs/utils/llm.cjs.map +1 -1
  275. package/dist/cjs/utils/misc.cjs +0 -16
  276. package/dist/cjs/utils/misc.cjs.map +1 -1
  277. package/dist/cjs/utils/proxy.cjs +0 -26
  278. package/dist/cjs/utils/proxy.cjs.map +1 -1
  279. package/dist/cjs/utils/run.cjs +0 -6
  280. package/dist/cjs/utils/run.cjs.map +1 -1
  281. package/dist/cjs/utils/schema.cjs +0 -5
  282. package/dist/cjs/utils/schema.cjs.map +1 -1
  283. package/dist/cjs/utils/title.cjs +0 -6
  284. package/dist/cjs/utils/title.cjs.map +1 -1
  285. package/dist/cjs/utils/tokens.cjs +0 -113
  286. package/dist/cjs/utils/tokens.cjs.map +1 -1
  287. package/dist/cjs/utils/toolContent.cjs +0 -41
  288. package/dist/cjs/utils/toolContent.cjs.map +1 -1
  289. package/dist/cjs/utils/truncation.cjs +0 -61
  290. package/dist/cjs/utils/truncation.cjs.map +1 -1
  291. package/dist/esm/agents/AgentContext.mjs +0 -356
  292. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  293. package/dist/esm/agents/projection.mjs +0 -9
  294. package/dist/esm/agents/projection.mjs.map +1 -1
  295. package/dist/esm/common/constants.mjs +0 -26
  296. package/dist/esm/common/constants.mjs.map +1 -1
  297. package/dist/esm/common/enum.mjs +0 -85
  298. package/dist/esm/common/enum.mjs.map +1 -1
  299. package/dist/esm/events.mjs +0 -14
  300. package/dist/esm/events.mjs.map +1 -1
  301. package/dist/esm/graphs/Graph.mjs +1 -909
  302. package/dist/esm/graphs/Graph.mjs.map +1 -1
  303. package/dist/esm/graphs/MultiAgentGraph.mjs +7 -272
  304. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  305. package/dist/esm/graphs/applyGraphRuntimeConfig.mjs.map +1 -1
  306. package/dist/esm/graphs/createGraph.mjs.map +1 -1
  307. package/dist/esm/hitl/askUserQuestion.mjs +0 -53
  308. package/dist/esm/hitl/askUserQuestion.mjs.map +1 -1
  309. package/dist/esm/hitl/askUserQuestions.mjs +0 -20
  310. package/dist/esm/hitl/askUserQuestions.mjs.map +1 -1
  311. package/dist/esm/hitl/askUserQuestionsInterrupt.mjs +0 -6
  312. package/dist/esm/hitl/askUserQuestionsInterrupt.mjs.map +1 -1
  313. package/dist/esm/hooks/HookRegistry.mjs +0 -127
  314. package/dist/esm/hooks/HookRegistry.mjs.map +1 -1
  315. package/dist/esm/hooks/createToolPolicyHook.mjs +0 -38
  316. package/dist/esm/hooks/createToolPolicyHook.mjs.map +1 -1
  317. package/dist/esm/hooks/createWorkspacePolicyHook.mjs +0 -77
  318. package/dist/esm/hooks/createWorkspacePolicyHook.mjs.map +1 -1
  319. package/dist/esm/hooks/executeHooks.mjs +0 -79
  320. package/dist/esm/hooks/executeHooks.mjs.map +1 -1
  321. package/dist/esm/hooks/index.mjs +0 -16
  322. package/dist/esm/hooks/index.mjs.map +1 -1
  323. package/dist/esm/hooks/matchers.mjs +0 -104
  324. package/dist/esm/hooks/matchers.mjs.map +1 -1
  325. package/dist/esm/hooks/types.mjs +0 -8
  326. package/dist/esm/hooks/types.mjs.map +1 -1
  327. package/dist/esm/instrumentation.mjs +0 -14
  328. package/dist/esm/instrumentation.mjs.map +1 -1
  329. package/dist/esm/langfuse.mjs +0 -75
  330. package/dist/esm/langfuse.mjs.map +1 -1
  331. package/dist/esm/langfuseConfig.mjs.map +1 -1
  332. package/dist/esm/langfuseRuntimeContext.mjs +0 -13
  333. package/dist/esm/langfuseRuntimeContext.mjs.map +1 -1
  334. package/dist/esm/langfuseRuntimeScope.mjs +0 -4
  335. package/dist/esm/langfuseRuntimeScope.mjs.map +1 -1
  336. package/dist/esm/langfuseSpanRegistry.mjs +0 -28
  337. package/dist/esm/langfuseSpanRegistry.mjs.map +1 -1
  338. package/dist/esm/langfuseToolOutputTracing.mjs +0 -3
  339. package/dist/esm/langfuseToolOutputTracing.mjs.map +1 -1
  340. package/dist/esm/langfuseTraceShaping.mjs +0 -74
  341. package/dist/esm/langfuseTraceShaping.mjs.map +1 -1
  342. package/dist/esm/llm/anthropic/index.mjs +0 -3
  343. package/dist/esm/llm/anthropic/index.mjs.map +1 -1
  344. package/dist/esm/llm/anthropic/types.mjs.map +1 -1
  345. package/dist/esm/llm/anthropic/utils/message_inputs.mjs +1 -111
  346. package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
  347. package/dist/esm/llm/anthropic/utils/message_outputs.mjs +0 -1
  348. package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
  349. package/dist/esm/llm/anthropic/utils/stream_events.mjs +0 -8
  350. package/dist/esm/llm/anthropic/utils/stream_events.mjs.map +1 -1
  351. package/dist/esm/llm/anthropic/utils/tools.mjs.map +1 -1
  352. package/dist/esm/llm/bedrock/cachePoints.mjs.map +1 -1
  353. package/dist/esm/llm/bedrock/index.mjs +1 -95
  354. package/dist/esm/llm/bedrock/index.mjs.map +1 -1
  355. package/dist/esm/llm/bedrock/toolCache.mjs.map +1 -1
  356. package/dist/esm/llm/bedrock/utils/message_inputs.mjs +0 -78
  357. package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
  358. package/dist/esm/llm/bedrock/utils/message_outputs.mjs +0 -24
  359. package/dist/esm/llm/bedrock/utils/message_outputs.mjs.map +1 -1
  360. package/dist/esm/llm/contextOverflowRecovery.mjs +0 -62
  361. package/dist/esm/llm/contextOverflowRecovery.mjs.map +1 -1
  362. package/dist/esm/llm/fake.mjs.map +1 -1
  363. package/dist/esm/llm/google/index.mjs +2 -21
  364. package/dist/esm/llm/google/index.mjs.map +1 -1
  365. package/dist/esm/llm/google/utils/common.mjs +0 -35
  366. package/dist/esm/llm/google/utils/common.mjs.map +1 -1
  367. package/dist/esm/llm/init.mjs +0 -9
  368. package/dist/esm/llm/init.mjs.map +1 -1
  369. package/dist/esm/llm/invoke.mjs +1 -270
  370. package/dist/esm/llm/invoke.mjs.map +1 -1
  371. package/dist/esm/llm/mistral/index.mjs.map +1 -1
  372. package/dist/esm/llm/openai/index.mjs +0 -99
  373. package/dist/esm/llm/openai/index.mjs.map +1 -1
  374. package/dist/esm/llm/openai/streamMetadata.mjs +0 -21
  375. package/dist/esm/llm/openai/streamMetadata.mjs.map +1 -1
  376. package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
  377. package/dist/esm/llm/openrouter/index.mjs +0 -1
  378. package/dist/esm/llm/openrouter/index.mjs.map +1 -1
  379. package/dist/esm/llm/openrouter/toolCache.mjs +0 -6
  380. package/dist/esm/llm/openrouter/toolCache.mjs.map +1 -1
  381. package/dist/esm/llm/preempt.mjs +0 -75
  382. package/dist/esm/llm/preempt.mjs.map +1 -1
  383. package/dist/esm/llm/providers.mjs.map +1 -1
  384. package/dist/esm/llm/request.mjs +0 -10
  385. package/dist/esm/llm/request.mjs.map +1 -1
  386. package/dist/esm/llm/stream/chunkAdapters.mjs +0 -62
  387. package/dist/esm/llm/stream/chunkAdapters.mjs.map +1 -1
  388. package/dist/esm/llm/stream/smoother.mjs +0 -58
  389. package/dist/esm/llm/stream/smoother.mjs.map +1 -1
  390. package/dist/esm/llm/streamLimits.mjs +4 -293
  391. package/dist/esm/llm/streamLimits.mjs.map +1 -1
  392. package/dist/esm/llm/truncation.mjs +0 -36
  393. package/dist/esm/llm/truncation.mjs.map +1 -1
  394. package/dist/esm/llm/vertexai/index.mjs +0 -330
  395. package/dist/esm/llm/vertexai/index.mjs.map +1 -1
  396. package/dist/esm/messages/alternation.mjs +0 -43
  397. package/dist/esm/messages/alternation.mjs.map +1 -1
  398. package/dist/esm/messages/anthropicToolCache.mjs +0 -45
  399. package/dist/esm/messages/anthropicToolCache.mjs.map +1 -1
  400. package/dist/esm/messages/assistantPhase.mjs +0 -12
  401. package/dist/esm/messages/assistantPhase.mjs.map +1 -1
  402. package/dist/esm/messages/budget.mjs +0 -9
  403. package/dist/esm/messages/budget.mjs.map +1 -1
  404. package/dist/esm/messages/cache.mjs +0 -172
  405. package/dist/esm/messages/cache.mjs.map +1 -1
  406. package/dist/esm/messages/content.mjs +0 -9
  407. package/dist/esm/messages/content.mjs.map +1 -1
  408. package/dist/esm/messages/contextPruning.mjs +0 -15
  409. package/dist/esm/messages/contextPruning.mjs.map +1 -1
  410. package/dist/esm/messages/contextPruningSettings.mjs +0 -3
  411. package/dist/esm/messages/contextPruningSettings.mjs.map +1 -1
  412. package/dist/esm/messages/core.mjs +0 -48
  413. package/dist/esm/messages/core.mjs.map +1 -1
  414. package/dist/esm/messages/format.mjs +1 -345
  415. package/dist/esm/messages/format.mjs.map +1 -1
  416. package/dist/esm/messages/handoffCue.mjs +0 -36
  417. package/dist/esm/messages/handoffCue.mjs.map +1 -1
  418. package/dist/esm/messages/ids.mjs.map +1 -1
  419. package/dist/esm/messages/injected.mjs +0 -33
  420. package/dist/esm/messages/injected.mjs.map +1 -1
  421. package/dist/esm/messages/langchain.mjs +0 -14
  422. package/dist/esm/messages/langchain.mjs.map +1 -1
  423. package/dist/esm/messages/prune.mjs +1 -184
  424. package/dist/esm/messages/prune.mjs.map +1 -1
  425. package/dist/esm/messages/recency.mjs +0 -32
  426. package/dist/esm/messages/recency.mjs.map +1 -1
  427. package/dist/esm/messages/reducer.mjs +0 -30
  428. package/dist/esm/messages/reducer.mjs.map +1 -1
  429. package/dist/esm/messages/tools.mjs +0 -14
  430. package/dist/esm/messages/tools.mjs.map +1 -1
  431. package/dist/esm/openai/index.mjs.map +1 -1
  432. package/dist/esm/prompts/activityLabel.mjs +9 -79
  433. package/dist/esm/prompts/activityLabel.mjs.map +1 -1
  434. package/dist/esm/responses/index.mjs.map +1 -1
  435. package/dist/esm/run.mjs +2 -538
  436. package/dist/esm/run.mjs.map +1 -1
  437. package/dist/esm/session/AgentSession.mjs +1 -17
  438. package/dist/esm/session/AgentSession.mjs.map +1 -1
  439. package/dist/esm/session/JsonlSessionStore.mjs.map +1 -1
  440. package/dist/esm/session/handlers.mjs +0 -7
  441. package/dist/esm/session/handlers.mjs.map +1 -1
  442. package/dist/esm/session/ids.mjs.map +1 -1
  443. package/dist/esm/session/messageSerialization.mjs +0 -4
  444. package/dist/esm/session/messageSerialization.mjs.map +1 -1
  445. package/dist/esm/stream.mjs +1 -93
  446. package/dist/esm/stream.mjs.map +1 -1
  447. package/dist/esm/summarization/index.mjs +0 -27
  448. package/dist/esm/summarization/index.mjs.map +1 -1
  449. package/dist/esm/summarization/node.mjs +0 -273
  450. package/dist/esm/summarization/node.mjs.map +1 -1
  451. package/dist/esm/tools/BashExecutor.mjs +0 -35
  452. package/dist/esm/tools/BashExecutor.mjs.map +1 -1
  453. package/dist/esm/tools/BashProgrammaticToolCalling.mjs +0 -24
  454. package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
  455. package/dist/esm/tools/Calculator.mjs.map +1 -1
  456. package/dist/esm/tools/CodeExecutor.mjs +0 -13
  457. package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
  458. package/dist/esm/tools/CodeSessionFileSummary.mjs.map +1 -1
  459. package/dist/esm/tools/ProgrammaticToolCalling.mjs +0 -101
  460. package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
  461. package/dist/esm/tools/ReadFile.mjs.map +1 -1
  462. package/dist/esm/tools/SkillTool.mjs +0 -5
  463. package/dist/esm/tools/SkillTool.mjs.map +1 -1
  464. package/dist/esm/tools/SubagentTool.mjs +0 -10
  465. package/dist/esm/tools/SubagentTool.mjs.map +1 -1
  466. package/dist/esm/tools/ToolNode.mjs +6 -1038
  467. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  468. package/dist/esm/tools/ToolSearch.mjs +0 -179
  469. package/dist/esm/tools/ToolSearch.mjs.map +1 -1
  470. package/dist/esm/tools/cloudflare/CloudflareBridgeRuntime.mjs.map +1 -1
  471. package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs.map +1 -1
  472. package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs +0 -39
  473. package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs.map +1 -1
  474. package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs.map +1 -1
  475. package/dist/esm/tools/eagerEventExecution.mjs +0 -6
  476. package/dist/esm/tools/eagerEventExecution.mjs.map +1 -1
  477. package/dist/esm/tools/handlers.mjs +1 -41
  478. package/dist/esm/tools/handlers.mjs.map +1 -1
  479. package/dist/esm/tools/intentArg.mjs +1 -132
  480. package/dist/esm/tools/intentArg.mjs.map +1 -1
  481. package/dist/esm/tools/local/CompileCheckTool.mjs +0 -25
  482. package/dist/esm/tools/local/CompileCheckTool.mjs.map +1 -1
  483. package/dist/esm/tools/local/FileCheckpointer.mjs +0 -23
  484. package/dist/esm/tools/local/FileCheckpointer.mjs.map +1 -1
  485. package/dist/esm/tools/local/LocalCodingTools.mjs +0 -80
  486. package/dist/esm/tools/local/LocalCodingTools.mjs.map +1 -1
  487. package/dist/esm/tools/local/LocalExecutionEngine.mjs +0 -126
  488. package/dist/esm/tools/local/LocalExecutionEngine.mjs.map +1 -1
  489. package/dist/esm/tools/local/LocalExecutionTools.mjs.map +1 -1
  490. package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +0 -12
  491. package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
  492. package/dist/esm/tools/local/attachments.mjs +0 -44
  493. package/dist/esm/tools/local/attachments.mjs.map +1 -1
  494. package/dist/esm/tools/local/bashAst.mjs +0 -16
  495. package/dist/esm/tools/local/bashAst.mjs.map +1 -1
  496. package/dist/esm/tools/local/editStrategies.mjs +0 -14
  497. package/dist/esm/tools/local/editStrategies.mjs.map +1 -1
  498. package/dist/esm/tools/local/resolveLocalExecutionTools.mjs.map +1 -1
  499. package/dist/esm/tools/local/syntaxCheck.mjs +0 -31
  500. package/dist/esm/tools/local/syntaxCheck.mjs.map +1 -1
  501. package/dist/esm/tools/local/textEncoding.mjs +0 -11
  502. package/dist/esm/tools/local/textEncoding.mjs.map +1 -1
  503. package/dist/esm/tools/local/workspaceFS.mjs +0 -33
  504. package/dist/esm/tools/local/workspaceFS.mjs.map +1 -1
  505. package/dist/esm/tools/ptcTimeout.mjs.map +1 -1
  506. package/dist/esm/tools/schema.mjs +0 -8
  507. package/dist/esm/tools/schema.mjs.map +1 -1
  508. package/dist/esm/tools/search/anthropic.mjs +0 -9
  509. package/dist/esm/tools/search/anthropic.mjs.map +1 -1
  510. package/dist/esm/tools/search/content.mjs.map +1 -1
  511. package/dist/esm/tools/search/crw-scraper.mjs +0 -33
  512. package/dist/esm/tools/search/crw-scraper.mjs.map +1 -1
  513. package/dist/esm/tools/search/crw-search.mjs +0 -2
  514. package/dist/esm/tools/search/crw-search.mjs.map +1 -1
  515. package/dist/esm/tools/search/firecrawl.mjs +0 -25
  516. package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
  517. package/dist/esm/tools/search/format.mjs +0 -30
  518. package/dist/esm/tools/search/format.mjs.map +1 -1
  519. package/dist/esm/tools/search/highlights.mjs +0 -16
  520. package/dist/esm/tools/search/highlights.mjs.map +1 -1
  521. package/dist/esm/tools/search/keenable-scraper.mjs +0 -8
  522. package/dist/esm/tools/search/keenable-scraper.mjs.map +1 -1
  523. package/dist/esm/tools/search/keenable-search.mjs +0 -7
  524. package/dist/esm/tools/search/keenable-search.mjs.map +1 -1
  525. package/dist/esm/tools/search/rerankers.mjs +0 -35
  526. package/dist/esm/tools/search/rerankers.mjs.map +1 -1
  527. package/dist/esm/tools/search/schema.mjs +0 -1
  528. package/dist/esm/tools/search/schema.mjs.map +1 -1
  529. package/dist/esm/tools/search/search.mjs +1 -14
  530. package/dist/esm/tools/search/search.mjs.map +1 -1
  531. package/dist/esm/tools/search/serper-scraper.mjs +0 -46
  532. package/dist/esm/tools/search/serper-scraper.mjs.map +1 -1
  533. package/dist/esm/tools/search/tavily-scraper.mjs.map +1 -1
  534. package/dist/esm/tools/search/tavily-search.mjs.map +1 -1
  535. package/dist/esm/tools/search/tool.mjs +0 -25
  536. package/dist/esm/tools/search/tool.mjs.map +1 -1
  537. package/dist/esm/tools/search/utils.mjs +0 -8
  538. package/dist/esm/tools/search/utils.mjs.map +1 -1
  539. package/dist/esm/tools/skillCatalog.mjs +0 -6
  540. package/dist/esm/tools/skillCatalog.mjs.map +1 -1
  541. package/dist/esm/tools/streamedToolCallSeals.mjs +0 -6
  542. package/dist/esm/tools/streamedToolCallSeals.mjs.map +1 -1
  543. package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs +0 -2
  544. package/dist/esm/tools/subagent/SubagentExecutionRegistry.mjs.map +1 -1
  545. package/dist/esm/tools/subagent/SubagentExecutor.mjs +3 -213
  546. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
  547. package/dist/esm/tools/subagent/SubagentReplay.mjs.map +1 -1
  548. package/dist/esm/tools/subagent/childGraphConfig.mjs +0 -4
  549. package/dist/esm/tools/subagent/childGraphConfig.mjs.map +1 -1
  550. package/dist/esm/tools/subagent/runtimeLimits.mjs.map +1 -1
  551. package/dist/esm/tools/toolOutputReferences.mjs +1 -322
  552. package/dist/esm/tools/toolOutputReferences.mjs.map +1 -1
  553. package/dist/esm/types/hitl.mjs +0 -5
  554. package/dist/esm/types/hitl.mjs.map +1 -1
  555. package/dist/esm/utils/callbacks.mjs.map +1 -1
  556. package/dist/esm/utils/errors.mjs +14 -165
  557. package/dist/esm/utils/errors.mjs.map +1 -1
  558. package/dist/esm/utils/events.mjs +0 -10
  559. package/dist/esm/utils/events.mjs.map +1 -1
  560. package/dist/esm/utils/graph.mjs.map +1 -1
  561. package/dist/esm/utils/handlers.mjs +0 -3
  562. package/dist/esm/utils/handlers.mjs.map +1 -1
  563. package/dist/esm/utils/llm.mjs +0 -1
  564. package/dist/esm/utils/llm.mjs.map +1 -1
  565. package/dist/esm/utils/misc.mjs +0 -16
  566. package/dist/esm/utils/misc.mjs.map +1 -1
  567. package/dist/esm/utils/proxy.mjs +0 -26
  568. package/dist/esm/utils/proxy.mjs.map +1 -1
  569. package/dist/esm/utils/run.mjs +0 -6
  570. package/dist/esm/utils/run.mjs.map +1 -1
  571. package/dist/esm/utils/schema.mjs +0 -5
  572. package/dist/esm/utils/schema.mjs.map +1 -1
  573. package/dist/esm/utils/title.mjs +0 -6
  574. package/dist/esm/utils/title.mjs.map +1 -1
  575. package/dist/esm/utils/tokens.mjs +0 -113
  576. package/dist/esm/utils/tokens.mjs.map +1 -1
  577. package/dist/esm/utils/toolContent.mjs +0 -41
  578. package/dist/esm/utils/toolContent.mjs.map +1 -1
  579. package/dist/esm/utils/truncation.mjs +0 -61
  580. package/dist/esm/utils/truncation.mjs.map +1 -1
  581. package/package.json +35 -32
  582. package/dist/types/agents/__tests__/promptCacheLiveHelpers.d.ts +0 -52
  583. package/dist/types/test/mockTools.d.ts +0 -28
  584. package/dist/types/utils/__tests__/fixtures/contextOverflowSignatures.d.ts +0 -40
  585. package/src/__tests__/stream.eagerArgsDivergence.test.ts +0 -911
  586. package/src/__tests__/stream.eagerEventExecution.test.ts +0 -5046
  587. package/src/__tests__/stream.streamLimits.test.ts +0 -1982
  588. package/src/agents/__tests__/AgentContext.anthropic.live.test.ts +0 -448
  589. package/src/agents/__tests__/AgentContext.bedrock.live.test.ts +0 -655
  590. package/src/agents/__tests__/AgentContext.openrouter.live.test.ts +0 -128
  591. package/src/agents/__tests__/AgentContext.overflow.test.ts +0 -205
  592. package/src/agents/__tests__/AgentContext.test.ts +0 -2425
  593. package/src/agents/__tests__/projection.test.ts +0 -73
  594. package/src/agents/__tests__/promptCacheLiveHelpers.ts +0 -175
  595. package/src/aggregator.test.ts +0 -1214
  596. package/src/graphs/__tests__/Graph.breakerLifecycle.test.ts +0 -273
  597. package/src/graphs/__tests__/Graph.closeRunStep.test.ts +0 -385
  598. package/src/graphs/__tests__/Graph.contextOverflow.test.ts +0 -1766
  599. package/src/graphs/__tests__/Graph.preemptSignal.test.ts +0 -126
  600. package/src/graphs/__tests__/Graph.reasoning.test.ts +0 -1717
  601. package/src/graphs/__tests__/Graph.subagentResumeState.test.ts +0 -80
  602. package/src/graphs/__tests__/MultiAgentGraph.test.ts +0 -177
  603. package/src/graphs/__tests__/composition.smoke.test.ts +0 -509
  604. package/src/graphs/__tests__/createGraph.test.ts +0 -206
  605. package/src/hooks/__tests__/HookRegistry.test.ts +0 -334
  606. package/src/hooks/__tests__/compactHooks.test.ts +0 -250
  607. package/src/hooks/__tests__/createToolPolicyHook.test.ts +0 -268
  608. package/src/hooks/__tests__/createWorkspacePolicyHook.test.ts +0 -405
  609. package/src/hooks/__tests__/executeHooks.test.ts +0 -1294
  610. package/src/hooks/__tests__/integration.test.ts +0 -337
  611. package/src/hooks/__tests__/matchers.test.ts +0 -238
  612. package/src/hooks/__tests__/preemptBoundary.test.ts +0 -152
  613. package/src/hooks/__tests__/toolHooks.test.ts +0 -669
  614. package/src/llm/__tests__/contextOverflowRecovery.test.ts +0 -401
  615. package/src/llm/__tests__/fallbackOverflow.test.ts +0 -287
  616. package/src/llm/anthropic/Jacob_Lee_Resume_2023.pdf +0 -0
  617. package/src/llm/anthropic/inherited-content-utils.spec.ts +0 -249
  618. package/src/llm/anthropic/inherited-stream-events.spec.ts +0 -1259
  619. package/src/llm/anthropic/inherited-strict.spec.ts +0 -302
  620. package/src/llm/anthropic/llm.spec.ts +0 -3394
  621. package/src/llm/anthropic/utils/cross-provider-reasoning.test.ts +0 -383
  622. package/src/llm/anthropic/utils/cross-provider-server-tools.test.ts +0 -110
  623. package/src/llm/anthropic/utils/server-tool-inputs.test.ts +0 -508
  624. package/src/llm/anthropic/utils/streaming-tool-input.test.ts +0 -361
  625. package/src/llm/anthropic/utils/stripPrefillCache.test.ts +0 -111
  626. package/src/llm/anthropic/utils/tool-id-normalization.test.ts +0 -287
  627. package/src/llm/bedrock/inherited-cache.spec.ts +0 -144
  628. package/src/llm/bedrock/inherited.spec.ts +0 -724
  629. package/src/llm/bedrock/llm.spec.ts +0 -1533
  630. package/src/llm/bedrock/streamSealDispatch.test.ts +0 -331
  631. package/src/llm/bedrock/toolCache.test.ts +0 -194
  632. package/src/llm/bedrock/utils/cross-provider-reasoning.test.ts +0 -131
  633. package/src/llm/bedrock/utils/cross-provider-server-tools.test.ts +0 -122
  634. package/src/llm/bedrock/utils/message_inputs.test.ts +0 -650
  635. package/src/llm/bedrock/utils/message_outputs.test.ts +0 -85
  636. package/src/llm/bedrock/utils/toolResultCachePoint.test.ts +0 -118
  637. package/src/llm/custom-chat-models.smoke.test.ts +0 -1966
  638. package/src/llm/google/data/gettysburg10.wav +0 -0
  639. package/src/llm/google/data/hotdog.jpg +0 -0
  640. package/src/llm/google/inherited-stream-events.spec.ts +0 -350
  641. package/src/llm/google/llm.spec.ts +0 -1388
  642. package/src/llm/google/streamSmoothing.test.ts +0 -121
  643. package/src/llm/google/utils/common.test.ts +0 -196
  644. package/src/llm/invoke.alternation.test.ts +0 -87
  645. package/src/llm/invoke.handoffCue.test.ts +0 -112
  646. package/src/llm/invoke.streamLimits.test.ts +0 -142
  647. package/src/llm/invoke.test.ts +0 -1198
  648. package/src/llm/mistral/streamSmoothing.test.ts +0 -97
  649. package/src/llm/openai/cacheWriteTokens.test.ts +0 -112
  650. package/src/llm/openai/contentBlocks.test.ts +0 -381
  651. package/src/llm/openai/deepseek.test.ts +0 -747
  652. package/src/llm/openai/inherited-deepseek.spec.ts +0 -347
  653. package/src/llm/openai/inherited-xai.spec.ts +0 -416
  654. package/src/llm/openai/llm.spec.ts +0 -1774
  655. package/src/llm/openai/managedRequests.test.ts +0 -182
  656. package/src/llm/openai/sequentialToolCallSeals.test.ts +0 -199
  657. package/src/llm/openai/streamMetadata.spec.ts +0 -86
  658. package/src/llm/openai/streamMetadataDedup.spec.ts +0 -166
  659. package/src/llm/openai/utils/isReasoningModel.test.ts +0 -90
  660. package/src/llm/openai/utils/messages.test.ts +0 -488
  661. package/src/llm/openrouter/reasoning.test.ts +0 -561
  662. package/src/llm/openrouter/toolCache.test.ts +0 -134
  663. package/src/llm/preempt.test.ts +0 -323
  664. package/src/llm/stream/chunkAdapters.test.ts +0 -202
  665. package/src/llm/stream/reassembly.test.ts +0 -241
  666. package/src/llm/stream/smoother.bench.test.ts +0 -155
  667. package/src/llm/stream/smoother.test.ts +0 -519
  668. package/src/llm/streamLimits.test.ts +0 -450
  669. package/src/llm/truncation.test.ts +0 -242
  670. package/src/llm/vertexai/fixThoughtSignatures.test.ts +0 -154
  671. package/src/llm/vertexai/inherited-stream-events.spec.ts +0 -271
  672. package/src/llm/vertexai/llm.spec.ts +0 -159
  673. package/src/llm/vertexai/repairUsageMetadata.test.ts +0 -54
  674. package/src/llm/vertexai/sealStreamedToolCalls.test.ts +0 -88
  675. package/src/llm/vertexai/streamSealDispatch.test.ts +0 -148
  676. package/src/llm/vertexai/streamSmoothing.test.ts +0 -109
  677. package/src/messages/__tests__/anthropicToolCache.test.ts +0 -339
  678. package/src/messages/__tests__/observationMasking.test.ts +0 -312
  679. package/src/messages/__tests__/recency.test.ts +0 -267
  680. package/src/messages/__tests__/tools.test.ts +0 -473
  681. package/src/messages/alternation.test.ts +0 -212
  682. package/src/messages/assistantPhase.test.ts +0 -75
  683. package/src/messages/cache.tail.test.ts +0 -533
  684. package/src/messages/cache.test.ts +0 -2166
  685. package/src/messages/content.test.ts +0 -362
  686. package/src/messages/contextPruning.test.ts +0 -184
  687. package/src/messages/ensureThinkingBlock.test.ts +0 -1427
  688. package/src/messages/foldToollessToolBlocks.test.ts +0 -596
  689. package/src/messages/formatAgentMessages.reducer.test.ts +0 -162
  690. package/src/messages/formatAgentMessages.skills.test.ts +0 -513
  691. package/src/messages/formatAgentMessages.steer.test.ts +0 -598
  692. package/src/messages/formatAgentMessages.test.ts +0 -8111
  693. package/src/messages/formatAgentMessages.tools.test.ts +0 -522
  694. package/src/messages/formatMessage.test.ts +0 -693
  695. package/src/messages/handoffCue.test.ts +0 -96
  696. package/src/messages/injected.test.ts +0 -107
  697. package/src/messages/labelContentByAgent.test.ts +0 -962
  698. package/src/messages/reducer.spec.ts +0 -32
  699. package/src/messages/shiftIndexTokenCountMap.test.ts +0 -81
  700. package/src/messages/tailCacheConversion.test.ts +0 -161
  701. package/src/openai/__tests__/openai.test.ts +0 -337
  702. package/src/responses/__tests__/responses.test.ts +0 -652
  703. package/src/scripts/abort.ts +0 -157
  704. package/src/scripts/activity-labels/captured.json +0 -56
  705. package/src/scripts/activity-labels/checks.cjs +0 -205
  706. package/src/scripts/activity-labels/corpus.cjs +0 -473
  707. package/src/scripts/activity-labels/report.cjs +0 -203
  708. package/src/scripts/activity-labels/rescore.cjs +0 -102
  709. package/src/scripts/activity-labels/run.ts +0 -705
  710. package/src/scripts/activity-labels/variants.ts +0 -71
  711. package/src/scripts/ant_web_search.ts +0 -159
  712. package/src/scripts/ant_web_search_edge_case.ts +0 -163
  713. package/src/scripts/ant_web_search_error_edge_case.ts +0 -149
  714. package/src/scripts/args.ts +0 -48
  715. package/src/scripts/bedrock-cache-debug.ts +0 -250
  716. package/src/scripts/bedrock-content-aggregation-test.ts +0 -266
  717. package/src/scripts/bedrock-merge-test.ts +0 -107
  718. package/src/scripts/bedrock-parallel-tools-test.ts +0 -204
  719. package/src/scripts/bench-prompt-cache.ts +0 -479
  720. package/src/scripts/caching.ts +0 -132
  721. package/src/scripts/cli.ts +0 -172
  722. package/src/scripts/cli2.ts +0 -133
  723. package/src/scripts/cli3.ts +0 -184
  724. package/src/scripts/cli4.ts +0 -191
  725. package/src/scripts/cli5.ts +0 -191
  726. package/src/scripts/code_exec.ts +0 -214
  727. package/src/scripts/code_exec_files.ts +0 -237
  728. package/src/scripts/code_exec_multi_session.ts +0 -237
  729. package/src/scripts/code_exec_ptc.ts +0 -335
  730. package/src/scripts/code_exec_session.ts +0 -283
  731. package/src/scripts/code_exec_simple.ts +0 -148
  732. package/src/scripts/compare_pi_vs_ours.ts +0 -1259
  733. package/src/scripts/content.ts +0 -139
  734. package/src/scripts/context-overflow-probe.ts +0 -997
  735. package/src/scripts/empty_input.ts +0 -137
  736. package/src/scripts/handoff-test.ts +0 -134
  737. package/src/scripts/local_engine.ts +0 -166
  738. package/src/scripts/local_engine_checkpointer.ts +0 -205
  739. package/src/scripts/local_engine_compile.ts +0 -263
  740. package/src/scripts/local_engine_hooks.ts +0 -226
  741. package/src/scripts/local_engine_image.ts +0 -201
  742. package/src/scripts/local_engine_ptc.ts +0 -151
  743. package/src/scripts/local_engine_workspace.ts +0 -258
  744. package/src/scripts/memory.ts +0 -107
  745. package/src/scripts/multi-agent-chain.ts +0 -332
  746. package/src/scripts/multi-agent-conditional.ts +0 -222
  747. package/src/scripts/multi-agent-document-review-chain.ts +0 -198
  748. package/src/scripts/multi-agent-hybrid-flow.ts +0 -311
  749. package/src/scripts/multi-agent-parallel-start.ts +0 -265
  750. package/src/scripts/multi-agent-parallel.ts +0 -395
  751. package/src/scripts/multi-agent-sequence.ts +0 -217
  752. package/src/scripts/multi-agent-subagent.ts +0 -246
  753. package/src/scripts/multi-agent-supervisor.ts +0 -366
  754. package/src/scripts/multi-agent-test.ts +0 -187
  755. package/src/scripts/openrouter_prompt_cache_live.ts +0 -310
  756. package/src/scripts/parallel-asymmetric-tools-test.ts +0 -275
  757. package/src/scripts/parallel-full-metadata-test.ts +0 -241
  758. package/src/scripts/parallel-tools-test.ts +0 -341
  759. package/src/scripts/preempt-probe.ts +0 -330
  760. package/src/scripts/preempt-scenarios.ts +0 -388
  761. package/src/scripts/programmatic_exec.ts +0 -387
  762. package/src/scripts/programmatic_exec_agent.ts +0 -232
  763. package/src/scripts/search.ts +0 -147
  764. package/src/scripts/sequential-full-metadata-test.ts +0 -198
  765. package/src/scripts/session_live.ts +0 -548
  766. package/src/scripts/simple.ts +0 -226
  767. package/src/scripts/single-agent-metadata-test.ts +0 -196
  768. package/src/scripts/stream.ts +0 -141
  769. package/src/scripts/subagent-configurable-inheritance.ts +0 -252
  770. package/src/scripts/subagent-event-driven-debug.ts +0 -190
  771. package/src/scripts/subagent-tools-debug.ts +0 -160
  772. package/src/scripts/subagent-usage-sink.ts +0 -176
  773. package/src/scripts/summarization-recency.ts +0 -462
  774. package/src/scripts/test-custom-prompt-key.ts +0 -145
  775. package/src/scripts/test-handoff-input.ts +0 -170
  776. package/src/scripts/test-handoff-preamble.ts +0 -278
  777. package/src/scripts/test-handoff-steering.ts +0 -430
  778. package/src/scripts/test-multi-agent-list-handoff.ts +0 -418
  779. package/src/scripts/test-parallel-agent-labeling.ts +0 -327
  780. package/src/scripts/test-parallel-handoffs.ts +0 -292
  781. package/src/scripts/test-thinking-handoff-bedrock.ts +0 -154
  782. package/src/scripts/test-thinking-handoff.ts +0 -156
  783. package/src/scripts/test-thinking-to-thinking-handoff-bedrock.ts +0 -166
  784. package/src/scripts/test-tool-before-handoff-role-order.ts +0 -276
  785. package/src/scripts/test-tools-before-handoff.ts +0 -222
  786. package/src/scripts/test_code_api.ts +0 -354
  787. package/src/scripts/thinking-bedrock.ts +0 -160
  788. package/src/scripts/thinking-vertexai.ts +0 -168
  789. package/src/scripts/thinking.ts +0 -172
  790. package/src/scripts/tool_search.ts +0 -153
  791. package/src/scripts/tools.ts +0 -163
  792. package/src/session/__tests__/JsonlSessionStore.test.ts +0 -1463
  793. package/src/session/__tests__/handlers.test.ts +0 -161
  794. package/src/specs/activity-label-observability.live.test.ts +0 -262
  795. package/src/specs/activity-label-observability.test.ts +0 -167
  796. package/src/specs/activity-label-prompt.test.ts +0 -359
  797. package/src/specs/activity-label-trace-seed.test.ts +0 -47
  798. package/src/specs/activity-phase-label.test.ts +0 -306
  799. package/src/specs/agent-handoffs.live.test.ts +0 -140
  800. package/src/specs/agent-handoffs.test.ts +0 -2465
  801. package/src/specs/anthropic.simple.test.ts +0 -453
  802. package/src/specs/ask-user-question-batch.test.ts +0 -289
  803. package/src/specs/ask-user-questions.live.test.ts +0 -185
  804. package/src/specs/ask-user-questions.test.ts +0 -293
  805. package/src/specs/azure.simple.test.ts +0 -502
  806. package/src/specs/bedrock-toolless.live.test.ts +0 -123
  807. package/src/specs/bedrock-truncation.live.test.ts +0 -191
  808. package/src/specs/cache.simple.test.ts +0 -416
  809. package/src/specs/context-accuracy.live.test.ts +0 -409
  810. package/src/specs/context-overflow-recovery.live.test.ts +0 -213
  811. package/src/specs/context-usage-event.test.ts +0 -117
  812. package/src/specs/context-usage.live.test.ts +0 -297
  813. package/src/specs/custom-event-await.test.ts +0 -304
  814. package/src/specs/deepseek.simple.test.ts +0 -290
  815. package/src/specs/deterministic-trace-id.test.ts +0 -43
  816. package/src/specs/discovered-tools.test.ts +0 -217
  817. package/src/specs/durability-checkpoint.integration.test.ts +0 -243
  818. package/src/specs/graph-subagent.live.test.ts +0 -242
  819. package/src/specs/graph-subagent.test.ts +0 -322
  820. package/src/specs/handoffCue.test.ts +0 -165
  821. package/src/specs/langfuse-callbacks.test.ts +0 -1578
  822. package/src/specs/langfuse-config.test.ts +0 -247
  823. package/src/specs/langfuse-instrumentation.test.ts +0 -393
  824. package/src/specs/langfuse-metadata.test.ts +0 -245
  825. package/src/specs/langfuse-routing.integration.test.ts +0 -844
  826. package/src/specs/langfuse-runtime-context.test.ts +0 -92
  827. package/src/specs/langfuse-span-registry.test.ts +0 -87
  828. package/src/specs/langfuse-tool-output-tracing.test.ts +0 -1858
  829. package/src/specs/langfuse-trace-shaping.test.ts +0 -591
  830. package/src/specs/moonshot.simple.test.ts +0 -367
  831. package/src/specs/multi-agent-summarization.test.ts +0 -396
  832. package/src/specs/openai.simple.test.ts +0 -315
  833. package/src/specs/openrouter.simple.test.ts +0 -275
  834. package/src/specs/preemptSeal.test.ts +0 -678
  835. package/src/specs/prune.test.ts +0 -3741
  836. package/src/specs/reasoning.test.ts +0 -201
  837. package/src/specs/run-step-timestamps.test.ts +0 -414
  838. package/src/specs/spec.utils.ts +0 -15
  839. package/src/specs/subagent.test.ts +0 -864
  840. package/src/specs/summarization-unit.test.ts +0 -973
  841. package/src/specs/summarization.test.ts +0 -3823
  842. package/src/specs/summarize-prune.test.ts +0 -376
  843. package/src/specs/thinking-handoff.test.ts +0 -621
  844. package/src/specs/thinking-prune.test.ts +0 -827
  845. package/src/specs/token-accounting-e2e.test.ts +0 -1034
  846. package/src/specs/token-accounting-pipeline.test.ts +0 -1008
  847. package/src/specs/token-distribution-edge-case.test.ts +0 -315
  848. package/src/specs/token-memoization.test.ts +0 -40
  849. package/src/specs/tokens.test.ts +0 -1000
  850. package/src/specs/tool-error-resume.test.ts +0 -194
  851. package/src/specs/tool-error.test.ts +0 -198
  852. package/src/specs/vllm-reasoning-toolcalls.test.ts +0 -340
  853. package/src/stream.dispatch.test.ts +0 -63
  854. package/src/stream.test.ts +0 -144
  855. package/src/summarization/__tests__/aggregator.test.ts +0 -236
  856. package/src/summarization/__tests__/node.test.ts +0 -1996
  857. package/src/summarization/__tests__/trigger.test.ts +0 -149
  858. package/src/summarization/chunkHandler.test.ts +0 -196
  859. package/src/test/mockTools.ts +0 -386
  860. package/src/tools/Calculator.test.ts +0 -278
  861. package/src/tools/__tests__/BashExecutor.test.ts +0 -108
  862. package/src/tools/__tests__/CloudflareSandboxExecution.test.ts +0 -939
  863. package/src/tools/__tests__/CodeApiAuthHeaders.test.ts +0 -858
  864. package/src/tools/__tests__/CodeExecutor.stateful.test.ts +0 -124
  865. package/src/tools/__tests__/LocalExecutionRoots.test.ts +0 -8
  866. package/src/tools/__tests__/LocalExecutionTools.test.ts +0 -2733
  867. package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts +0 -318
  868. package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +0 -1557
  869. package/src/tools/__tests__/ReadFile.test.ts +0 -44
  870. package/src/tools/__tests__/SkillTool.test.ts +0 -442
  871. package/src/tools/__tests__/SubagentExecutor.test.ts +0 -3728
  872. package/src/tools/__tests__/SubagentReplay.test.ts +0 -329
  873. package/src/tools/__tests__/SubagentTool.test.ts +0 -149
  874. package/src/tools/__tests__/ToolNode.breakerSignal.test.ts +0 -595
  875. package/src/tools/__tests__/ToolNode.eagerEventExecution.test.ts +0 -1191
  876. package/src/tools/__tests__/ToolNode.invalidToolCalls.test.ts +0 -757
  877. package/src/tools/__tests__/ToolNode.langfuse.test.ts +0 -57
  878. package/src/tools/__tests__/ToolNode.onResultCompletion.test.ts +0 -736
  879. package/src/tools/__tests__/ToolNode.outputReferences.test.ts +0 -1710
  880. package/src/tools/__tests__/ToolNode.runtimeState.test.ts +0 -120
  881. package/src/tools/__tests__/ToolNode.session.test.ts +0 -1352
  882. package/src/tools/__tests__/ToolNode.streamLimits.test.ts +0 -69
  883. package/src/tools/__tests__/ToolSearch.integration.test.ts +0 -161
  884. package/src/tools/__tests__/ToolSearch.test.ts +0 -1227
  885. package/src/tools/__tests__/annotateMessagesForLLM.test.ts +0 -561
  886. package/src/tools/__tests__/directToolHITLResumeScope.test.ts +0 -980
  887. package/src/tools/__tests__/directToolHooks.test.ts +0 -700
  888. package/src/tools/__tests__/eagerEventExecution.session.test.ts +0 -92
  889. package/src/tools/__tests__/handlers.test.ts +0 -997
  890. package/src/tools/__tests__/hitl.test.ts +0 -4663
  891. package/src/tools/__tests__/intentArg.test.ts +0 -357
  892. package/src/tools/__tests__/intentCoverage.test.ts +0 -139
  893. package/src/tools/__tests__/localToolNames.test.ts +0 -75
  894. package/src/tools/__tests__/skillCatalog.test.ts +0 -161
  895. package/src/tools/__tests__/subagentHooks.test.ts +0 -1651
  896. package/src/tools/__tests__/toolOutputReferences.test.ts +0 -515
  897. package/src/tools/__tests__/workspaceSeam.test.ts +0 -147
  898. package/src/tools/local/__tests__/FileCheckpointer.test.ts +0 -162
  899. package/src/tools/local/__tests__/editStrategies.test.ts +0 -134
  900. package/src/tools/search/content.test.ts +0 -173
  901. package/src/tools/search/crw.test.ts +0 -836
  902. package/src/tools/search/format.test.ts +0 -242
  903. package/src/tools/search/http-agent.test.ts +0 -133
  904. package/src/tools/search/jina-reranker.test.ts +0 -306
  905. package/src/tools/search/keenable-scraper.test.ts +0 -153
  906. package/src/tools/search/keenable.test.ts +0 -183
  907. package/src/tools/search/outcome.test.ts +0 -90
  908. package/src/tools/search/output.md +0 -2775
  909. package/src/tools/search/rag-api-reranker.test.ts +0 -891
  910. package/src/tools/search/source-processing.test.ts +0 -516
  911. package/src/tools/search/tavily.test.ts +0 -965
  912. package/src/tools/search/test.html +0 -884
  913. package/src/tools/search/test.md +0 -643
  914. package/src/tools/subagent/__tests__/SubagentExecutionRegistry.test.ts +0 -637
  915. package/src/tools/subagent/__tests__/SubagentExecutor.lazy.test.ts +0 -3054
  916. package/src/tools/subagent/__tests__/childGraphConfig.test.ts +0 -521
  917. package/src/utils/__tests__/apportion.test.ts +0 -32
  918. package/src/utils/__tests__/errors.test.ts +0 -270
  919. package/src/utils/__tests__/fixtures/contextOverflowSignatures.ts +0 -336
  920. package/src/utils/__tests__/redactSecrets.test.ts +0 -56
  921. package/src/utils/__tests__/truncation.test.ts +0 -66
  922. package/src/utils/llm.test.ts +0 -18
  923. package/src/utils/proxy.test.ts +0 -176
  924. package/src/utils/toolContent.test.ts +0 -1432
@@ -1,2465 +0,0 @@
1
- // src/specs/agent-handoffs.test.ts
2
- import { MemorySaver } from '@langchain/langgraph';
3
- import { DynamicStructuredTool } from '@langchain/core/tools';
4
- import {
5
- AIMessage,
6
- HumanMessage,
7
- ToolMessage,
8
- getBufferString,
9
- } from '@langchain/core/messages';
10
- import type { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
11
- import type { ChatGenerationChunk } from '@langchain/core/outputs';
12
- import type { RunnableConfig } from '@langchain/core/runnables';
13
- import type { ToolCall } from '@langchain/core/messages/tool';
14
- import type * as t from '@/types';
15
- import { Providers, GraphEvents, Constants } from '@/common';
16
- import { createHandlers } from '@/utils/handlers';
17
- import { StandardGraph } from '@/graphs/Graph';
18
- import { ToolNode } from '@/tools/ToolNode';
19
- import { FakeChatModel } from '@/llm/fake';
20
- import * as events from '@/utils/events';
21
- import { Run } from '@/run';
22
-
23
- /**
24
- * Helper to safely get tool name from tool object
25
- */
26
- const getToolName = (tool: t.GraphTools[0]): string | undefined => {
27
- return (tool as { name?: string }).name;
28
- };
29
-
30
- /**
31
- * Helper to safely get tool description from tool object
32
- */
33
- const getToolDescription = (tool: t.GraphTools[0]): string | undefined => {
34
- return (tool as { description?: string }).description;
35
- };
36
-
37
- /**
38
- * Helper to safely get tool schema from tool object
39
- */
40
- const getToolSchema = (tool: t.GraphTools[0]): unknown => {
41
- return (tool as { schema?: unknown }).schema;
42
- };
43
-
44
- /**
45
- * Helper to find tool by name
46
- */
47
- const findToolByName = (
48
- tools: t.GraphTools | undefined,
49
- name: string
50
- ): t.GraphTools[0] | undefined => {
51
- return tools?.find((tool) => getToolName(tool) === name);
52
- };
53
-
54
- type HandoffModelScript = {
55
- promptMarker: string;
56
- response: string;
57
- toolCalls?: ToolCall[];
58
- };
59
-
60
- function validateToolHistory(messages: t.BaseGraphState['messages']): void {
61
- const toolCallIds = new Set<string>();
62
- const toolResultIds = new Set<string>();
63
- for (const message of messages) {
64
- if (message.getType() === 'ai') {
65
- for (const toolCall of (message as AIMessage).tool_calls ?? []) {
66
- if (toolCall.id != null) {
67
- toolCallIds.add(toolCall.id);
68
- }
69
- }
70
- } else if (message.getType() === 'tool') {
71
- toolResultIds.add((message as ToolMessage).tool_call_id);
72
- }
73
- }
74
- for (const toolCallId of toolCallIds) {
75
- if (!toolResultIds.has(toolCallId)) {
76
- throw new Error(`Tool call ${toolCallId} has no matching result`);
77
- }
78
- }
79
- for (const toolResultId of toolResultIds) {
80
- if (!toolCallIds.has(toolResultId)) {
81
- throw new Error(`Tool result ${toolResultId} has no matching call`);
82
- }
83
- }
84
- }
85
-
86
- class ScriptedHandoffModel extends FakeChatModel {
87
- private scripts: HandoffModelScript[];
88
-
89
- constructor(scripts: HandoffModelScript[]) {
90
- super({ responses: [''] });
91
- this.scripts = scripts;
92
- }
93
-
94
- override async *_streamResponseChunks(
95
- messages: t.BaseGraphState['messages'],
96
- options: this['ParsedCallOptions'],
97
- runManager?: CallbackManagerForLLMRun
98
- ): AsyncGenerator<ChatGenerationChunk> {
99
- validateToolHistory(messages);
100
- const prompt = getBufferString(messages);
101
- let script: HandoffModelScript | undefined;
102
- let latestMarkerIndex = -1;
103
- for (const candidate of this.scripts) {
104
- const markerIndex = prompt.lastIndexOf(candidate.promptMarker);
105
- if (markerIndex > latestMarkerIndex) {
106
- script = candidate;
107
- latestMarkerIndex = markerIndex;
108
- }
109
- }
110
- if (script == null) {
111
- throw new Error(`No handoff model script matched prompt: ${prompt}`);
112
- }
113
- const model = new FakeChatModel({
114
- responses: [script.response],
115
- toolCalls: script.toolCalls,
116
- });
117
- yield* model._streamResponseChunks(messages, options, runManager);
118
- }
119
- }
120
-
121
- type HandoffReceptionProbe = {
122
- processHandoffReception(
123
- messages: t.BaseGraphState['messages'],
124
- agentId: string
125
- ): {
126
- instructions: string | null;
127
- parallelGroupId?: number;
128
- filteredMessages?: t.BaseGraphState['messages'];
129
- } | null;
130
- };
131
-
132
- type PendingSend = {
133
- node: string;
134
- args: { messages?: t.BaseGraphState['messages'] };
135
- };
136
-
137
- const isPendingSend = (value: unknown): value is PendingSend => {
138
- if (value == null || typeof value !== 'object') {
139
- return false;
140
- }
141
- const candidate = value as { node?: unknown; args?: unknown };
142
- return (
143
- typeof candidate.node === 'string' &&
144
- candidate.args != null &&
145
- typeof candidate.args === 'object'
146
- );
147
- };
148
-
149
- /**
150
- * Test suite for Agent Handoffs feature
151
- *
152
- * Tests cover:
153
- * - Basic handoff between two agents
154
- * - Handoffs with custom descriptions
155
- * - Handoffs with prompts and prompt keys
156
- * - Sequential handoffs (A -> B -> C)
157
- * - Bidirectional handoffs (A <-> B)
158
- * - Multiple handoff options from single agent
159
- * - Handoff tool creation and execution
160
- * - Error cases and edge conditions
161
- */
162
- describe('Agent Handoffs Tests', () => {
163
- jest.setTimeout(30000);
164
-
165
- const createTestConfig = (
166
- agents: t.AgentInputs[],
167
- edges: t.GraphEdge[]
168
- ): t.RunConfig => ({
169
- runId: `handoff-test-${Date.now()}-${Math.random()}`,
170
- graphConfig: {
171
- type: 'multi-agent',
172
- agents,
173
- edges,
174
- },
175
- returnContent: true,
176
- skipCleanup: true,
177
- });
178
-
179
- const createBasicAgent = (
180
- agentId: string,
181
- instructions: string
182
- ): t.AgentInputs => ({
183
- agentId,
184
- provider: Providers.ANTHROPIC,
185
- clientOptions: {
186
- modelName: 'claude-haiku-4-5',
187
- apiKey: 'test-key',
188
- },
189
- instructions,
190
- maxContextTokens: 28000,
191
- });
192
-
193
- describe('Basic Handoff Tests', () => {
194
- it('should create handoff tool for agent with outgoing handoff edge', async () => {
195
- const agents: t.AgentInputs[] = [
196
- createBasicAgent('agent_a', 'You are agent A'),
197
- createBasicAgent('agent_b', 'You are agent B'),
198
- ];
199
-
200
- const edges: t.GraphEdge[] = [
201
- {
202
- from: 'agent_a',
203
- to: 'agent_b',
204
- edgeType: 'handoff',
205
- description: 'Transfer to agent B',
206
- },
207
- ];
208
-
209
- const run = await Run.create(createTestConfig(agents, edges));
210
-
211
- expect(run.Graph).toBeDefined();
212
-
213
- const agentAContext = (run.Graph as StandardGraph).agentContexts.get(
214
- 'agent_a'
215
- );
216
- expect(agentAContext).toBeDefined();
217
- expect(agentAContext?.graphTools).toBeDefined();
218
-
219
- // Check that handoff tool was created
220
- const handoffTool = findToolByName(
221
- agentAContext?.graphTools,
222
- `${Constants.LC_TRANSFER_TO_}agent_b`
223
- );
224
- expect(handoffTool).toBeDefined();
225
- expect(getToolDescription(handoffTool!)).toBe('Transfer to agent B');
226
- });
227
-
228
- it('should successfully handoff from agent A to agent B', async () => {
229
- const agents: t.AgentInputs[] = [
230
- createBasicAgent('agent_a', 'You are agent A. Transfer to agent B.'),
231
- createBasicAgent('agent_b', 'You are agent B. Respond to the user.'),
232
- ];
233
-
234
- const edges: t.GraphEdge[] = [
235
- {
236
- from: 'agent_a',
237
- to: 'agent_b',
238
- edgeType: 'handoff',
239
- description: 'Transfer to agent B when needed',
240
- },
241
- ];
242
-
243
- const run = await Run.create(createTestConfig(agents, edges));
244
-
245
- // Override models to simulate handoff behavior
246
- run.Graph?.overrideTestModel(
247
- [
248
- 'Transferring to agent B', // Agent A response
249
- 'Hello from agent B', // Agent B response
250
- ],
251
- 10,
252
- [
253
- {
254
- id: 'tool_call_1',
255
- name: `${Constants.LC_TRANSFER_TO_}agent_b`,
256
- args: {},
257
- } as ToolCall,
258
- ]
259
- );
260
-
261
- const messages = [new HumanMessage('Hello')];
262
-
263
- const config: Partial<RunnableConfig> & {
264
- version: 'v1' | 'v2';
265
- streamMode: string;
266
- } = {
267
- configurable: {
268
- thread_id: 'test-handoff-thread',
269
- },
270
- streamMode: 'values',
271
- version: 'v2' as const,
272
- };
273
-
274
- await run.processStream({ messages }, config);
275
-
276
- const finalMessages = run.getRunMessages();
277
- expect(finalMessages).toBeDefined();
278
- expect(finalMessages!.length).toBeGreaterThan(1);
279
-
280
- // Check for tool message indicating handoff
281
- const toolMessages = finalMessages!.filter(
282
- (msg) => msg.getType() === 'tool'
283
- ) as ToolMessage[];
284
-
285
- const handoffToolMessage = toolMessages.find(
286
- (msg) => msg.name === `${Constants.LC_TRANSFER_TO_}agent_b`
287
- );
288
- expect(handoffToolMessage).toBeDefined();
289
- expect(handoffToolMessage?.content).toContain('transferred to agent_b');
290
- });
291
-
292
- it('should not create handoff tool for agent without outgoing edges', async () => {
293
- const agents: t.AgentInputs[] = [
294
- createBasicAgent('agent_a', 'You are agent A'),
295
- createBasicAgent('agent_b', 'You are agent B'),
296
- ];
297
-
298
- const edges: t.GraphEdge[] = [
299
- {
300
- from: 'agent_a',
301
- to: 'agent_b',
302
- edgeType: 'handoff',
303
- },
304
- ];
305
-
306
- const run = await Run.create(createTestConfig(agents, edges));
307
-
308
- const agentBContext = (run.Graph as StandardGraph).agentContexts.get(
309
- 'agent_b'
310
- );
311
- expect(agentBContext).toBeDefined();
312
-
313
- // Agent B should not have handoff tools (no outgoing edges)
314
- const handoffTools = agentBContext?.graphTools?.filter((tool) => {
315
- const name = getToolName(tool);
316
- return name?.startsWith(Constants.LC_TRANSFER_TO_) ?? false;
317
- });
318
- expect(handoffTools?.length ?? 0).toBe(0);
319
- });
320
- });
321
-
322
- describe('Bidirectional Handoffs', () => {
323
- it('should create handoff tools for both agents in bidirectional setup', async () => {
324
- const agents: t.AgentInputs[] = [
325
- createBasicAgent('agent_a', 'You are agent A'),
326
- createBasicAgent('agent_b', 'You are agent B'),
327
- ];
328
-
329
- const edges: t.GraphEdge[] = [
330
- {
331
- from: 'agent_a',
332
- to: 'agent_b',
333
- edgeType: 'handoff',
334
- description: 'Transfer to agent B',
335
- },
336
- {
337
- from: 'agent_b',
338
- to: 'agent_a',
339
- edgeType: 'handoff',
340
- description: 'Transfer to agent A',
341
- },
342
- ];
343
-
344
- const run = await Run.create(createTestConfig(agents, edges));
345
-
346
- const agentAContext = (run.Graph as StandardGraph).agentContexts.get(
347
- 'agent_a'
348
- );
349
- const agentBContext = (run.Graph as StandardGraph).agentContexts.get(
350
- 'agent_b'
351
- );
352
-
353
- // Agent A should have tool to transfer to B
354
- const agentAHandoffTool = findToolByName(
355
- agentAContext?.graphTools,
356
- `${Constants.LC_TRANSFER_TO_}agent_b`
357
- );
358
- expect(agentAHandoffTool).toBeDefined();
359
-
360
- // Agent B should have tool to transfer to A
361
- const agentBHandoffTool = findToolByName(
362
- agentBContext?.graphTools,
363
- `${Constants.LC_TRANSFER_TO_}agent_a`
364
- );
365
- expect(agentBHandoffTool).toBeDefined();
366
- });
367
-
368
- it('should handle handoff from A to B in bidirectional setup', async () => {
369
- const agents: t.AgentInputs[] = [
370
- createBasicAgent('agent_a', 'You are agent A'),
371
- createBasicAgent('agent_b', 'You are agent B'),
372
- ];
373
-
374
- const edges: t.GraphEdge[] = [
375
- {
376
- from: 'agent_a',
377
- to: 'agent_b',
378
- edgeType: 'handoff',
379
- },
380
- {
381
- from: 'agent_b',
382
- to: 'agent_a',
383
- edgeType: 'handoff',
384
- },
385
- ];
386
-
387
- const run = await Run.create(createTestConfig(agents, edges));
388
-
389
- // Simulate single handoff from A to B
390
- run.Graph?.overrideTestModel(
391
- ['Transferring to B', 'Response from B'],
392
- 10,
393
- [
394
- {
395
- id: 'tool_call_1',
396
- name: `${Constants.LC_TRANSFER_TO_}agent_b`,
397
- args: {},
398
- } as ToolCall,
399
- ]
400
- );
401
-
402
- const messages = [new HumanMessage('Start conversation')];
403
-
404
- const config: Partial<RunnableConfig> & {
405
- version: 'v1' | 'v2';
406
- streamMode: string;
407
- } = {
408
- configurable: {
409
- thread_id: 'test-bidirectional-thread',
410
- },
411
- streamMode: 'values',
412
- version: 'v2' as const,
413
- };
414
-
415
- await run.processStream({ messages }, config);
416
-
417
- const finalMessages = run.getRunMessages();
418
- expect(finalMessages).toBeDefined();
419
-
420
- // Should have a handoff tool message
421
- const toolMessages = finalMessages!.filter(
422
- (msg) => msg.getType() === 'tool'
423
- ) as ToolMessage[];
424
-
425
- const handoffMessage = toolMessages.find(
426
- (msg) => msg.name === `${Constants.LC_TRANSFER_TO_}agent_b`
427
- );
428
- expect(handoffMessage).toBeDefined();
429
- });
430
- });
431
-
432
- describe('Sequential Handoffs (Chain)', () => {
433
- it('should create handoff tools for chain of agents A -> B -> C', async () => {
434
- const agents: t.AgentInputs[] = [
435
- createBasicAgent('agent_a', 'You are agent A'),
436
- createBasicAgent('agent_b', 'You are agent B'),
437
- createBasicAgent('agent_c', 'You are agent C'),
438
- ];
439
-
440
- const edges: t.GraphEdge[] = [
441
- {
442
- from: 'agent_a',
443
- to: 'agent_b',
444
- edgeType: 'handoff',
445
- description: 'Transfer to agent B',
446
- },
447
- {
448
- from: 'agent_b',
449
- to: 'agent_c',
450
- edgeType: 'handoff',
451
- description: 'Transfer to agent C',
452
- },
453
- ];
454
-
455
- const run = await Run.create(createTestConfig(agents, edges));
456
-
457
- const agentAContext = (run.Graph as StandardGraph).agentContexts.get(
458
- 'agent_a'
459
- );
460
- const agentBContext = (run.Graph as StandardGraph).agentContexts.get(
461
- 'agent_b'
462
- );
463
- const agentCContext = (run.Graph as StandardGraph).agentContexts.get(
464
- 'agent_c'
465
- );
466
-
467
- // Agent A should have tool to transfer to B
468
- expect(
469
- findToolByName(
470
- agentAContext?.graphTools,
471
- `${Constants.LC_TRANSFER_TO_}agent_b`
472
- )
473
- ).toBeDefined();
474
-
475
- // Agent B should have tool to transfer to C
476
- expect(
477
- findToolByName(
478
- agentBContext?.graphTools,
479
- `${Constants.LC_TRANSFER_TO_}agent_c`
480
- )
481
- ).toBeDefined();
482
-
483
- // Agent C should have no handoff tools
484
- const agentCHandoffTools = agentCContext?.graphTools?.filter((tool) => {
485
- const name = getToolName(tool);
486
- return name?.startsWith(Constants.LC_TRANSFER_TO_) ?? false;
487
- });
488
- expect(agentCHandoffTools?.length ?? 0).toBe(0);
489
- });
490
- });
491
-
492
- describe('Multiple Handoff Options', () => {
493
- it('should create multiple handoff tools when agent has multiple outgoing edges', async () => {
494
- const agents: t.AgentInputs[] = [
495
- createBasicAgent('router', 'You are a router agent'),
496
- createBasicAgent('agent_a', 'You are agent A'),
497
- createBasicAgent('agent_b', 'You are agent B'),
498
- createBasicAgent('agent_c', 'You are agent C'),
499
- ];
500
-
501
- const edges: t.GraphEdge[] = [
502
- {
503
- from: 'router',
504
- to: 'agent_a',
505
- edgeType: 'handoff',
506
- description: 'Transfer to agent A for task A',
507
- },
508
- {
509
- from: 'router',
510
- to: 'agent_b',
511
- edgeType: 'handoff',
512
- description: 'Transfer to agent B for task B',
513
- },
514
- {
515
- from: 'router',
516
- to: 'agent_c',
517
- edgeType: 'handoff',
518
- description: 'Transfer to agent C for task C',
519
- },
520
- ];
521
-
522
- const run = await Run.create(createTestConfig(agents, edges));
523
-
524
- const routerContext = (run.Graph as StandardGraph).agentContexts.get(
525
- 'router'
526
- );
527
- expect(routerContext).toBeDefined();
528
-
529
- // Router should have 3 handoff tools
530
- const handoffTools = routerContext?.graphTools?.filter((tool) => {
531
- const name = getToolName(tool);
532
- return name?.startsWith(Constants.LC_TRANSFER_TO_) ?? false;
533
- });
534
- expect(handoffTools?.length).toBe(3);
535
-
536
- // Verify each tool exists
537
- expect(
538
- findToolByName(handoffTools, `${Constants.LC_TRANSFER_TO_}agent_a`)
539
- ).toBeDefined();
540
- expect(
541
- findToolByName(handoffTools, `${Constants.LC_TRANSFER_TO_}agent_b`)
542
- ).toBeDefined();
543
- expect(
544
- findToolByName(handoffTools, `${Constants.LC_TRANSFER_TO_}agent_c`)
545
- ).toBeDefined();
546
- });
547
-
548
- it('should route to correct agent based on handoff tool used', async () => {
549
- const agents: t.AgentInputs[] = [
550
- createBasicAgent('router', 'You are a router'),
551
- createBasicAgent('agent_a', 'You are agent A'),
552
- createBasicAgent('agent_b', 'You are agent B'),
553
- ];
554
-
555
- const edges: t.GraphEdge[] = [
556
- {
557
- from: 'router',
558
- to: 'agent_a',
559
- edgeType: 'handoff',
560
- description: 'Transfer to agent A',
561
- },
562
- {
563
- from: 'router',
564
- to: 'agent_b',
565
- edgeType: 'handoff',
566
- description: 'Transfer to agent B',
567
- },
568
- ];
569
-
570
- const run = await Run.create(createTestConfig(agents, edges));
571
-
572
- // Router chooses agent_b
573
- run.Graph?.overrideTestModel(
574
- ['Routing to agent B', 'Hello from agent B'],
575
- 10,
576
- [
577
- {
578
- id: 'tool_call_1',
579
- name: `${Constants.LC_TRANSFER_TO_}agent_b`,
580
- args: {},
581
- } as ToolCall,
582
- ]
583
- );
584
-
585
- const messages = [new HumanMessage('Route this message')];
586
-
587
- const config: Partial<RunnableConfig> & {
588
- version: 'v1' | 'v2';
589
- streamMode: string;
590
- } = {
591
- configurable: {
592
- thread_id: 'test-routing-thread',
593
- },
594
- streamMode: 'values',
595
- version: 'v2' as const,
596
- };
597
-
598
- await run.processStream({ messages }, config);
599
-
600
- const finalMessages = run.getRunMessages();
601
- const toolMessages = finalMessages!.filter(
602
- (msg) => msg.getType() === 'tool'
603
- ) as ToolMessage[];
604
-
605
- // Should have handoff to agent_b, not agent_a
606
- const handoffToB = toolMessages.find(
607
- (msg) => msg.name === `${Constants.LC_TRANSFER_TO_}agent_b`
608
- );
609
- expect(handoffToB).toBeDefined();
610
-
611
- const handoffToA = toolMessages.find(
612
- (msg) => msg.name === `${Constants.LC_TRANSFER_TO_}agent_a`
613
- );
614
- expect(handoffToA).toBeUndefined();
615
- });
616
- });
617
-
618
- describe('Parallel Handoffs', () => {
619
- it('should expose one runtime group on simultaneous destination content', async () => {
620
- const agents: t.AgentInputs[] = [
621
- createBasicAgent('router', 'You are a router'),
622
- createBasicAgent('left', 'You are the left specialist'),
623
- createBasicAgent('right', 'You are the right specialist'),
624
- ];
625
- const edges: t.GraphEdge[] = [
626
- { from: 'router', to: 'left', edgeType: 'handoff' },
627
- { from: 'router', to: 'right', edgeType: 'handoff' },
628
- ];
629
- const { contentParts, handlers } = createHandlers();
630
- const runConfig = createTestConfig(agents, edges);
631
- runConfig.customHandlers = handlers;
632
- const run = await Run.create(runConfig);
633
-
634
- run.Graph?.overrideTestModel(
635
- ['Routing', 'Left complete', 'Right complete'],
636
- 10,
637
- [
638
- {
639
- id: 'tool_call_left',
640
- name: `${Constants.LC_TRANSFER_TO_}left`,
641
- args: {},
642
- } as ToolCall,
643
- {
644
- id: 'tool_call_right',
645
- name: `${Constants.LC_TRANSFER_TO_}right`,
646
- args: {},
647
- } as ToolCall,
648
- ]
649
- );
650
-
651
- const config: Partial<RunnableConfig> & {
652
- version: 'v1' | 'v2';
653
- streamMode: string;
654
- } = {
655
- configurable: { thread_id: 'test-parallel-handoff-group-thread' },
656
- streamMode: 'values',
657
- version: 'v2',
658
- };
659
- await run.processStream(
660
- { messages: [new HumanMessage('Run both specialists')] },
661
- config
662
- );
663
-
664
- const definedParts = contentParts.filter(
665
- (part): part is t.MessageContentComplex => part != null
666
- );
667
- const routerParts = definedParts.filter(
668
- (part) => part.agentId === 'router'
669
- );
670
- const leftParts = definedParts.filter((part) => part.agentId === 'left');
671
- const rightParts = definedParts.filter(
672
- (part) => part.agentId === 'right'
673
- );
674
- const leftGroupId = leftParts[0]?.groupId;
675
-
676
- expect(routerParts.length).toBeGreaterThan(0);
677
- expect(routerParts.every((part) => part.groupId == null)).toBe(true);
678
- expect(leftParts.length).toBeGreaterThan(0);
679
- expect(rightParts.length).toBeGreaterThan(0);
680
- expect(leftGroupId).toEqual(expect.any(Number));
681
- expect(leftParts.every((part) => part.groupId === leftGroupId)).toBe(
682
- true
683
- );
684
- expect(rightParts.every((part) => part.groupId === leftGroupId)).toBe(
685
- true
686
- );
687
- });
688
-
689
- it('should checkpoint one durable group ID before parallel recipients run', async () => {
690
- const agents: t.AgentInputs[] = [
691
- createBasicAgent('router', 'You are a router'),
692
- createBasicAgent('left', 'You are the left specialist'),
693
- createBasicAgent('right', 'You are the right specialist'),
694
- ];
695
- const edges: t.GraphEdge[] = [
696
- { from: 'router', to: 'left', edgeType: 'handoff' },
697
- { from: 'router', to: 'right', edgeType: 'handoff' },
698
- ];
699
- const checkpointer = new MemorySaver();
700
- const runConfig = createTestConfig(agents, edges);
701
- runConfig.graphConfig.compileOptions = { checkpointer };
702
- const run = await Run.create(runConfig);
703
-
704
- run.Graph?.overrideTestModel(
705
- ['Routing', 'Left complete', 'Right complete'],
706
- 10,
707
- [
708
- {
709
- id: 'tool_call_checkpoint_left',
710
- name: `${Constants.LC_TRANSFER_TO_}left`,
711
- args: {},
712
- } as ToolCall,
713
- {
714
- id: 'tool_call_checkpoint_right',
715
- name: `${Constants.LC_TRANSFER_TO_}right`,
716
- args: {},
717
- } as ToolCall,
718
- ]
719
- );
720
-
721
- const threadId = 'test-parallel-handoff-checkpoint-thread';
722
- const config: Partial<RunnableConfig> & {
723
- version: 'v1' | 'v2';
724
- streamMode: string;
725
- durability: 'sync';
726
- } = {
727
- configurable: { thread_id: threadId },
728
- streamMode: 'values',
729
- version: 'v2',
730
- durability: 'sync',
731
- };
732
- const historicalToolCall = {
733
- id: 'tool_call_before_parallel_handoff',
734
- name: 'historical_lookup',
735
- args: {},
736
- };
737
- await run.processStream(
738
- {
739
- messages: [
740
- new HumanMessage('Look this up first'),
741
- new AIMessage({ content: '', tool_calls: [historicalToolCall] }),
742
- new ToolMessage({
743
- content: 'Historical result',
744
- name: historicalToolCall.name,
745
- tool_call_id: historicalToolCall.id,
746
- }),
747
- new HumanMessage('Run both specialists'),
748
- ],
749
- },
750
- config
751
- );
752
-
753
- let persistedHandoffs: ToolMessage[] = [];
754
- let persistedSends: PendingSend[] = [];
755
- for await (const tuple of checkpointer.list({
756
- configurable: { thread_id: threadId },
757
- })) {
758
- const sends = (tuple.pendingWrites ?? [])
759
- .filter(([, channel]) => channel === '__pregel_tasks')
760
- .map(([, , value]) => value)
761
- .filter(isPendingSend)
762
- .filter(({ node }) => node === 'left' || node === 'right');
763
- const handoffs = sends.flatMap((send) =>
764
- (send.args.messages ?? []).filter(
765
- (message): message is ToolMessage =>
766
- message.getType() === 'tool' &&
767
- message.name === `${Constants.LC_TRANSFER_TO_}${send.node}`
768
- )
769
- );
770
- if (handoffs.length === 2) {
771
- persistedHandoffs = handoffs;
772
- persistedSends = sends;
773
- break;
774
- }
775
- }
776
-
777
- expect(persistedHandoffs).toHaveLength(2);
778
- const persistedGroupIds = persistedHandoffs.map(
779
- (message) => message.additional_kwargs[Constants.HANDOFF_GROUP_ID]
780
- );
781
- const persistedBatchIds = persistedHandoffs.map(
782
- (message) => message.additional_kwargs[Constants.HANDOFF_PARALLEL_BATCH]
783
- );
784
- const persistedGroupId = persistedGroupIds[0];
785
- if (typeof persistedGroupId !== 'number') {
786
- throw new Error('Expected a persisted numeric handoff group ID');
787
- }
788
-
789
- expect(Number.isSafeInteger(persistedGroupId)).toBe(true);
790
- expect(persistedGroupId).toBeGreaterThanOrEqual(2 ** 48);
791
- expect(persistedGroupIds[1]).toBe(persistedGroupId);
792
- expect(persistedBatchIds[0]).toEqual(expect.any(String));
793
- expect(persistedBatchIds[1]).toBe(persistedBatchIds[0]);
794
-
795
- const historicalResults = persistedSends.flatMap((send) =>
796
- (send.args.messages ?? []).filter(
797
- (message): message is ToolMessage =>
798
- message.getType() === 'tool' &&
799
- (message as ToolMessage).tool_call_id === historicalToolCall.id
800
- )
801
- );
802
- expect(historicalResults).toHaveLength(2);
803
- for (const result of historicalResults) {
804
- expect(
805
- result.additional_kwargs[Constants.HANDOFF_PARALLEL_BATCH]
806
- ).toBeUndefined();
807
- expect(
808
- result.additional_kwargs[Constants.HANDOFF_GROUP_ID]
809
- ).toBeUndefined();
810
- expect(
811
- result.additional_kwargs.handoff_parallel_siblings
812
- ).toBeUndefined();
813
- }
814
- });
815
-
816
- it('should suppress a static group when a hybrid router selects one handoff', async () => {
817
- const agents: t.AgentInputs[] = [
818
- createBasicAgent('router', 'You are a router'),
819
- createBasicAgent('left', 'You are the left specialist'),
820
- createBasicAgent('right', 'You are the right specialist'),
821
- ];
822
- const edges: t.GraphEdge[] = [
823
- {
824
- from: 'router',
825
- to: ['left', 'right'],
826
- edgeType: 'direct',
827
- },
828
- { from: 'router', to: 'left', edgeType: 'handoff' },
829
- { from: 'router', to: 'right', edgeType: 'handoff' },
830
- ];
831
- const { contentParts, handlers } = createHandlers();
832
- const runConfig = createTestConfig(agents, edges);
833
- runConfig.customHandlers = handlers;
834
- const run = await Run.create(runConfig);
835
-
836
- run.Graph?.overrideTestModel(['Routing', 'Left complete'], 10, [
837
- {
838
- id: 'tool_call_left_only',
839
- name: `${Constants.LC_TRANSFER_TO_}left`,
840
- args: {},
841
- } as ToolCall,
842
- ]);
843
-
844
- const config: Partial<RunnableConfig> & {
845
- version: 'v1' | 'v2';
846
- streamMode: string;
847
- } = {
848
- configurable: { thread_id: 'test-hybrid-handoff-group-thread' },
849
- streamMode: 'values',
850
- version: 'v2',
851
- };
852
- await run.processStream(
853
- { messages: [new HumanMessage('Run only the left specialist')] },
854
- config
855
- );
856
-
857
- const definedParts = contentParts.filter(
858
- (part): part is t.MessageContentComplex => part != null
859
- );
860
- const leftParts = definedParts.filter((part) => part.agentId === 'left');
861
- const rightParts = definedParts.filter(
862
- (part) => part.agentId === 'right'
863
- );
864
-
865
- expect(leftParts.length).toBeGreaterThan(0);
866
- expect(leftParts.every((part) => part.groupId == null)).toBe(true);
867
- expect(rightParts).toHaveLength(0);
868
- });
869
-
870
- it('should not reuse a historical handoff when a target is later reached directly', async () => {
871
- const agents: t.AgentInputs[] = [
872
- createBasicAgent('router', 'historical-router-marker'),
873
- createBasicAgent('recipient', 'historical-recipient-agent-marker'),
874
- createBasicAgent('sibling', 'historical-sibling-agent-marker'),
875
- ];
876
- const edges: t.GraphEdge[] = [
877
- { from: 'router', to: 'recipient', edgeType: 'direct' },
878
- {
879
- from: 'router',
880
- to: 'recipient',
881
- edgeType: 'handoff',
882
- prompt: 'Instructions for the recipient',
883
- },
884
- {
885
- from: 'router',
886
- to: 'sibling',
887
- edgeType: 'handoff',
888
- prompt: 'Instructions for the sibling',
889
- },
890
- ];
891
- const run = await Run.create(createTestConfig(agents, edges));
892
- if (run.Graph == null) {
893
- throw new Error('Expected a multi-agent graph');
894
- }
895
- run.Graph.overrideModel = new ScriptedHandoffModel([
896
- {
897
- promptMarker: 'stale-recipient-instructions-marker',
898
- response: 'Historical recipient complete',
899
- },
900
- {
901
- promptMarker: 'second-direct-request-marker',
902
- response: 'Direct pass complete',
903
- },
904
- ]);
905
-
906
- const config: Partial<RunnableConfig> & {
907
- version: 'v1' | 'v2';
908
- streamMode: string;
909
- } = {
910
- configurable: {
911
- thread_id: 'test-historical-handoff-direct-thread',
912
- },
913
- streamMode: 'values',
914
- version: 'v2',
915
- };
916
- const historicalToolCall = {
917
- id: 'tool_call_historical_recipient',
918
- name: `${Constants.LC_TRANSFER_TO_}recipient`,
919
- args: { instructions: 'stale-recipient-instructions-marker' },
920
- };
921
- await run.processStream(
922
- {
923
- messages: [
924
- new HumanMessage('first-historical-request-marker'),
925
- new AIMessage({ content: '', tool_calls: [historicalToolCall] }),
926
- new ToolMessage({
927
- content:
928
- 'Successfully transferred to recipient\n\nInstructions: stale-recipient-instructions-marker',
929
- name: historicalToolCall.name,
930
- tool_call_id: historicalToolCall.id,
931
- additional_kwargs: {
932
- handoff_source_name: 'Router',
933
- handoff_instructions: 'stale-recipient-instructions-marker',
934
- handoff_parallel_siblings: ['sibling'],
935
- [Constants.HANDOFF_GROUP_ID]: 2 ** 48 + 1,
936
- },
937
- }),
938
- new HumanMessage('second-direct-request-marker'),
939
- ],
940
- },
941
- config
942
- );
943
-
944
- const recipientSteps = run.Graph.getRunSteps('recipient');
945
- expect(recipientSteps.length).toBeGreaterThan(0);
946
- expect(recipientSteps.every((step) => step.groupId == null)).toBe(true);
947
- const directPassMessages = run
948
- .getRunMessages()
949
- ?.filter(
950
- (message) =>
951
- message.getType() === 'ai' &&
952
- message.content === 'Direct pass complete'
953
- );
954
- expect(directPassMessages).toHaveLength(2);
955
- });
956
-
957
- it('should clear the handoff identity before a direct re-entry', async () => {
958
- const agents: t.AgentInputs[] = [
959
- {
960
- ...createBasicAgent('router', 'stale-context-router-marker'),
961
- name: 'Router',
962
- },
963
- {
964
- ...createBasicAgent('recipient', 'stale-context-recipient-marker'),
965
- name: 'Recipient',
966
- },
967
- {
968
- ...createBasicAgent('sibling', 'stale-context-sibling-marker'),
969
- name: 'Sibling',
970
- },
971
- {
972
- ...createBasicAgent('relay', 'stale-context-relay-marker'),
973
- name: 'Relay',
974
- },
975
- ];
976
- const edges: t.GraphEdge[] = [
977
- {
978
- from: 'router',
979
- to: 'recipient',
980
- edgeType: 'handoff',
981
- prompt: 'Instructions for the recipient',
982
- },
983
- {
984
- from: 'router',
985
- to: 'sibling',
986
- edgeType: 'handoff',
987
- prompt: 'Instructions for the sibling',
988
- },
989
- {
990
- from: 'recipient',
991
- to: 'relay',
992
- edgeType: 'handoff',
993
- prompt: 'Instructions for the relay',
994
- },
995
- { from: 'relay', to: 'recipient', edgeType: 'direct' },
996
- ];
997
- const run = await Run.create(createTestConfig(agents, edges));
998
- if (run.Graph == null) {
999
- throw new Error('Expected a multi-agent graph');
1000
- }
1001
- const model = new ScriptedHandoffModel([
1002
- {
1003
- promptMarker: 'stale-context-router-marker',
1004
- response: 'Routing in parallel',
1005
- toolCalls: [
1006
- {
1007
- id: 'tool_call_stale_context_recipient',
1008
- name: `${Constants.LC_TRANSFER_TO_}recipient`,
1009
- args: { instructions: 'recipient-first-handoff-marker' },
1010
- },
1011
- {
1012
- id: 'tool_call_stale_context_sibling',
1013
- name: `${Constants.LC_TRANSFER_TO_}sibling`,
1014
- args: { instructions: 'sibling-first-handoff-marker' },
1015
- },
1016
- ],
1017
- },
1018
- {
1019
- promptMarker: 'recipient-first-handoff-marker',
1020
- response: 'Sending through relay',
1021
- toolCalls: [
1022
- {
1023
- id: 'tool_call_stale_context_relay',
1024
- name: `${Constants.LC_TRANSFER_TO_}relay`,
1025
- args: { instructions: 'relay-handoff-marker' },
1026
- },
1027
- ],
1028
- },
1029
- {
1030
- promptMarker: 'sibling-first-handoff-marker',
1031
- response: 'Sibling complete',
1032
- },
1033
- {
1034
- promptMarker: 'relay-handoff-marker',
1035
- response: 'relay-direct-reentry-marker',
1036
- },
1037
- {
1038
- promptMarker: 'relay-direct-reentry-marker',
1039
- response: 'Recipient direct complete',
1040
- },
1041
- ]);
1042
- run.Graph.overrideModel = model;
1043
-
1044
- const config: Partial<RunnableConfig> & {
1045
- version: 'v1' | 'v2';
1046
- streamMode: string;
1047
- } = {
1048
- configurable: {
1049
- thread_id: 'test-clear-handoff-context-direct-reentry-thread',
1050
- },
1051
- streamMode: 'values',
1052
- version: 'v2',
1053
- };
1054
- await run.processStream(
1055
- { messages: [new HumanMessage('stale-context-router-marker')] },
1056
- config
1057
- );
1058
-
1059
- const recipientContext = run.Graph.agentContexts.get('recipient');
1060
- const recipientSystemRunnable = recipientContext?.systemRunnable;
1061
- if (recipientSystemRunnable == null) {
1062
- throw new Error('Expected recipient system instructions');
1063
- }
1064
- const recipientSystemPrompt = getBufferString(
1065
- await recipientSystemRunnable.invoke([])
1066
- );
1067
- expect(recipientSystemPrompt).toContain('stale-context-recipient-marker');
1068
- expect(recipientSystemPrompt).not.toContain('## Multi-Agent Workflow');
1069
- expect(recipientSystemPrompt).not.toContain('transferred from "Router"');
1070
- expect(recipientSystemPrompt).not.toContain('Running in parallel with:');
1071
- });
1072
-
1073
- it('should clear the runtime group after a parallel target hands off sequentially', async () => {
1074
- const agents: t.AgentInputs[] = [
1075
- createBasicAgent('router', 'router-script-marker'),
1076
- createBasicAgent('left', 'left-script-marker'),
1077
- createBasicAgent('right', 'right-script-marker'),
1078
- createBasicAgent('final', 'final-script-marker'),
1079
- ];
1080
- const edges: t.GraphEdge[] = [
1081
- {
1082
- from: 'router',
1083
- to: 'left',
1084
- edgeType: 'handoff',
1085
- prompt: 'Instructions for the left specialist',
1086
- },
1087
- {
1088
- from: 'router',
1089
- to: 'right',
1090
- edgeType: 'handoff',
1091
- prompt: 'Instructions for the right specialist',
1092
- },
1093
- {
1094
- from: 'left',
1095
- to: 'final',
1096
- edgeType: 'handoff',
1097
- prompt: 'Instructions for the final specialist',
1098
- },
1099
- ];
1100
- const run = await Run.create(createTestConfig(agents, edges));
1101
- if (run.Graph == null) {
1102
- throw new Error('Expected a multi-agent graph');
1103
- }
1104
- run.Graph.overrideModel = new ScriptedHandoffModel([
1105
- {
1106
- promptMarker: 'router-script-marker',
1107
- response: 'Routing',
1108
- toolCalls: [
1109
- {
1110
- id: 'tool_call_nested_left',
1111
- name: `${Constants.LC_TRANSFER_TO_}left`,
1112
- args: { instructions: 'left-script-marker' },
1113
- },
1114
- {
1115
- id: 'tool_call_nested_right',
1116
- name: `${Constants.LC_TRANSFER_TO_}right`,
1117
- args: { instructions: 'right-script-marker' },
1118
- },
1119
- ],
1120
- },
1121
- {
1122
- promptMarker: 'left-script-marker',
1123
- response: 'Forwarding',
1124
- toolCalls: [
1125
- {
1126
- id: 'tool_call_nested_final',
1127
- name: `${Constants.LC_TRANSFER_TO_}final`,
1128
- args: { instructions: 'final-script-marker' },
1129
- },
1130
- ],
1131
- },
1132
- {
1133
- promptMarker: 'right-script-marker',
1134
- response: 'Right complete',
1135
- },
1136
- {
1137
- promptMarker: 'final-script-marker',
1138
- response: 'Final complete',
1139
- },
1140
- ]);
1141
-
1142
- const config: Partial<RunnableConfig> & {
1143
- version: 'v1' | 'v2';
1144
- streamMode: string;
1145
- } = {
1146
- configurable: { thread_id: 'test-nested-handoff-group-thread' },
1147
- streamMode: 'values',
1148
- version: 'v2',
1149
- };
1150
- await run.processStream(
1151
- { messages: [new HumanMessage('router-script-marker')] },
1152
- config
1153
- );
1154
-
1155
- const leftSteps = run.Graph.getRunSteps('left');
1156
- const rightSteps = run.Graph.getRunSteps('right');
1157
- const finalSteps = run.Graph.getRunSteps('final');
1158
- const parallelGroupId = leftSteps[0]?.groupId;
1159
-
1160
- expect(parallelGroupId).toEqual(expect.any(Number));
1161
- expect(rightSteps.length).toBeGreaterThan(0);
1162
- expect(rightSteps.every((step) => step.groupId === parallelGroupId)).toBe(
1163
- true
1164
- );
1165
- expect(finalSteps.length).toBeGreaterThan(0);
1166
- expect(finalSteps.every((step) => step.groupId == null)).toBe(true);
1167
- });
1168
-
1169
- it('should remove every transfer call from mixed conditional recipient history', async () => {
1170
- const agents: t.AgentInputs[] = [
1171
- createBasicAgent('router', 'mixed-router-marker'),
1172
- createBasicAgent('left', 'mixed-left-marker'),
1173
- createBasicAgent('right', 'mixed-right-marker'),
1174
- ];
1175
- const edges: t.GraphEdge[] = [
1176
- {
1177
- from: 'router',
1178
- to: 'left',
1179
- edgeType: 'handoff',
1180
- prompt: 'Instructions for the left specialist',
1181
- },
1182
- {
1183
- from: 'router',
1184
- to: 'right',
1185
- condition: () => 'right',
1186
- prompt: 'Instructions for the right specialist',
1187
- },
1188
- ];
1189
- const run = await Run.create(createTestConfig(agents, edges));
1190
- if (run.Graph == null) {
1191
- throw new Error('Expected a multi-agent graph');
1192
- }
1193
- run.Graph.overrideModel = new ScriptedHandoffModel([
1194
- {
1195
- promptMarker: 'mixed-router-marker',
1196
- response: 'Routing',
1197
- toolCalls: [
1198
- {
1199
- id: 'tool_call_mixed_left',
1200
- name: `${Constants.LC_TRANSFER_TO_}left`,
1201
- args: { instructions: 'mixed-left-marker' },
1202
- },
1203
- {
1204
- id: 'tool_call_mixed_right',
1205
- name: 'conditional_transfer',
1206
- args: { instructions: 'mixed-right-marker' },
1207
- },
1208
- ],
1209
- },
1210
- {
1211
- promptMarker: 'mixed-left-marker',
1212
- response: 'Left complete',
1213
- },
1214
- {
1215
- promptMarker: 'mixed-right-marker',
1216
- response: 'Right complete',
1217
- },
1218
- ]);
1219
-
1220
- const config: Partial<RunnableConfig> & {
1221
- version: 'v1' | 'v2';
1222
- streamMode: string;
1223
- } = {
1224
- configurable: { thread_id: 'test-mixed-parallel-handoff-thread' },
1225
- streamMode: 'values',
1226
- version: 'v2',
1227
- };
1228
- await expect(
1229
- run.processStream(
1230
- { messages: [new HumanMessage('mixed-router-marker')] },
1231
- config
1232
- )
1233
- ).resolves.toBeDefined();
1234
-
1235
- const leftSteps = run.Graph.getRunSteps('left');
1236
- const rightSteps = run.Graph.getRunSteps('right');
1237
- const groupId = leftSteps[0]?.groupId;
1238
- expect(groupId).toEqual(expect.any(Number));
1239
- expect(rightSteps.length).toBeGreaterThan(0);
1240
- expect(rightSteps.every((step) => step.groupId === groupId)).toBe(true);
1241
- });
1242
- });
1243
-
1244
- describe('Handoffs with Prompts', () => {
1245
- it('should create handoff tool with prompt parameter when prompt is specified', async () => {
1246
- const agents: t.AgentInputs[] = [
1247
- createBasicAgent('agent_a', 'You are agent A'),
1248
- createBasicAgent('agent_b', 'You are agent B'),
1249
- ];
1250
-
1251
- const edges: t.GraphEdge[] = [
1252
- {
1253
- from: 'agent_a',
1254
- to: 'agent_b',
1255
- edgeType: 'handoff',
1256
- description: 'Transfer to agent B with instructions',
1257
- prompt: 'Provide specific instructions for agent B',
1258
- promptKey: 'instructions',
1259
- },
1260
- ];
1261
-
1262
- const run = await Run.create(createTestConfig(agents, edges));
1263
-
1264
- const agentAContext = (run.Graph as StandardGraph).agentContexts.get(
1265
- 'agent_a'
1266
- );
1267
- const handoffTool = findToolByName(
1268
- agentAContext?.graphTools,
1269
- `${Constants.LC_TRANSFER_TO_}agent_b`
1270
- );
1271
-
1272
- expect(handoffTool).toBeDefined();
1273
- // Tool should accept parameters (schema should be defined)
1274
- expect(getToolSchema(handoffTool!)).toBeDefined();
1275
- });
1276
-
1277
- it('should use default promptKey when not specified', async () => {
1278
- const agents: t.AgentInputs[] = [
1279
- createBasicAgent('agent_a', 'You are agent A'),
1280
- createBasicAgent('agent_b', 'You are agent B'),
1281
- ];
1282
-
1283
- const edges: t.GraphEdge[] = [
1284
- {
1285
- from: 'agent_a',
1286
- to: 'agent_b',
1287
- edgeType: 'handoff',
1288
- prompt: 'Instructions for handoff',
1289
- // promptKey not specified, should default to 'instructions'
1290
- },
1291
- ];
1292
-
1293
- const run = await Run.create(createTestConfig(agents, edges));
1294
-
1295
- const agentAContext = (run.Graph as StandardGraph).agentContexts.get(
1296
- 'agent_a'
1297
- );
1298
- const handoffTool = findToolByName(
1299
- agentAContext?.graphTools,
1300
- `${Constants.LC_TRANSFER_TO_}agent_b`
1301
- );
1302
-
1303
- expect(handoffTool).toBeDefined();
1304
- expect(getToolSchema(handoffTool!)).toBeDefined();
1305
- });
1306
-
1307
- it('should include prompt content in handoff tool message', async () => {
1308
- const agents: t.AgentInputs[] = [
1309
- createBasicAgent('agent_a', 'You are agent A'),
1310
- createBasicAgent('agent_b', 'You are agent B'),
1311
- ];
1312
-
1313
- const edges: t.GraphEdge[] = [
1314
- {
1315
- from: 'agent_a',
1316
- to: 'agent_b',
1317
- edgeType: 'handoff',
1318
- description: 'Transfer to agent B',
1319
- prompt: 'Additional context for agent B',
1320
- promptKey: 'context',
1321
- },
1322
- ];
1323
-
1324
- const run = await Run.create(createTestConfig(agents, edges));
1325
-
1326
- run.Graph?.overrideTestModel(['Transferring with context'], 10, [
1327
- {
1328
- id: 'tool_call_1',
1329
- name: `${Constants.LC_TRANSFER_TO_}agent_b`,
1330
- args: { context: 'User needs help with booking' },
1331
- } as ToolCall,
1332
- ]);
1333
-
1334
- const messages = [new HumanMessage('Help me')];
1335
-
1336
- const config: Partial<RunnableConfig> & {
1337
- version: 'v1' | 'v2';
1338
- streamMode: string;
1339
- } = {
1340
- configurable: {
1341
- thread_id: 'test-prompt-thread',
1342
- },
1343
- streamMode: 'values',
1344
- version: 'v2' as const,
1345
- };
1346
-
1347
- await run.processStream({ messages }, config);
1348
-
1349
- const finalMessages = run.getRunMessages();
1350
- const toolMessages = finalMessages!.filter(
1351
- (msg) => msg.getType() === 'tool'
1352
- ) as ToolMessage[];
1353
-
1354
- const handoffMessage = toolMessages.find(
1355
- (msg) => msg.name === `${Constants.LC_TRANSFER_TO_}agent_b`
1356
- );
1357
-
1358
- expect(handoffMessage).toBeDefined();
1359
- // Tool message should contain the prompt key and value
1360
- expect(handoffMessage?.content).toContain('Context:');
1361
- });
1362
-
1363
- it('should deliver custom prompt key content to the receiving agent', async () => {
1364
- const agents: t.AgentInputs[] = [
1365
- createBasicAgent('agent_a', 'You are agent A'),
1366
- createBasicAgent('agent_b', 'You are agent B'),
1367
- ];
1368
- const edges: t.GraphEdge[] = [
1369
- {
1370
- from: 'agent_a',
1371
- to: 'agent_b',
1372
- edgeType: 'handoff',
1373
- prompt: 'Brief for agent B',
1374
- promptKey: 'brief',
1375
- },
1376
- ];
1377
- const run = await Run.create(createTestConfig(agents, edges));
1378
- const brief = 'Investigate the cache invalidation path';
1379
- const rawBrief = ` ${brief}\n`;
1380
-
1381
- run.Graph?.overrideTestModel(
1382
- ['Transferring', 'Investigation complete'],
1383
- 10,
1384
- [
1385
- {
1386
- id: 'tool_call_custom_prompt',
1387
- name: `${Constants.LC_TRANSFER_TO_}agent_b`,
1388
- args: { brief: rawBrief },
1389
- } as ToolCall,
1390
- ]
1391
- );
1392
-
1393
- const config: Partial<RunnableConfig> & {
1394
- version: 'v1' | 'v2';
1395
- streamMode: string;
1396
- } = {
1397
- configurable: { thread_id: 'test-custom-prompt-key-thread' },
1398
- streamMode: 'values',
1399
- version: 'v2',
1400
- };
1401
- await run.processStream(
1402
- { messages: [new HumanMessage('Delegate this investigation')] },
1403
- config
1404
- );
1405
-
1406
- const receivedBrief = run
1407
- .getRunMessages()
1408
- ?.some(
1409
- (message) =>
1410
- message.getType() === 'human' && message.content === brief
1411
- );
1412
- expect(receivedBrief).toBe(true);
1413
- expect(
1414
- run
1415
- .getRunMessages()
1416
- ?.some(
1417
- (message) =>
1418
- message.getType() === 'human' && message.content === rawBrief
1419
- )
1420
- ).toBe(false);
1421
- });
1422
-
1423
- it('should deliver custom prompt key content through a conditional handoff', async () => {
1424
- const agents: t.AgentInputs[] = [
1425
- createBasicAgent('agent_a', 'You are agent A'),
1426
- createBasicAgent('agent_b', 'You are agent B'),
1427
- ];
1428
- const edges: t.GraphEdge[] = [
1429
- {
1430
- from: 'agent_a',
1431
- to: 'agent_b',
1432
- condition: () => 'agent_b',
1433
- prompt: 'Brief for agent B',
1434
- promptKey: 'brief',
1435
- },
1436
- ];
1437
- const run = await Run.create(createTestConfig(agents, edges));
1438
- const brief = 'Review the conditional routing result';
1439
-
1440
- run.Graph?.overrideTestModel(['Transferring', 'Review complete'], 10, [
1441
- {
1442
- id: 'tool_call_conditional_prompt',
1443
- name: 'conditional_transfer',
1444
- args: { brief },
1445
- } as ToolCall,
1446
- ]);
1447
-
1448
- const config: Partial<RunnableConfig> & {
1449
- version: 'v1' | 'v2';
1450
- streamMode: string;
1451
- } = {
1452
- configurable: {
1453
- thread_id: 'test-conditional-custom-prompt-key-thread',
1454
- },
1455
- streamMode: 'values',
1456
- version: 'v2',
1457
- };
1458
- await run.processStream(
1459
- { messages: [new HumanMessage('Delegate conditionally')] },
1460
- config
1461
- );
1462
-
1463
- const receivedBrief = run
1464
- .getRunMessages()
1465
- ?.some(
1466
- (message) =>
1467
- message.getType() === 'human' && message.content === brief
1468
- );
1469
- expect(receivedBrief).toBe(true);
1470
- });
1471
-
1472
- it('should recover a complete custom-key payload from a legacy checkpoint', async () => {
1473
- const agents: t.AgentInputs[] = [
1474
- createBasicAgent('agent_a', 'You are agent A'),
1475
- createBasicAgent('agent_b', 'You are agent B'),
1476
- ];
1477
- const edges: t.GraphEdge[] = [
1478
- {
1479
- from: 'agent_a',
1480
- to: 'agent_b',
1481
- edgeType: 'handoff',
1482
- prompt: 'Brief for agent B',
1483
- promptKey: 'brief',
1484
- },
1485
- ];
1486
- const run = await Run.create(createTestConfig(agents, edges));
1487
- const graph = run.Graph as unknown as HandoffReceptionProbe;
1488
- const toolCall = {
1489
- id: 'tool_call_legacy_prompt',
1490
- name: `${Constants.LC_TRANSFER_TO_}agent_b`,
1491
- args: {},
1492
- };
1493
- const payload =
1494
- 'Inspect the routing decision.\nContext: retain this entire line.';
1495
- const context = graph.processHandoffReception(
1496
- [
1497
- new AIMessage({ content: '', tool_calls: [toolCall] }),
1498
- new ToolMessage({
1499
- content: `Successfully transferred to agent_b\n\nBrief: ${payload}`,
1500
- name: toolCall.name,
1501
- tool_call_id: toolCall.id,
1502
- }),
1503
- ],
1504
- 'agent_b'
1505
- );
1506
-
1507
- expect(context?.instructions).toBe(payload);
1508
-
1509
- const whitespaceContext = graph.processHandoffReception(
1510
- [
1511
- new AIMessage({
1512
- content: '',
1513
- tool_calls: [
1514
- {
1515
- id: 'tool_call_whitespace_prompt',
1516
- name: `${Constants.LC_TRANSFER_TO_}agent_b`,
1517
- args: {},
1518
- },
1519
- ],
1520
- }),
1521
- new ToolMessage({
1522
- content: 'Successfully transferred to agent_b\n\nBrief: ',
1523
- name: `${Constants.LC_TRANSFER_TO_}agent_b`,
1524
- tool_call_id: 'tool_call_whitespace_prompt',
1525
- additional_kwargs: {
1526
- handoff_instructions: ' \n ',
1527
- },
1528
- }),
1529
- ],
1530
- 'agent_b'
1531
- );
1532
- expect(whitespaceContext?.instructions).toBe('');
1533
- });
1534
- });
1535
-
1536
- describe('Edge Cases and Error Handling', () => {
1537
- it('should handle self-referential edge gracefully', async () => {
1538
- const agents: t.AgentInputs[] = [
1539
- createBasicAgent('agent_a', 'You are agent A'),
1540
- ];
1541
-
1542
- const edges: t.GraphEdge[] = [
1543
- {
1544
- from: 'agent_a',
1545
- to: 'agent_a',
1546
- edgeType: 'handoff',
1547
- description: 'Self-handoff (should be allowed but unusual)',
1548
- },
1549
- ];
1550
-
1551
- // Should not throw during creation
1552
- expect(async () => {
1553
- await Run.create(createTestConfig(agents, edges));
1554
- }).not.toThrow();
1555
- });
1556
-
1557
- it('should handle empty edges array', async () => {
1558
- const agents: t.AgentInputs[] = [
1559
- createBasicAgent('agent_a', 'You are agent A'),
1560
- createBasicAgent('agent_b', 'You are agent B'),
1561
- ];
1562
-
1563
- const edges: t.GraphEdge[] = [];
1564
-
1565
- const run = await Run.create(createTestConfig(agents, edges));
1566
-
1567
- expect(run.Graph).toBeDefined();
1568
-
1569
- // Agents should have no handoff tools
1570
- const agentAContext = (run.Graph as StandardGraph).agentContexts.get(
1571
- 'agent_a'
1572
- );
1573
- const handoffTools = agentAContext?.graphTools?.filter((tool) => {
1574
- const name = getToolName(tool);
1575
- return name?.startsWith(Constants.LC_TRANSFER_TO_) ?? false;
1576
- });
1577
- expect(handoffTools?.length ?? 0).toBe(0);
1578
- });
1579
-
1580
- it('should start from first agent when no edges are defined', async () => {
1581
- const agents: t.AgentInputs[] = [
1582
- createBasicAgent('agent_a', 'You are agent A'),
1583
- createBasicAgent('agent_b', 'You are agent B'),
1584
- ];
1585
-
1586
- const edges: t.GraphEdge[] = [];
1587
-
1588
- const run = await Run.create(createTestConfig(agents, edges));
1589
-
1590
- run.Graph?.overrideTestModel(['Response from first agent'], 10);
1591
-
1592
- const messages = [new HumanMessage('Hello')];
1593
-
1594
- const config: Partial<RunnableConfig> & {
1595
- version: 'v1' | 'v2';
1596
- streamMode: string;
1597
- } = {
1598
- configurable: {
1599
- thread_id: 'test-no-edges-thread',
1600
- },
1601
- streamMode: 'values',
1602
- version: 'v2' as const,
1603
- };
1604
-
1605
- await run.processStream({ messages }, config);
1606
-
1607
- const finalMessages = run.getRunMessages();
1608
- expect(finalMessages).toBeDefined();
1609
- expect(finalMessages!.length).toBeGreaterThan(0);
1610
- });
1611
-
1612
- it('should handle agents with existing tools alongside handoff tools', async () => {
1613
- const customTool = new DynamicStructuredTool({
1614
- name: 'custom_tool',
1615
- description: 'A custom tool',
1616
- schema: { type: 'object', properties: {}, required: [] },
1617
- func: async (): Promise<string> => 'Tool result',
1618
- });
1619
-
1620
- const agents: t.AgentInputs[] = [
1621
- {
1622
- ...createBasicAgent('agent_a', 'You are agent A'),
1623
- tools: [customTool],
1624
- },
1625
- createBasicAgent('agent_b', 'You are agent B'),
1626
- ];
1627
-
1628
- const edges: t.GraphEdge[] = [
1629
- {
1630
- from: 'agent_a',
1631
- to: 'agent_b',
1632
- edgeType: 'handoff',
1633
- description: 'Transfer to agent B',
1634
- },
1635
- ];
1636
-
1637
- const run = await Run.create(createTestConfig(agents, edges));
1638
-
1639
- const agentAContext = (run.Graph as StandardGraph).agentContexts.get(
1640
- 'agent_a'
1641
- );
1642
-
1643
- // Agent A should have custom tool in tools and handoff tool in graphTools
1644
- expect(findToolByName(agentAContext?.tools, 'custom_tool')).toBeDefined();
1645
-
1646
- expect(
1647
- findToolByName(
1648
- agentAContext?.graphTools,
1649
- `${Constants.LC_TRANSFER_TO_}agent_b`
1650
- )
1651
- ).toBeDefined();
1652
- });
1653
- });
1654
-
1655
- describe('Graph Structure Analysis', () => {
1656
- it('should correctly identify starting nodes with no incoming edges', async () => {
1657
- const agents: t.AgentInputs[] = [
1658
- createBasicAgent('agent_a', 'Starting agent'),
1659
- createBasicAgent('agent_b', 'Middle agent'),
1660
- createBasicAgent('agent_c', 'End agent'),
1661
- ];
1662
-
1663
- const edges: t.GraphEdge[] = [
1664
- {
1665
- from: 'agent_a',
1666
- to: 'agent_b',
1667
- edgeType: 'handoff',
1668
- },
1669
- {
1670
- from: 'agent_b',
1671
- to: 'agent_c',
1672
- edgeType: 'handoff',
1673
- },
1674
- ];
1675
-
1676
- const run = await Run.create(createTestConfig(agents, edges));
1677
-
1678
- // agent_a should be the starting node (no incoming edges)
1679
- expect(run.Graph).toBeDefined();
1680
- // This is internal behavior, but we can test via execution
1681
- run.Graph?.overrideTestModel(['Response from agent A'], 10);
1682
-
1683
- const messages = [new HumanMessage('Start')];
1684
-
1685
- const config: Partial<RunnableConfig> & {
1686
- version: 'v1' | 'v2';
1687
- streamMode: string;
1688
- } = {
1689
- configurable: {
1690
- thread_id: 'test-starting-node-thread',
1691
- },
1692
- streamMode: 'values',
1693
- version: 'v2' as const,
1694
- };
1695
-
1696
- // Should start from agent_a
1697
- await run.processStream({ messages }, config);
1698
-
1699
- const finalMessages = run.getRunMessages();
1700
- expect(finalMessages).toBeDefined();
1701
- });
1702
-
1703
- it('should handle multiple starting nodes (parallel entry points)', async () => {
1704
- const agents: t.AgentInputs[] = [
1705
- createBasicAgent('agent_a', 'Starting agent A'),
1706
- createBasicAgent('agent_b', 'Starting agent B'),
1707
- createBasicAgent('agent_c', 'Shared destination'),
1708
- ];
1709
-
1710
- const edges: t.GraphEdge[] = [
1711
- {
1712
- from: 'agent_a',
1713
- to: 'agent_c',
1714
- edgeType: 'handoff',
1715
- },
1716
- {
1717
- from: 'agent_b',
1718
- to: 'agent_c',
1719
- edgeType: 'handoff',
1720
- },
1721
- ];
1722
-
1723
- // Both agent_a and agent_b have no incoming edges, so both are starting nodes
1724
- const run = await Run.create(createTestConfig(agents, edges));
1725
-
1726
- expect(run.Graph).toBeDefined();
1727
- });
1728
- });
1729
-
1730
- describe('Tool Call Before Handoff (Issue #54)', () => {
1731
- it('should complete handoff when router calls a non-handoff tool in the same turn', async () => {
1732
- /**
1733
- * Reproduces the bug from issue #54:
1734
- * When a router calls a regular tool AND a handoff tool in the same turn,
1735
- * the filtered messages for the receiving agent end with a ToolMessage.
1736
- * Previously, instructions were appended as a HumanMessage (tool → user),
1737
- * which many APIs reject. The fix injects instructions into the last
1738
- * ToolMessage instead.
1739
- */
1740
- const customTool = new DynamicStructuredTool({
1741
- name: 'list_upload_sessions',
1742
- description: 'List available upload sessions',
1743
- schema: { type: 'object', properties: {}, required: [] },
1744
- func: async (): Promise<string> =>
1745
- JSON.stringify({ sessions: [{ id: 'sess_1', status: 'ready' }] }),
1746
- });
1747
-
1748
- const agents: t.AgentInputs[] = [
1749
- {
1750
- ...createBasicAgent('router', 'You are a router'),
1751
- tools: [customTool],
1752
- toolMap: new Map([['list_upload_sessions', customTool]]) as t.ToolMap,
1753
- },
1754
- createBasicAgent('data_analyst', 'You are a data analyst'),
1755
- ];
1756
-
1757
- const edges: t.GraphEdge[] = [
1758
- {
1759
- from: 'router',
1760
- to: 'data_analyst',
1761
- edgeType: 'handoff',
1762
- description: 'Transfer to data analyst',
1763
- prompt: 'Instructions for the analyst about what to analyze',
1764
- promptKey: 'instructions',
1765
- },
1766
- ];
1767
-
1768
- const run = await Run.create(createTestConfig(agents, edges));
1769
-
1770
- /**
1771
- * Simulate router calling list_upload_sessions AND handoff in the same turn.
1772
- * The first model response includes both tool calls.
1773
- * The second model response is the data_analyst's reply.
1774
- */
1775
- run.Graph?.overrideTestModel(
1776
- [
1777
- 'Checking available sessions and transferring to analyst',
1778
- 'Here is my analysis of the available sessions',
1779
- ],
1780
- 10,
1781
- [
1782
- {
1783
- id: 'tool_call_1',
1784
- name: 'list_upload_sessions',
1785
- args: {},
1786
- } as ToolCall,
1787
- {
1788
- id: 'tool_call_2',
1789
- name: `${Constants.LC_TRANSFER_TO_}data_analyst`,
1790
- args: { instructions: 'Analyze the upload session data' },
1791
- } as ToolCall,
1792
- ]
1793
- );
1794
-
1795
- const messages = [
1796
- new HumanMessage('Check my upload sessions and analyze them'),
1797
- ];
1798
-
1799
- const config: Partial<RunnableConfig> & {
1800
- version: 'v1' | 'v2';
1801
- streamMode: string;
1802
- } = {
1803
- configurable: {
1804
- thread_id: 'test-tool-before-handoff-thread',
1805
- },
1806
- streamMode: 'values',
1807
- version: 'v2' as const,
1808
- };
1809
-
1810
- /**
1811
- * This should complete without error. Before the fix, the receiving
1812
- * agent would get an invalid tool → user message sequence.
1813
- */
1814
- await run.processStream({ messages }, config);
1815
-
1816
- const finalMessages = run.getRunMessages();
1817
- expect(finalMessages).toBeDefined();
1818
- expect(finalMessages!.length).toBeGreaterThan(1);
1819
-
1820
- /** Verify that the handoff occurred */
1821
- const toolMessages = finalMessages!.filter(
1822
- (msg) => msg.getType() === 'tool'
1823
- ) as ToolMessage[];
1824
-
1825
- const handoffMessage = toolMessages.find(
1826
- (msg) => msg.name === `${Constants.LC_TRANSFER_TO_}data_analyst`
1827
- );
1828
- expect(handoffMessage).toBeDefined();
1829
-
1830
- /** Verify the flow completed (agent B responded) */
1831
- const aiMessages = finalMessages!.filter((msg) => msg.getType() === 'ai');
1832
- expect(aiMessages.length).toBeGreaterThanOrEqual(1);
1833
- });
1834
- });
1835
-
1836
- describe('Handoff Tool Naming', () => {
1837
- it('should use correct naming convention for handoff tools', async () => {
1838
- const agents: t.AgentInputs[] = [
1839
- createBasicAgent('flight_assistant', 'You handle flights'),
1840
- createBasicAgent('hotel_assistant', 'You handle hotels'),
1841
- ];
1842
-
1843
- const edges: t.GraphEdge[] = [
1844
- {
1845
- from: 'flight_assistant',
1846
- to: 'hotel_assistant',
1847
- edgeType: 'handoff',
1848
- description: 'Transfer to hotel booking',
1849
- },
1850
- ];
1851
-
1852
- const run = await Run.create(createTestConfig(agents, edges));
1853
-
1854
- const flightContext = (run.Graph as StandardGraph).agentContexts.get(
1855
- 'flight_assistant'
1856
- );
1857
- const handoffTool = findToolByName(
1858
- flightContext?.graphTools,
1859
- `${Constants.LC_TRANSFER_TO_}hotel_assistant`
1860
- );
1861
-
1862
- expect(handoffTool).toBeDefined();
1863
- expect(getToolName(handoffTool!)).toBe(
1864
- `${Constants.LC_TRANSFER_TO_}hotel_assistant`
1865
- );
1866
- });
1867
-
1868
- it('should preserve agent ID format in tool names', async () => {
1869
- const agents: t.AgentInputs[] = [
1870
- createBasicAgent('agent_with_underscores', 'Agent with underscores'),
1871
- createBasicAgent('AgentWithCamelCase', 'Agent with camel case'),
1872
- ];
1873
-
1874
- const edges: t.GraphEdge[] = [
1875
- {
1876
- from: 'agent_with_underscores',
1877
- to: 'AgentWithCamelCase',
1878
- edgeType: 'handoff',
1879
- },
1880
- ];
1881
-
1882
- const run = await Run.create(createTestConfig(agents, edges));
1883
-
1884
- const agentContext = (run.Graph as StandardGraph).agentContexts.get(
1885
- 'agent_with_underscores'
1886
- );
1887
- const handoffTool = findToolByName(
1888
- agentContext?.graphTools,
1889
- `${Constants.LC_TRANSFER_TO_}AgentWithCamelCase`
1890
- );
1891
-
1892
- expect(handoffTool).toBeDefined();
1893
- expect(getToolName(handoffTool!)).toBe(
1894
- `${Constants.LC_TRANSFER_TO_}AgentWithCamelCase`
1895
- );
1896
- });
1897
-
1898
- it('should return exact-name guidance for handoff names with extra suffixes', async () => {
1899
- const agents: t.AgentInputs[] = [
1900
- createBasicAgent('router', 'You are a router'),
1901
- createBasicAgent('data_analyst', 'You are a data analyst'),
1902
- ];
1903
-
1904
- const edges: t.GraphEdge[] = [
1905
- {
1906
- from: 'router',
1907
- to: 'data_analyst',
1908
- edgeType: 'handoff',
1909
- },
1910
- ];
1911
-
1912
- const run = await Run.create(createTestConfig(agents, edges));
1913
- const correctName = `${Constants.LC_TRANSFER_TO_}data_analyst`;
1914
- const wrongName = `${correctName}_analyst`;
1915
-
1916
- run.Graph?.overrideTestModel(
1917
- ['Trying to transfer', 'Stopping after invalid tool name'],
1918
- 10,
1919
- [
1920
- {
1921
- id: 'tool_call_wrong_handoff',
1922
- name: wrongName,
1923
- args: { instructions: 'Analyze the uploaded data' },
1924
- } as ToolCall,
1925
- ]
1926
- );
1927
-
1928
- const config: Partial<RunnableConfig> & {
1929
- version: 'v1' | 'v2';
1930
- streamMode: string;
1931
- } = {
1932
- configurable: {
1933
- thread_id: 'test-wrong-handoff-name-thread',
1934
- },
1935
- streamMode: 'values',
1936
- version: 'v2' as const,
1937
- };
1938
-
1939
- await run.processStream(
1940
- { messages: [new HumanMessage('Please analyze my data')] },
1941
- config
1942
- );
1943
-
1944
- const toolMessages = run
1945
- .getRunMessages()!
1946
- .filter((msg) => msg.getType() === 'tool') as ToolMessage[];
1947
- const wrongNameMessage = toolMessages.find(
1948
- (msg) => msg.name === wrongName
1949
- );
1950
-
1951
- expect(wrongNameMessage).toBeDefined();
1952
- expect(wrongNameMessage?.status).toBe('error');
1953
- expect(wrongNameMessage?.content).toContain(
1954
- `Did you mean "${correctName}"`
1955
- );
1956
- });
1957
-
1958
- it('should include toolMap handoffs when direct tool names are present', async () => {
1959
- const correctName = `${Constants.LC_TRANSFER_TO_}data_analyst`;
1960
- const wrongName = `${correctName}_analyst`;
1961
- const handoffTool = new DynamicStructuredTool({
1962
- name: correctName,
1963
- description: 'Transfer to data analyst',
1964
- schema: { type: 'object', properties: {}, required: [] },
1965
- func: async (): Promise<string> => 'transferred',
1966
- }) as t.GenericTool;
1967
- const node = new ToolNode({
1968
- tools: [handoffTool],
1969
- directToolNames: new Set(['execute_code']),
1970
- });
1971
- const result = (await node.invoke({
1972
- messages: [
1973
- new AIMessage({
1974
- content: '',
1975
- tool_calls: [{ id: 'wrong_handoff', name: wrongName, args: {} }],
1976
- }),
1977
- ],
1978
- })) as { messages: ToolMessage[] };
1979
- const wrongNameMessage = result.messages.find(
1980
- (msg) => msg.tool_call_id === 'wrong_handoff'
1981
- );
1982
-
1983
- expect(wrongNameMessage).toBeDefined();
1984
- expect(wrongNameMessage?.status).toBe('error');
1985
- expect(wrongNameMessage?.content).toContain(
1986
- `Did you mean "${correctName}"`
1987
- );
1988
- });
1989
-
1990
- it('should keep event-driven unknown handoffs local without direct tool names', async () => {
1991
- const executedToolNames: string[] = [];
1992
- const correctName = `${Constants.LC_TRANSFER_TO_}data_analyst`;
1993
- const wrongName = `${correctName}_analyst`;
1994
- const lookupName = 'lookup_sessions';
1995
- const handoffTool = new DynamicStructuredTool({
1996
- name: correctName,
1997
- description: 'Transfer to data analyst',
1998
- schema: { type: 'object', properties: {}, required: [] },
1999
- func: async (): Promise<string> => 'transferred',
2000
- }) as t.GenericTool;
2001
- const lookupTool = new DynamicStructuredTool({
2002
- name: lookupName,
2003
- description: 'List upload sessions',
2004
- schema: { type: 'object', properties: {}, required: [] },
2005
- func: async (): Promise<string> => 'sessions',
2006
- }) as t.GenericTool;
2007
- const dispatchSpy = jest
2008
- .spyOn(events, 'safeDispatchCustomEvent')
2009
- .mockImplementation(async (event, data): Promise<void> => {
2010
- if (event !== GraphEvents.ON_TOOL_EXECUTE) {
2011
- return;
2012
- }
2013
- const batch = data as t.ToolExecuteBatchRequest;
2014
- executedToolNames.push(
2015
- ...batch.toolCalls.map((toolCall) => toolCall.name)
2016
- );
2017
- batch.resolve(
2018
- batch.toolCalls.map((toolCall) => ({
2019
- toolCallId: toolCall.id,
2020
- status: 'success' as const,
2021
- content: `host result for ${toolCall.name}`,
2022
- }))
2023
- );
2024
- });
2025
- const node = new ToolNode({
2026
- tools: [handoffTool, lookupTool],
2027
- eventDrivenMode: true,
2028
- toolCallStepIds: new Map([
2029
- ['lookup_call', 'step_lookup'],
2030
- ['wrong_handoff', 'step_wrong_handoff'],
2031
- ]),
2032
- });
2033
-
2034
- try {
2035
- const result = (await node.invoke({
2036
- messages: [
2037
- new AIMessage({
2038
- content: '',
2039
- tool_calls: [
2040
- { id: 'lookup_call', name: lookupName, args: {} },
2041
- { id: 'wrong_handoff', name: wrongName, args: {} },
2042
- ],
2043
- }),
2044
- ],
2045
- })) as { messages: ToolMessage[] };
2046
- const wrongNameMessage = result.messages.find(
2047
- (msg) => msg.tool_call_id === 'wrong_handoff'
2048
- );
2049
-
2050
- expect(executedToolNames).toEqual([lookupName]);
2051
- expect(wrongNameMessage).toBeDefined();
2052
- expect(wrongNameMessage?.status).toBe('error');
2053
- expect(wrongNameMessage?.content).toContain(
2054
- `Did you mean "${correctName}"`
2055
- );
2056
- } finally {
2057
- dispatchSpy.mockRestore();
2058
- }
2059
- });
2060
-
2061
- it('should not dispatch mistyped graph handoffs to event-driven tool hosts', async () => {
2062
- const executedToolNames: string[] = [];
2063
- const agents: t.AgentInputs[] = [
2064
- {
2065
- ...createBasicAgent('router', 'You are a router'),
2066
- toolDefinitions: [
2067
- {
2068
- name: 'lookup_sessions',
2069
- description: 'List upload sessions',
2070
- parameters: {
2071
- type: 'object',
2072
- properties: {},
2073
- required: [],
2074
- },
2075
- },
2076
- ],
2077
- },
2078
- createBasicAgent('data_analyst', 'You are a data analyst'),
2079
- ];
2080
-
2081
- const edges: t.GraphEdge[] = [
2082
- {
2083
- from: 'router',
2084
- to: 'data_analyst',
2085
- edgeType: 'handoff',
2086
- },
2087
- ];
2088
-
2089
- const run = await Run.create({
2090
- ...createTestConfig(agents, edges),
2091
- customHandlers: {
2092
- [GraphEvents.ON_TOOL_EXECUTE]: {
2093
- handle: (_event: string, data: t.StreamEventData): void => {
2094
- const batch = data as t.ToolExecuteBatchRequest;
2095
- executedToolNames.push(
2096
- ...batch.toolCalls.map((toolCall) => toolCall.name)
2097
- );
2098
- batch.resolve(
2099
- batch.toolCalls.map((toolCall) => ({
2100
- toolCallId: toolCall.id,
2101
- status: 'success' as const,
2102
- content: `host result for ${toolCall.name}`,
2103
- }))
2104
- );
2105
- },
2106
- },
2107
- },
2108
- });
2109
- const correctName = `${Constants.LC_TRANSFER_TO_}data_analyst`;
2110
- const wrongName = `${correctName}_analyst`;
2111
-
2112
- run.Graph?.overrideTestModel(
2113
- ['Checking sessions and transferring', 'Handled invalid transfer'],
2114
- 10,
2115
- [
2116
- {
2117
- id: 'tool_call_lookup',
2118
- name: 'lookup_sessions',
2119
- args: {},
2120
- } as ToolCall,
2121
- {
2122
- id: 'tool_call_wrong_handoff',
2123
- name: wrongName,
2124
- args: { instructions: 'Analyze the upload session data' },
2125
- } as ToolCall,
2126
- ]
2127
- );
2128
-
2129
- const config: Partial<RunnableConfig> & {
2130
- version: 'v1' | 'v2';
2131
- streamMode: string;
2132
- } = {
2133
- configurable: {
2134
- thread_id: 'test-event-wrong-handoff-name-thread',
2135
- },
2136
- streamMode: 'values',
2137
- version: 'v2' as const,
2138
- };
2139
-
2140
- await run.processStream(
2141
- { messages: [new HumanMessage('Check my sessions and analyze them')] },
2142
- config
2143
- );
2144
-
2145
- const toolMessages = run
2146
- .getRunMessages()!
2147
- .filter((msg) => msg.getType() === 'tool') as ToolMessage[];
2148
- const wrongNameMessage = toolMessages.find(
2149
- (msg) => msg.name === wrongName
2150
- );
2151
-
2152
- expect(executedToolNames).toEqual(['lookup_sessions']);
2153
- expect(wrongNameMessage).toBeDefined();
2154
- expect(wrongNameMessage?.status).toBe('error');
2155
- expect(wrongNameMessage?.content).toContain(
2156
- `Did you mean "${correctName}"`
2157
- );
2158
- });
2159
- });
2160
-
2161
- describe('Handoffs with a malformed sibling call (invalid_tool_calls regression)', () => {
2162
- /**
2163
- * Regression for the invalid-call promotion crossing handoff boundaries:
2164
- * a handoff tool snapshots `update.messages` from the PRE-promotion state
2165
- * with a filtered same-id copy of the AI message, and commands apply
2166
- * after sibling reducer updates. Un-patched, the stale copy overwrote the
2167
- * promoted replacement and a parallel Send child's state omitted the
2168
- * synthesized result — the child agent's provider request then carried an
2169
- * invalid call/result pairing. `validateToolHistory` inside the scripted
2170
- * model asserts the pairing on EVERY model invocation, including the
2171
- * children's.
2172
- */
2173
- const MALFORMED_CALL_ID = 'tool_call_malformed_sibling';
2174
-
2175
- /** Corrupts the malformed sibling's streamed args into a non-object JSON
2176
- * string so `collapseToolCallChunks` files it under `invalid_tool_calls`
2177
- * — the shape a malformed provider stream produces. */
2178
- class MalformedSiblingHandoffModel extends ScriptedHandoffModel {
2179
- override async *_streamResponseChunks(
2180
- messages: t.BaseGraphState['messages'],
2181
- options: this['ParsedCallOptions'],
2182
- runManager?: CallbackManagerForLLMRun
2183
- ): AsyncGenerator<ChatGenerationChunk> {
2184
- for await (const chunk of super._streamResponseChunks(
2185
- messages,
2186
- options,
2187
- runManager
2188
- )) {
2189
- const chunkMessage = chunk.message as unknown as {
2190
- tool_call_chunks?: Array<{ id?: string; args?: string }>;
2191
- };
2192
- for (const toolCallChunk of chunkMessage.tool_call_chunks ?? []) {
2193
- if (toolCallChunk.id === MALFORMED_CALL_ID) {
2194
- toolCallChunk.args = '"malformed';
2195
- }
2196
- }
2197
- yield chunk;
2198
- }
2199
- }
2200
- }
2201
-
2202
- const expectPromotedPairing = (
2203
- finalMessages: t.BaseGraphState['messages']
2204
- ): void => {
2205
- const promoted = finalMessages.find(
2206
- (msg): msg is AIMessage =>
2207
- msg.getType() === 'ai' &&
2208
- ((msg as AIMessage).tool_calls ?? []).some(
2209
- (call) => call.id === MALFORMED_CALL_ID
2210
- )
2211
- );
2212
- expect(promoted).toBeDefined();
2213
- expect(promoted!.invalid_tool_calls ?? []).toHaveLength(0);
2214
- const synthesized = finalMessages.find(
2215
- (msg): msg is ToolMessage =>
2216
- msg.getType() === 'tool' &&
2217
- (msg as ToolMessage).tool_call_id === MALFORMED_CALL_ID
2218
- );
2219
- expect(synthesized).toBeDefined();
2220
- expect(String(synthesized!.content)).toContain('Malformed');
2221
- };
2222
-
2223
- it('single handoff: the child state keeps the promoted call and its synthesized result', async () => {
2224
- const agents: t.AgentInputs[] = [
2225
- createBasicAgent('router', 'You are a router'),
2226
- createBasicAgent('specialist', 'You are the specialist'),
2227
- ];
2228
- const edges: t.GraphEdge[] = [
2229
- {
2230
- from: 'router',
2231
- to: 'specialist',
2232
- edgeType: 'handoff',
2233
- prompt: 'Work the specialist task',
2234
- },
2235
- ];
2236
- const run = await Run.create(createTestConfig(agents, edges));
2237
- if (run.Graph == null) {
2238
- throw new Error('Expected a multi-agent graph');
2239
- }
2240
- run.Graph.overrideModel = new MalformedSiblingHandoffModel([
2241
- {
2242
- promptMarker: 'single-malformed-request-marker',
2243
- response: 'Routing with a malformed sibling',
2244
- toolCalls: [
2245
- {
2246
- id: 'tool_call_transfer_specialist',
2247
- name: `${Constants.LC_TRANSFER_TO_}specialist`,
2248
- args: { instructions: 'single-specialist-instructions-marker' },
2249
- } as ToolCall,
2250
- {
2251
- id: MALFORMED_CALL_ID,
2252
- name: 'broken_tool',
2253
- args: {},
2254
- } as ToolCall,
2255
- ],
2256
- },
2257
- {
2258
- promptMarker: 'single-specialist-instructions-marker',
2259
- response: 'Specialist complete',
2260
- },
2261
- ]);
2262
-
2263
- const config: Partial<RunnableConfig> & {
2264
- version: 'v1' | 'v2';
2265
- streamMode: string;
2266
- } = {
2267
- configurable: { thread_id: 'test-handoff-malformed-single-thread' },
2268
- streamMode: 'values',
2269
- version: 'v2',
2270
- };
2271
- await run.processStream(
2272
- { messages: [new HumanMessage('single-malformed-request-marker')] },
2273
- config
2274
- );
2275
-
2276
- const finalMessages = run.getRunMessages();
2277
- expect(finalMessages).toBeDefined();
2278
- /** The child agent actually ran — its scripted response is present —
2279
- * and every model call it made passed validateToolHistory. */
2280
- const specialistReply = finalMessages!.find(
2281
- (msg) =>
2282
- msg.getType() === 'ai' &&
2283
- String(msg.content).includes('Specialist complete')
2284
- );
2285
- expect(specialistReply).toBeDefined();
2286
- expectPromotedPairing(finalMessages!);
2287
- });
2288
-
2289
- it('parallel Send handoffs: each child state keeps the promoted call and its synthesized result', async () => {
2290
- const agents: t.AgentInputs[] = [
2291
- createBasicAgent('router', 'You are a router'),
2292
- createBasicAgent('left', 'You are the left specialist'),
2293
- createBasicAgent('right', 'You are the right specialist'),
2294
- ];
2295
- const edges: t.GraphEdge[] = [
2296
- {
2297
- from: 'router',
2298
- to: 'left',
2299
- edgeType: 'handoff',
2300
- prompt: 'Work the left task',
2301
- },
2302
- {
2303
- from: 'router',
2304
- to: 'right',
2305
- edgeType: 'handoff',
2306
- prompt: 'Work the right task',
2307
- },
2308
- ];
2309
- const run = await Run.create(createTestConfig(agents, edges));
2310
- if (run.Graph == null) {
2311
- throw new Error('Expected a multi-agent graph');
2312
- }
2313
- run.Graph.overrideModel = new MalformedSiblingHandoffModel([
2314
- {
2315
- promptMarker: 'parallel-malformed-request-marker',
2316
- response: 'Routing both with a malformed sibling',
2317
- toolCalls: [
2318
- {
2319
- id: 'tool_call_transfer_left',
2320
- name: `${Constants.LC_TRANSFER_TO_}left`,
2321
- args: { instructions: 'parallel-left-instructions-marker' },
2322
- } as ToolCall,
2323
- {
2324
- id: 'tool_call_transfer_right',
2325
- name: `${Constants.LC_TRANSFER_TO_}right`,
2326
- args: { instructions: 'parallel-right-instructions-marker' },
2327
- } as ToolCall,
2328
- {
2329
- id: MALFORMED_CALL_ID,
2330
- name: 'broken_tool',
2331
- args: {},
2332
- } as ToolCall,
2333
- ],
2334
- },
2335
- {
2336
- promptMarker: 'parallel-left-instructions-marker',
2337
- response: 'Left complete',
2338
- },
2339
- {
2340
- promptMarker: 'parallel-right-instructions-marker',
2341
- response: 'Right complete',
2342
- },
2343
- ]);
2344
-
2345
- const config: Partial<RunnableConfig> & {
2346
- version: 'v1' | 'v2';
2347
- streamMode: string;
2348
- } = {
2349
- configurable: { thread_id: 'test-handoff-malformed-parallel-thread' },
2350
- streamMode: 'values',
2351
- version: 'v2',
2352
- };
2353
- await run.processStream(
2354
- { messages: [new HumanMessage('parallel-malformed-request-marker')] },
2355
- config
2356
- );
2357
-
2358
- const finalMessages = run.getRunMessages();
2359
- expect(finalMessages).toBeDefined();
2360
- /** Both Send children ran off their patched child states, and every
2361
- * child model call passed validateToolHistory — the un-patched Send
2362
- * state omitted the synthesized result and carried the stale same-id
2363
- * copy instead. */
2364
- const leftReply = finalMessages!.find(
2365
- (msg) =>
2366
- msg.getType() === 'ai' &&
2367
- String(msg.content).includes('Left complete')
2368
- );
2369
- const rightReply = finalMessages!.find(
2370
- (msg) =>
2371
- msg.getType() === 'ai' &&
2372
- String(msg.content).includes('Right complete')
2373
- );
2374
- expect(leftReply).toBeDefined();
2375
- expect(rightReply).toBeDefined();
2376
- expectPromotedPairing(finalMessages!);
2377
- });
2378
-
2379
- it('reception strips transfer tool_use content blocks alongside the calls (array-content providers)', async () => {
2380
- /**
2381
- * The retained filtered AI message used to keep `content` verbatim:
2382
- * with the promoted sibling holding the message in state, an
2383
- * Anthropic child would replay the stripped transfer's `tool_use`
2384
- * block (and a parallel sibling's block, whose result never reaches
2385
- * this recipient) as unmatched calls. Both must be filtered with the
2386
- * tool-call filtering; non-transfer blocks stay.
2387
- */
2388
- const agents: t.AgentInputs[] = [
2389
- createBasicAgent('router', 'You are a router'),
2390
- createBasicAgent('left', 'You are the left specialist'),
2391
- createBasicAgent('right', 'You are the right specialist'),
2392
- ];
2393
- const edges: t.GraphEdge[] = [
2394
- { from: 'router', to: 'left', edgeType: 'handoff' },
2395
- { from: 'router', to: 'right', edgeType: 'handoff' },
2396
- ];
2397
- const run = await Run.create(createTestConfig(agents, edges));
2398
- const graph = run.Graph as unknown as HandoffReceptionProbe;
2399
-
2400
- const transferLeft = {
2401
- id: 'tc_transfer_left',
2402
- name: `${Constants.LC_TRANSFER_TO_}left`,
2403
- args: {},
2404
- };
2405
- const context = graph.processHandoffReception(
2406
- [
2407
- new AIMessage({
2408
- id: 'ai_reception_blocks',
2409
- content: [
2410
- { type: 'text', text: 'Routing.' },
2411
- {
2412
- type: 'tool_use',
2413
- id: 'tc_transfer_left',
2414
- name: `${Constants.LC_TRANSFER_TO_}left`,
2415
- input: {},
2416
- },
2417
- {
2418
- type: 'tool_use',
2419
- id: 'tc_transfer_right_sibling',
2420
- name: `${Constants.LC_TRANSFER_TO_}right`,
2421
- input: {},
2422
- },
2423
- {
2424
- type: 'tool_use',
2425
- id: 'tc_promoted_sibling',
2426
- name: 'unknown',
2427
- input: {},
2428
- },
2429
- ],
2430
- tool_calls: [
2431
- transferLeft,
2432
- { id: 'tc_promoted_sibling', name: 'unknown', args: {} },
2433
- ],
2434
- }),
2435
- new ToolMessage({
2436
- content: 'Successfully transferred to left',
2437
- name: transferLeft.name,
2438
- tool_call_id: transferLeft.id,
2439
- }),
2440
- new ToolMessage({
2441
- content: 'Error: Malformed args.',
2442
- name: 'unknown',
2443
- tool_call_id: 'tc_promoted_sibling',
2444
- }),
2445
- ],
2446
- 'left'
2447
- );
2448
-
2449
- const retained = context?.filteredMessages?.find(
2450
- (msg): msg is AIMessage => msg.getType() === 'ai'
2451
- );
2452
- expect(retained).toBeDefined();
2453
- expect(retained!.tool_calls?.map((call) => call.id)).toEqual([
2454
- 'tc_promoted_sibling',
2455
- ]);
2456
- const blocks = retained!.content as Array<{ type?: string; id?: string }>;
2457
- /** Both this recipient's transfer block AND the parallel sibling's
2458
- * are gone; the text and the promoted sibling's block remain. */
2459
- expect(blocks.map((block) => block.id ?? block.type)).toEqual([
2460
- 'text',
2461
- 'tc_promoted_sibling',
2462
- ]);
2463
- });
2464
- });
2465
- });