@illuma-ai/agents 1.0.81

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 (558) hide show
  1. package/README.md +485 -0
  2. package/dist/cjs/agents/AgentContext.cjs +734 -0
  3. package/dist/cjs/agents/AgentContext.cjs.map +1 -0
  4. package/dist/cjs/common/enum.cjs +190 -0
  5. package/dist/cjs/common/enum.cjs.map +1 -0
  6. package/dist/cjs/events.cjs +172 -0
  7. package/dist/cjs/events.cjs.map +1 -0
  8. package/dist/cjs/graphs/Graph.cjs +1615 -0
  9. package/dist/cjs/graphs/Graph.cjs.map +1 -0
  10. package/dist/cjs/graphs/MultiAgentGraph.cjs +890 -0
  11. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -0
  12. package/dist/cjs/instrumentation.cjs +21 -0
  13. package/dist/cjs/instrumentation.cjs.map +1 -0
  14. package/dist/cjs/llm/anthropic/index.cjs +292 -0
  15. package/dist/cjs/llm/anthropic/index.cjs.map +1 -0
  16. package/dist/cjs/llm/anthropic/types.cjs +50 -0
  17. package/dist/cjs/llm/anthropic/types.cjs.map +1 -0
  18. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +630 -0
  19. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -0
  20. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +218 -0
  21. package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -0
  22. package/dist/cjs/llm/anthropic/utils/tools.cjs +29 -0
  23. package/dist/cjs/llm/anthropic/utils/tools.cjs.map +1 -0
  24. package/dist/cjs/llm/bedrock/index.cjs +282 -0
  25. package/dist/cjs/llm/bedrock/index.cjs.map +1 -0
  26. package/dist/cjs/llm/fake.cjs +97 -0
  27. package/dist/cjs/llm/fake.cjs.map +1 -0
  28. package/dist/cjs/llm/google/index.cjs +216 -0
  29. package/dist/cjs/llm/google/index.cjs.map +1 -0
  30. package/dist/cjs/llm/google/utils/common.cjs +647 -0
  31. package/dist/cjs/llm/google/utils/common.cjs.map +1 -0
  32. package/dist/cjs/llm/openai/index.cjs +1028 -0
  33. package/dist/cjs/llm/openai/index.cjs.map +1 -0
  34. package/dist/cjs/llm/openai/utils/index.cjs +765 -0
  35. package/dist/cjs/llm/openai/utils/index.cjs.map +1 -0
  36. package/dist/cjs/llm/openrouter/index.cjs +212 -0
  37. package/dist/cjs/llm/openrouter/index.cjs.map +1 -0
  38. package/dist/cjs/llm/providers.cjs +43 -0
  39. package/dist/cjs/llm/providers.cjs.map +1 -0
  40. package/dist/cjs/llm/text.cjs +69 -0
  41. package/dist/cjs/llm/text.cjs.map +1 -0
  42. package/dist/cjs/llm/vertexai/index.cjs +329 -0
  43. package/dist/cjs/llm/vertexai/index.cjs.map +1 -0
  44. package/dist/cjs/main.cjs +240 -0
  45. package/dist/cjs/main.cjs.map +1 -0
  46. package/dist/cjs/messages/cache.cjs +387 -0
  47. package/dist/cjs/messages/cache.cjs.map +1 -0
  48. package/dist/cjs/messages/content.cjs +53 -0
  49. package/dist/cjs/messages/content.cjs.map +1 -0
  50. package/dist/cjs/messages/core.cjs +367 -0
  51. package/dist/cjs/messages/core.cjs.map +1 -0
  52. package/dist/cjs/messages/format.cjs +761 -0
  53. package/dist/cjs/messages/format.cjs.map +1 -0
  54. package/dist/cjs/messages/ids.cjs +23 -0
  55. package/dist/cjs/messages/ids.cjs.map +1 -0
  56. package/dist/cjs/messages/prune.cjs +398 -0
  57. package/dist/cjs/messages/prune.cjs.map +1 -0
  58. package/dist/cjs/messages/tools.cjs +96 -0
  59. package/dist/cjs/messages/tools.cjs.map +1 -0
  60. package/dist/cjs/run.cjs +328 -0
  61. package/dist/cjs/run.cjs.map +1 -0
  62. package/dist/cjs/schemas/validate.cjs +324 -0
  63. package/dist/cjs/schemas/validate.cjs.map +1 -0
  64. package/dist/cjs/splitStream.cjs +210 -0
  65. package/dist/cjs/splitStream.cjs.map +1 -0
  66. package/dist/cjs/stream.cjs +620 -0
  67. package/dist/cjs/stream.cjs.map +1 -0
  68. package/dist/cjs/tools/BrowserTools.cjs +248 -0
  69. package/dist/cjs/tools/BrowserTools.cjs.map +1 -0
  70. package/dist/cjs/tools/Calculator.cjs +66 -0
  71. package/dist/cjs/tools/Calculator.cjs.map +1 -0
  72. package/dist/cjs/tools/CodeExecutor.cjs +234 -0
  73. package/dist/cjs/tools/CodeExecutor.cjs.map +1 -0
  74. package/dist/cjs/tools/ProgrammaticToolCalling.cjs +636 -0
  75. package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -0
  76. package/dist/cjs/tools/ToolNode.cjs +548 -0
  77. package/dist/cjs/tools/ToolNode.cjs.map +1 -0
  78. package/dist/cjs/tools/ToolSearch.cjs +909 -0
  79. package/dist/cjs/tools/ToolSearch.cjs.map +1 -0
  80. package/dist/cjs/tools/handlers.cjs +255 -0
  81. package/dist/cjs/tools/handlers.cjs.map +1 -0
  82. package/dist/cjs/tools/schema.cjs +31 -0
  83. package/dist/cjs/tools/schema.cjs.map +1 -0
  84. package/dist/cjs/tools/search/anthropic.cjs +40 -0
  85. package/dist/cjs/tools/search/anthropic.cjs.map +1 -0
  86. package/dist/cjs/tools/search/content.cjs +140 -0
  87. package/dist/cjs/tools/search/content.cjs.map +1 -0
  88. package/dist/cjs/tools/search/firecrawl.cjs +179 -0
  89. package/dist/cjs/tools/search/firecrawl.cjs.map +1 -0
  90. package/dist/cjs/tools/search/format.cjs +203 -0
  91. package/dist/cjs/tools/search/format.cjs.map +1 -0
  92. package/dist/cjs/tools/search/highlights.cjs +245 -0
  93. package/dist/cjs/tools/search/highlights.cjs.map +1 -0
  94. package/dist/cjs/tools/search/rerankers.cjs +174 -0
  95. package/dist/cjs/tools/search/rerankers.cjs.map +1 -0
  96. package/dist/cjs/tools/search/schema.cjs +117 -0
  97. package/dist/cjs/tools/search/schema.cjs.map +1 -0
  98. package/dist/cjs/tools/search/search.cjs +566 -0
  99. package/dist/cjs/tools/search/search.cjs.map +1 -0
  100. package/dist/cjs/tools/search/serper-scraper.cjs +132 -0
  101. package/dist/cjs/tools/search/serper-scraper.cjs.map +1 -0
  102. package/dist/cjs/tools/search/tool.cjs +456 -0
  103. package/dist/cjs/tools/search/tool.cjs.map +1 -0
  104. package/dist/cjs/tools/search/utils.cjs +66 -0
  105. package/dist/cjs/tools/search/utils.cjs.map +1 -0
  106. package/dist/cjs/types/graph.cjs +29 -0
  107. package/dist/cjs/types/graph.cjs.map +1 -0
  108. package/dist/cjs/utils/contextAnalytics.cjs +66 -0
  109. package/dist/cjs/utils/contextAnalytics.cjs.map +1 -0
  110. package/dist/cjs/utils/events.cjs +31 -0
  111. package/dist/cjs/utils/events.cjs.map +1 -0
  112. package/dist/cjs/utils/graph.cjs +16 -0
  113. package/dist/cjs/utils/graph.cjs.map +1 -0
  114. package/dist/cjs/utils/handlers.cjs +70 -0
  115. package/dist/cjs/utils/handlers.cjs.map +1 -0
  116. package/dist/cjs/utils/llm.cjs +27 -0
  117. package/dist/cjs/utils/llm.cjs.map +1 -0
  118. package/dist/cjs/utils/misc.cjs +56 -0
  119. package/dist/cjs/utils/misc.cjs.map +1 -0
  120. package/dist/cjs/utils/run.cjs +73 -0
  121. package/dist/cjs/utils/run.cjs.map +1 -0
  122. package/dist/cjs/utils/schema.cjs +27 -0
  123. package/dist/cjs/utils/schema.cjs.map +1 -0
  124. package/dist/cjs/utils/title.cjs +125 -0
  125. package/dist/cjs/utils/title.cjs.map +1 -0
  126. package/dist/cjs/utils/tokens.cjs +125 -0
  127. package/dist/cjs/utils/tokens.cjs.map +1 -0
  128. package/dist/cjs/utils/toonFormat.cjs +388 -0
  129. package/dist/cjs/utils/toonFormat.cjs.map +1 -0
  130. package/dist/esm/agents/AgentContext.mjs +732 -0
  131. package/dist/esm/agents/AgentContext.mjs.map +1 -0
  132. package/dist/esm/common/enum.mjs +190 -0
  133. package/dist/esm/common/enum.mjs.map +1 -0
  134. package/dist/esm/events.mjs +164 -0
  135. package/dist/esm/events.mjs.map +1 -0
  136. package/dist/esm/graphs/Graph.mjs +1612 -0
  137. package/dist/esm/graphs/Graph.mjs.map +1 -0
  138. package/dist/esm/graphs/MultiAgentGraph.mjs +888 -0
  139. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -0
  140. package/dist/esm/instrumentation.mjs +19 -0
  141. package/dist/esm/instrumentation.mjs.map +1 -0
  142. package/dist/esm/llm/anthropic/index.mjs +290 -0
  143. package/dist/esm/llm/anthropic/index.mjs.map +1 -0
  144. package/dist/esm/llm/anthropic/types.mjs +48 -0
  145. package/dist/esm/llm/anthropic/types.mjs.map +1 -0
  146. package/dist/esm/llm/anthropic/utils/message_inputs.mjs +627 -0
  147. package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -0
  148. package/dist/esm/llm/anthropic/utils/message_outputs.mjs +216 -0
  149. package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -0
  150. package/dist/esm/llm/anthropic/utils/tools.mjs +27 -0
  151. package/dist/esm/llm/anthropic/utils/tools.mjs.map +1 -0
  152. package/dist/esm/llm/bedrock/index.mjs +280 -0
  153. package/dist/esm/llm/bedrock/index.mjs.map +1 -0
  154. package/dist/esm/llm/fake.mjs +94 -0
  155. package/dist/esm/llm/fake.mjs.map +1 -0
  156. package/dist/esm/llm/google/index.mjs +214 -0
  157. package/dist/esm/llm/google/index.mjs.map +1 -0
  158. package/dist/esm/llm/google/utils/common.mjs +638 -0
  159. package/dist/esm/llm/google/utils/common.mjs.map +1 -0
  160. package/dist/esm/llm/openai/index.mjs +1018 -0
  161. package/dist/esm/llm/openai/index.mjs.map +1 -0
  162. package/dist/esm/llm/openai/utils/index.mjs +759 -0
  163. package/dist/esm/llm/openai/utils/index.mjs.map +1 -0
  164. package/dist/esm/llm/openrouter/index.mjs +210 -0
  165. package/dist/esm/llm/openrouter/index.mjs.map +1 -0
  166. package/dist/esm/llm/providers.mjs +39 -0
  167. package/dist/esm/llm/providers.mjs.map +1 -0
  168. package/dist/esm/llm/text.mjs +67 -0
  169. package/dist/esm/llm/text.mjs.map +1 -0
  170. package/dist/esm/llm/vertexai/index.mjs +327 -0
  171. package/dist/esm/llm/vertexai/index.mjs.map +1 -0
  172. package/dist/esm/main.mjs +37 -0
  173. package/dist/esm/main.mjs.map +1 -0
  174. package/dist/esm/messages/cache.mjs +382 -0
  175. package/dist/esm/messages/cache.mjs.map +1 -0
  176. package/dist/esm/messages/content.mjs +51 -0
  177. package/dist/esm/messages/content.mjs.map +1 -0
  178. package/dist/esm/messages/core.mjs +359 -0
  179. package/dist/esm/messages/core.mjs.map +1 -0
  180. package/dist/esm/messages/format.mjs +752 -0
  181. package/dist/esm/messages/format.mjs.map +1 -0
  182. package/dist/esm/messages/ids.mjs +21 -0
  183. package/dist/esm/messages/ids.mjs.map +1 -0
  184. package/dist/esm/messages/prune.mjs +393 -0
  185. package/dist/esm/messages/prune.mjs.map +1 -0
  186. package/dist/esm/messages/tools.mjs +93 -0
  187. package/dist/esm/messages/tools.mjs.map +1 -0
  188. package/dist/esm/run.mjs +325 -0
  189. package/dist/esm/run.mjs.map +1 -0
  190. package/dist/esm/schemas/validate.mjs +317 -0
  191. package/dist/esm/schemas/validate.mjs.map +1 -0
  192. package/dist/esm/splitStream.mjs +207 -0
  193. package/dist/esm/splitStream.mjs.map +1 -0
  194. package/dist/esm/stream.mjs +616 -0
  195. package/dist/esm/stream.mjs.map +1 -0
  196. package/dist/esm/tools/BrowserTools.mjs +244 -0
  197. package/dist/esm/tools/BrowserTools.mjs.map +1 -0
  198. package/dist/esm/tools/Calculator.mjs +41 -0
  199. package/dist/esm/tools/Calculator.mjs.map +1 -0
  200. package/dist/esm/tools/CodeExecutor.mjs +226 -0
  201. package/dist/esm/tools/CodeExecutor.mjs.map +1 -0
  202. package/dist/esm/tools/ProgrammaticToolCalling.mjs +622 -0
  203. package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -0
  204. package/dist/esm/tools/ToolNode.mjs +545 -0
  205. package/dist/esm/tools/ToolNode.mjs.map +1 -0
  206. package/dist/esm/tools/ToolSearch.mjs +870 -0
  207. package/dist/esm/tools/ToolSearch.mjs.map +1 -0
  208. package/dist/esm/tools/handlers.mjs +250 -0
  209. package/dist/esm/tools/handlers.mjs.map +1 -0
  210. package/dist/esm/tools/schema.mjs +28 -0
  211. package/dist/esm/tools/schema.mjs.map +1 -0
  212. package/dist/esm/tools/search/anthropic.mjs +37 -0
  213. package/dist/esm/tools/search/anthropic.mjs.map +1 -0
  214. package/dist/esm/tools/search/content.mjs +119 -0
  215. package/dist/esm/tools/search/content.mjs.map +1 -0
  216. package/dist/esm/tools/search/firecrawl.mjs +176 -0
  217. package/dist/esm/tools/search/firecrawl.mjs.map +1 -0
  218. package/dist/esm/tools/search/format.mjs +201 -0
  219. package/dist/esm/tools/search/format.mjs.map +1 -0
  220. package/dist/esm/tools/search/highlights.mjs +243 -0
  221. package/dist/esm/tools/search/highlights.mjs.map +1 -0
  222. package/dist/esm/tools/search/rerankers.mjs +168 -0
  223. package/dist/esm/tools/search/rerankers.mjs.map +1 -0
  224. package/dist/esm/tools/search/schema.mjs +104 -0
  225. package/dist/esm/tools/search/schema.mjs.map +1 -0
  226. package/dist/esm/tools/search/search.mjs +563 -0
  227. package/dist/esm/tools/search/search.mjs.map +1 -0
  228. package/dist/esm/tools/search/serper-scraper.mjs +129 -0
  229. package/dist/esm/tools/search/serper-scraper.mjs.map +1 -0
  230. package/dist/esm/tools/search/tool.mjs +454 -0
  231. package/dist/esm/tools/search/tool.mjs.map +1 -0
  232. package/dist/esm/tools/search/utils.mjs +61 -0
  233. package/dist/esm/tools/search/utils.mjs.map +1 -0
  234. package/dist/esm/types/graph.mjs +26 -0
  235. package/dist/esm/types/graph.mjs.map +1 -0
  236. package/dist/esm/utils/contextAnalytics.mjs +64 -0
  237. package/dist/esm/utils/contextAnalytics.mjs.map +1 -0
  238. package/dist/esm/utils/events.mjs +29 -0
  239. package/dist/esm/utils/events.mjs.map +1 -0
  240. package/dist/esm/utils/graph.mjs +13 -0
  241. package/dist/esm/utils/graph.mjs.map +1 -0
  242. package/dist/esm/utils/handlers.mjs +68 -0
  243. package/dist/esm/utils/handlers.mjs.map +1 -0
  244. package/dist/esm/utils/llm.mjs +24 -0
  245. package/dist/esm/utils/llm.mjs.map +1 -0
  246. package/dist/esm/utils/misc.mjs +53 -0
  247. package/dist/esm/utils/misc.mjs.map +1 -0
  248. package/dist/esm/utils/run.mjs +70 -0
  249. package/dist/esm/utils/run.mjs.map +1 -0
  250. package/dist/esm/utils/schema.mjs +24 -0
  251. package/dist/esm/utils/schema.mjs.map +1 -0
  252. package/dist/esm/utils/title.mjs +122 -0
  253. package/dist/esm/utils/title.mjs.map +1 -0
  254. package/dist/esm/utils/tokens.mjs +121 -0
  255. package/dist/esm/utils/tokens.mjs.map +1 -0
  256. package/dist/esm/utils/toonFormat.mjs +381 -0
  257. package/dist/esm/utils/toonFormat.mjs.map +1 -0
  258. package/dist/types/agents/AgentContext.d.ts +293 -0
  259. package/dist/types/common/enum.d.ts +155 -0
  260. package/dist/types/common/index.d.ts +1 -0
  261. package/dist/types/events.d.ts +31 -0
  262. package/dist/types/graphs/Graph.d.ts +216 -0
  263. package/dist/types/graphs/MultiAgentGraph.d.ts +104 -0
  264. package/dist/types/graphs/index.d.ts +2 -0
  265. package/dist/types/index.d.ts +21 -0
  266. package/dist/types/instrumentation.d.ts +1 -0
  267. package/dist/types/llm/anthropic/index.d.ts +39 -0
  268. package/dist/types/llm/anthropic/types.d.ts +37 -0
  269. package/dist/types/llm/anthropic/utils/message_inputs.d.ts +14 -0
  270. package/dist/types/llm/anthropic/utils/message_outputs.d.ts +14 -0
  271. package/dist/types/llm/anthropic/utils/output_parsers.d.ts +22 -0
  272. package/dist/types/llm/anthropic/utils/tools.d.ts +3 -0
  273. package/dist/types/llm/bedrock/index.d.ts +141 -0
  274. package/dist/types/llm/bedrock/types.d.ts +27 -0
  275. package/dist/types/llm/bedrock/utils/index.d.ts +5 -0
  276. package/dist/types/llm/bedrock/utils/message_inputs.d.ts +31 -0
  277. package/dist/types/llm/bedrock/utils/message_outputs.d.ts +33 -0
  278. package/dist/types/llm/fake.d.ts +31 -0
  279. package/dist/types/llm/google/index.d.ts +24 -0
  280. package/dist/types/llm/google/types.d.ts +42 -0
  281. package/dist/types/llm/google/utils/common.d.ts +34 -0
  282. package/dist/types/llm/google/utils/tools.d.ts +10 -0
  283. package/dist/types/llm/google/utils/zod_to_genai_parameters.d.ts +14 -0
  284. package/dist/types/llm/openai/index.d.ts +127 -0
  285. package/dist/types/llm/openai/types.d.ts +10 -0
  286. package/dist/types/llm/openai/utils/index.d.ts +29 -0
  287. package/dist/types/llm/openrouter/index.d.ts +15 -0
  288. package/dist/types/llm/providers.d.ts +5 -0
  289. package/dist/types/llm/text.d.ts +21 -0
  290. package/dist/types/llm/vertexai/index.d.ts +293 -0
  291. package/dist/types/messages/cache.d.ts +54 -0
  292. package/dist/types/messages/content.d.ts +7 -0
  293. package/dist/types/messages/core.d.ts +14 -0
  294. package/dist/types/messages/format.d.ts +137 -0
  295. package/dist/types/messages/ids.d.ts +3 -0
  296. package/dist/types/messages/index.d.ts +7 -0
  297. package/dist/types/messages/prune.d.ts +52 -0
  298. package/dist/types/messages/reducer.d.ts +9 -0
  299. package/dist/types/messages/tools.d.ts +17 -0
  300. package/dist/types/mockStream.d.ts +32 -0
  301. package/dist/types/prompts/collab.d.ts +1 -0
  302. package/dist/types/prompts/index.d.ts +2 -0
  303. package/dist/types/prompts/taskmanager.d.ts +41 -0
  304. package/dist/types/run.d.ts +41 -0
  305. package/dist/types/schemas/index.d.ts +1 -0
  306. package/dist/types/schemas/validate.d.ts +59 -0
  307. package/dist/types/splitStream.d.ts +37 -0
  308. package/dist/types/stream.d.ts +15 -0
  309. package/dist/types/test/mockTools.d.ts +28 -0
  310. package/dist/types/tools/BrowserTools.d.ts +87 -0
  311. package/dist/types/tools/Calculator.d.ts +34 -0
  312. package/dist/types/tools/CodeExecutor.d.ts +57 -0
  313. package/dist/types/tools/ProgrammaticToolCalling.d.ts +138 -0
  314. package/dist/types/tools/ToolNode.d.ts +51 -0
  315. package/dist/types/tools/ToolSearch.d.ts +219 -0
  316. package/dist/types/tools/handlers.d.ts +22 -0
  317. package/dist/types/tools/schema.d.ts +12 -0
  318. package/dist/types/tools/search/anthropic.d.ts +16 -0
  319. package/dist/types/tools/search/content.d.ts +4 -0
  320. package/dist/types/tools/search/firecrawl.d.ts +54 -0
  321. package/dist/types/tools/search/format.d.ts +5 -0
  322. package/dist/types/tools/search/highlights.d.ts +13 -0
  323. package/dist/types/tools/search/index.d.ts +3 -0
  324. package/dist/types/tools/search/rerankers.d.ts +38 -0
  325. package/dist/types/tools/search/schema.d.ts +103 -0
  326. package/dist/types/tools/search/search.d.ts +8 -0
  327. package/dist/types/tools/search/serper-scraper.d.ts +59 -0
  328. package/dist/types/tools/search/test.d.ts +1 -0
  329. package/dist/types/tools/search/tool.d.ts +3 -0
  330. package/dist/types/tools/search/types.d.ts +575 -0
  331. package/dist/types/tools/search/utils.d.ts +10 -0
  332. package/dist/types/types/graph.d.ts +399 -0
  333. package/dist/types/types/index.d.ts +5 -0
  334. package/dist/types/types/llm.d.ts +105 -0
  335. package/dist/types/types/messages.d.ts +4 -0
  336. package/dist/types/types/run.d.ts +112 -0
  337. package/dist/types/types/stream.d.ts +308 -0
  338. package/dist/types/types/tools.d.ts +296 -0
  339. package/dist/types/utils/contextAnalytics.d.ts +37 -0
  340. package/dist/types/utils/events.d.ts +6 -0
  341. package/dist/types/utils/graph.d.ts +2 -0
  342. package/dist/types/utils/handlers.d.ts +34 -0
  343. package/dist/types/utils/index.d.ts +9 -0
  344. package/dist/types/utils/llm.d.ts +3 -0
  345. package/dist/types/utils/llmConfig.d.ts +3 -0
  346. package/dist/types/utils/logging.d.ts +1 -0
  347. package/dist/types/utils/misc.d.ts +7 -0
  348. package/dist/types/utils/run.d.ts +27 -0
  349. package/dist/types/utils/schema.d.ts +8 -0
  350. package/dist/types/utils/title.d.ts +4 -0
  351. package/dist/types/utils/tokens.d.ts +28 -0
  352. package/dist/types/utils/toonFormat.d.ts +111 -0
  353. package/package.json +190 -0
  354. package/src/agents/AgentContext.test.ts +458 -0
  355. package/src/agents/AgentContext.ts +972 -0
  356. package/src/agents/__tests__/AgentContext.test.ts +805 -0
  357. package/src/agents/__tests__/resolveStructuredOutputMode.test.ts +137 -0
  358. package/src/common/enum.ts +203 -0
  359. package/src/common/index.ts +2 -0
  360. package/src/events.ts +223 -0
  361. package/src/graphs/Graph.ts +2228 -0
  362. package/src/graphs/MultiAgentGraph.ts +1063 -0
  363. package/src/graphs/__tests__/structured-output.integration.test.ts +809 -0
  364. package/src/graphs/__tests__/structured-output.test.ts +183 -0
  365. package/src/graphs/index.ts +2 -0
  366. package/src/index.ts +34 -0
  367. package/src/instrumentation.ts +22 -0
  368. package/src/llm/anthropic/Jacob_Lee_Resume_2023.pdf +0 -0
  369. package/src/llm/anthropic/index.ts +413 -0
  370. package/src/llm/anthropic/llm.spec.ts +1442 -0
  371. package/src/llm/anthropic/types.ts +140 -0
  372. package/src/llm/anthropic/utils/message_inputs.ts +757 -0
  373. package/src/llm/anthropic/utils/message_outputs.ts +289 -0
  374. package/src/llm/anthropic/utils/output_parsers.ts +133 -0
  375. package/src/llm/anthropic/utils/tools.ts +29 -0
  376. package/src/llm/bedrock/__tests__/bedrock-caching.test.ts +495 -0
  377. package/src/llm/bedrock/index.ts +411 -0
  378. package/src/llm/bedrock/llm.spec.ts +616 -0
  379. package/src/llm/bedrock/types.ts +51 -0
  380. package/src/llm/bedrock/utils/index.ts +18 -0
  381. package/src/llm/bedrock/utils/message_inputs.ts +563 -0
  382. package/src/llm/bedrock/utils/message_outputs.ts +310 -0
  383. package/src/llm/fake.ts +133 -0
  384. package/src/llm/google/data/gettysburg10.wav +0 -0
  385. package/src/llm/google/data/hotdog.jpg +0 -0
  386. package/src/llm/google/index.ts +337 -0
  387. package/src/llm/google/llm.spec.ts +934 -0
  388. package/src/llm/google/types.ts +56 -0
  389. package/src/llm/google/utils/common.ts +873 -0
  390. package/src/llm/google/utils/tools.ts +160 -0
  391. package/src/llm/google/utils/zod_to_genai_parameters.ts +86 -0
  392. package/src/llm/openai/index.ts +1366 -0
  393. package/src/llm/openai/types.ts +24 -0
  394. package/src/llm/openai/utils/index.ts +1035 -0
  395. package/src/llm/openai/utils/isReasoningModel.test.ts +90 -0
  396. package/src/llm/openrouter/index.ts +291 -0
  397. package/src/llm/providers.ts +52 -0
  398. package/src/llm/text.ts +94 -0
  399. package/src/llm/vertexai/index.ts +359 -0
  400. package/src/messages/__tests__/tools.test.ts +473 -0
  401. package/src/messages/cache.test.ts +1261 -0
  402. package/src/messages/cache.ts +518 -0
  403. package/src/messages/content.test.ts +362 -0
  404. package/src/messages/content.ts +63 -0
  405. package/src/messages/core.ts +473 -0
  406. package/src/messages/ensureThinkingBlock.test.ts +468 -0
  407. package/src/messages/format.ts +1029 -0
  408. package/src/messages/formatAgentMessages.test.ts +1513 -0
  409. package/src/messages/formatAgentMessages.tools.test.ts +419 -0
  410. package/src/messages/formatMessage.test.ts +693 -0
  411. package/src/messages/ids.ts +26 -0
  412. package/src/messages/index.ts +7 -0
  413. package/src/messages/labelContentByAgent.test.ts +887 -0
  414. package/src/messages/prune.ts +568 -0
  415. package/src/messages/reducer.ts +80 -0
  416. package/src/messages/shiftIndexTokenCountMap.test.ts +81 -0
  417. package/src/messages/tools.ts +108 -0
  418. package/src/mockStream.ts +99 -0
  419. package/src/prompts/collab.ts +6 -0
  420. package/src/prompts/index.ts +2 -0
  421. package/src/prompts/taskmanager.ts +61 -0
  422. package/src/run.ts +467 -0
  423. package/src/schemas/index.ts +2 -0
  424. package/src/schemas/schema-preparation.test.ts +500 -0
  425. package/src/schemas/validate.test.ts +358 -0
  426. package/src/schemas/validate.ts +454 -0
  427. package/src/scripts/abort.ts +157 -0
  428. package/src/scripts/ant_web_search.ts +158 -0
  429. package/src/scripts/ant_web_search_edge_case.ts +162 -0
  430. package/src/scripts/ant_web_search_error_edge_case.ts +148 -0
  431. package/src/scripts/args.ts +48 -0
  432. package/src/scripts/caching.ts +132 -0
  433. package/src/scripts/cli.ts +172 -0
  434. package/src/scripts/cli2.ts +133 -0
  435. package/src/scripts/cli3.ts +184 -0
  436. package/src/scripts/cli4.ts +191 -0
  437. package/src/scripts/cli5.ts +191 -0
  438. package/src/scripts/code_exec.ts +213 -0
  439. package/src/scripts/code_exec_files.ts +236 -0
  440. package/src/scripts/code_exec_multi_session.ts +241 -0
  441. package/src/scripts/code_exec_ptc.ts +334 -0
  442. package/src/scripts/code_exec_session.ts +282 -0
  443. package/src/scripts/code_exec_simple.ts +147 -0
  444. package/src/scripts/content.ts +138 -0
  445. package/src/scripts/empty_input.ts +137 -0
  446. package/src/scripts/handoff-test.ts +135 -0
  447. package/src/scripts/image.ts +178 -0
  448. package/src/scripts/memory.ts +97 -0
  449. package/src/scripts/multi-agent-chain.ts +331 -0
  450. package/src/scripts/multi-agent-conditional.ts +221 -0
  451. package/src/scripts/multi-agent-document-review-chain.ts +197 -0
  452. package/src/scripts/multi-agent-hybrid-flow.ts +310 -0
  453. package/src/scripts/multi-agent-parallel-start.ts +265 -0
  454. package/src/scripts/multi-agent-parallel.ts +394 -0
  455. package/src/scripts/multi-agent-sequence.ts +217 -0
  456. package/src/scripts/multi-agent-supervisor.ts +365 -0
  457. package/src/scripts/multi-agent-test.ts +186 -0
  458. package/src/scripts/parallel-asymmetric-tools-test.ts +274 -0
  459. package/src/scripts/parallel-full-metadata-test.ts +240 -0
  460. package/src/scripts/parallel-tools-test.ts +340 -0
  461. package/src/scripts/programmatic_exec.ts +396 -0
  462. package/src/scripts/programmatic_exec_agent.ts +231 -0
  463. package/src/scripts/search.ts +146 -0
  464. package/src/scripts/sequential-full-metadata-test.ts +197 -0
  465. package/src/scripts/simple.ts +225 -0
  466. package/src/scripts/single-agent-metadata-test.ts +198 -0
  467. package/src/scripts/stream.ts +140 -0
  468. package/src/scripts/test-custom-prompt-key.ts +145 -0
  469. package/src/scripts/test-handoff-input.ts +170 -0
  470. package/src/scripts/test-handoff-preamble.ts +277 -0
  471. package/src/scripts/test-multi-agent-list-handoff.ts +417 -0
  472. package/src/scripts/test-parallel-agent-labeling.ts +325 -0
  473. package/src/scripts/test-parallel-handoffs.ts +291 -0
  474. package/src/scripts/test-thinking-handoff-bedrock.ts +153 -0
  475. package/src/scripts/test-thinking-handoff.ts +155 -0
  476. package/src/scripts/test-tools-before-handoff.ts +226 -0
  477. package/src/scripts/test_code_api.ts +361 -0
  478. package/src/scripts/thinking-bedrock.ts +159 -0
  479. package/src/scripts/thinking.ts +171 -0
  480. package/src/scripts/tool_search.ts +162 -0
  481. package/src/scripts/tools.ts +177 -0
  482. package/src/specs/agent-handoffs.test.ts +888 -0
  483. package/src/specs/anthropic.simple.test.ts +387 -0
  484. package/src/specs/azure.simple.test.ts +364 -0
  485. package/src/specs/cache.simple.test.ts +396 -0
  486. package/src/specs/deepseek.simple.test.ts +283 -0
  487. package/src/specs/emergency-prune.test.ts +407 -0
  488. package/src/specs/moonshot.simple.test.ts +358 -0
  489. package/src/specs/openai.simple.test.ts +311 -0
  490. package/src/specs/openrouter.simple.test.ts +107 -0
  491. package/src/specs/prune.test.ts +901 -0
  492. package/src/specs/reasoning.test.ts +201 -0
  493. package/src/specs/spec.utils.ts +3 -0
  494. package/src/specs/thinking-handoff.test.ts +620 -0
  495. package/src/specs/thinking-prune.test.ts +703 -0
  496. package/src/specs/token-distribution-edge-case.test.ts +316 -0
  497. package/src/specs/token-memoization.test.ts +32 -0
  498. package/src/specs/tool-error.test.ts +198 -0
  499. package/src/splitStream.test.ts +691 -0
  500. package/src/splitStream.ts +234 -0
  501. package/src/stream.test.ts +94 -0
  502. package/src/stream.ts +801 -0
  503. package/src/test/mockTools.ts +386 -0
  504. package/src/tools/BrowserTools.ts +393 -0
  505. package/src/tools/Calculator.test.ts +278 -0
  506. package/src/tools/Calculator.ts +46 -0
  507. package/src/tools/CodeExecutor.ts +270 -0
  508. package/src/tools/ProgrammaticToolCalling.ts +785 -0
  509. package/src/tools/ToolNode.ts +674 -0
  510. package/src/tools/ToolSearch.ts +1095 -0
  511. package/src/tools/__tests__/BrowserTools.test.ts +265 -0
  512. package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts +319 -0
  513. package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +1006 -0
  514. package/src/tools/__tests__/ToolSearch.integration.test.ts +162 -0
  515. package/src/tools/__tests__/ToolSearch.test.ts +1003 -0
  516. package/src/tools/handlers.ts +363 -0
  517. package/src/tools/schema.ts +37 -0
  518. package/src/tools/search/anthropic.ts +51 -0
  519. package/src/tools/search/content.test.ts +173 -0
  520. package/src/tools/search/content.ts +147 -0
  521. package/src/tools/search/firecrawl.ts +210 -0
  522. package/src/tools/search/format.ts +250 -0
  523. package/src/tools/search/highlights.ts +320 -0
  524. package/src/tools/search/index.ts +3 -0
  525. package/src/tools/search/jina-reranker.test.ts +130 -0
  526. package/src/tools/search/output.md +2775 -0
  527. package/src/tools/search/rerankers.ts +242 -0
  528. package/src/tools/search/schema.ts +113 -0
  529. package/src/tools/search/search.ts +768 -0
  530. package/src/tools/search/serper-scraper.ts +155 -0
  531. package/src/tools/search/test.html +884 -0
  532. package/src/tools/search/test.md +643 -0
  533. package/src/tools/search/test.ts +159 -0
  534. package/src/tools/search/tool.ts +657 -0
  535. package/src/tools/search/types.ts +665 -0
  536. package/src/tools/search/utils.ts +79 -0
  537. package/src/types/graph.test.ts +218 -0
  538. package/src/types/graph.ts +533 -0
  539. package/src/types/index.ts +6 -0
  540. package/src/types/llm.ts +140 -0
  541. package/src/types/messages.ts +4 -0
  542. package/src/types/run.ts +128 -0
  543. package/src/types/stream.ts +417 -0
  544. package/src/types/tools.ts +355 -0
  545. package/src/utils/contextAnalytics.ts +103 -0
  546. package/src/utils/events.ts +32 -0
  547. package/src/utils/graph.ts +11 -0
  548. package/src/utils/handlers.ts +107 -0
  549. package/src/utils/index.ts +9 -0
  550. package/src/utils/llm.ts +26 -0
  551. package/src/utils/llmConfig.ts +208 -0
  552. package/src/utils/logging.ts +48 -0
  553. package/src/utils/misc.ts +57 -0
  554. package/src/utils/run.ts +106 -0
  555. package/src/utils/schema.ts +35 -0
  556. package/src/utils/title.ts +177 -0
  557. package/src/utils/tokens.ts +142 -0
  558. package/src/utils/toonFormat.ts +475 -0
@@ -0,0 +1,888 @@
1
+ import { tool } from '@langchain/core/tools';
2
+ import { PromptTemplate } from '@langchain/core/prompts';
3
+ import { ToolMessage, AIMessage, getBufferString, HumanMessage } from '@langchain/core/messages';
4
+ import { getCurrentTaskInput, Command, Annotation, messagesStateReducer, StateGraph, END, START } from '@langchain/langgraph';
5
+ import { StandardGraph } from './Graph.mjs';
6
+ import { Constants } from '../common/enum.mjs';
7
+
8
+ /** Pattern to extract instructions from transfer ToolMessage content */
9
+ const HANDOFF_INSTRUCTIONS_PATTERN = /(?:Instructions?|Context):\s*(.+)/is;
10
+ /**
11
+ * MultiAgentGraph extends StandardGraph to support dynamic multi-agent workflows
12
+ * with handoffs, fan-in/fan-out, and other composable patterns.
13
+ *
14
+ * Key behavior:
15
+ * - Agents with ONLY handoff edges: Can dynamically route to any handoff destination
16
+ * - Agents with ONLY direct edges: Always follow their direct edges
17
+ * - Agents with BOTH: Use Command for exclusive routing (handoff OR direct, not both)
18
+ * - If handoff occurs: Only the handoff destination executes
19
+ * - If no handoff: Direct edges execute (potentially in parallel)
20
+ *
21
+ * This enables the common pattern where an agent either delegates (handoff)
22
+ * OR continues its workflow (direct edges), but not both simultaneously.
23
+ */
24
+ class MultiAgentGraph extends StandardGraph {
25
+ edges;
26
+ startingNodes = new Set();
27
+ directEdges = [];
28
+ handoffEdges = [];
29
+ /**
30
+ * Map of agentId to parallel group info.
31
+ * Contains groupId (incrementing number reflecting execution order) for agents in parallel groups.
32
+ * Sequential agents (not in any parallel group) have undefined entry.
33
+ *
34
+ * Example for: researcher -> [analyst1, analyst2, analyst3] -> summarizer
35
+ * - researcher: undefined (sequential, order 0)
36
+ * - analyst1, analyst2, analyst3: { groupId: 1 } (parallel group, order 1)
37
+ * - summarizer: undefined (sequential, order 2)
38
+ */
39
+ agentParallelGroups = new Map();
40
+ constructor(input) {
41
+ super(input);
42
+ this.edges = input.edges;
43
+ this.categorizeEdges();
44
+ this.analyzeGraph();
45
+ this.createHandoffTools();
46
+ }
47
+ /**
48
+ * Categorize edges into handoff and direct types
49
+ */
50
+ categorizeEdges() {
51
+ for (const edge of this.edges) {
52
+ // Default behavior: edges with conditions or explicit 'handoff' type are handoff edges
53
+ // Edges with explicit 'direct' type or multi-destination without conditions are direct edges
54
+ if (edge.edgeType === 'direct') {
55
+ this.directEdges.push(edge);
56
+ }
57
+ else if (edge.edgeType === 'handoff' || edge.condition != null) {
58
+ this.handoffEdges.push(edge);
59
+ }
60
+ else {
61
+ // Default: single-to-single edges are handoff, single-to-multiple are direct
62
+ const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
63
+ const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
64
+ if (sources.length === 1 && destinations.length > 1) {
65
+ // Fan-out pattern defaults to direct
66
+ this.directEdges.push(edge);
67
+ }
68
+ else {
69
+ // Everything else defaults to handoff
70
+ this.handoffEdges.push(edge);
71
+ }
72
+ }
73
+ }
74
+ }
75
+ /**
76
+ * Analyze graph structure to determine starting nodes and connections
77
+ */
78
+ analyzeGraph() {
79
+ const hasIncomingEdge = new Set();
80
+ // Track all nodes that have incoming edges
81
+ for (const edge of this.edges) {
82
+ const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
83
+ destinations.forEach((dest) => hasIncomingEdge.add(dest));
84
+ }
85
+ // Starting nodes are those without incoming edges
86
+ for (const agentId of this.agentContexts.keys()) {
87
+ if (!hasIncomingEdge.has(agentId)) {
88
+ this.startingNodes.add(agentId);
89
+ }
90
+ }
91
+ // If no starting nodes found, use the first agent
92
+ if (this.startingNodes.size === 0 && this.agentContexts.size > 0) {
93
+ this.startingNodes.add(this.agentContexts.keys().next().value);
94
+ }
95
+ // Determine if graph has parallel execution capability
96
+ this.computeParallelCapability();
97
+ }
98
+ /**
99
+ * Compute parallel groups by traversing the graph in execution order.
100
+ * Assigns incrementing group IDs that reflect the sequential order of execution.
101
+ *
102
+ * For: researcher -> [analyst1, analyst2, analyst3] -> summarizer
103
+ * - researcher: no group (first sequential node)
104
+ * - analyst1, analyst2, analyst3: groupId 1 (first parallel group)
105
+ * - summarizer: no group (next sequential node)
106
+ *
107
+ * This allows frontend to render in order:
108
+ * Row 0: researcher
109
+ * Row 1: [analyst1, analyst2, analyst3] (grouped)
110
+ * Row 2: summarizer
111
+ */
112
+ computeParallelCapability() {
113
+ let groupCounter = 1; // Start at 1, 0 reserved for "no group"
114
+ // Check 1: Multiple starting nodes means parallel from the start (group 1)
115
+ if (this.startingNodes.size > 1) {
116
+ for (const agentId of this.startingNodes) {
117
+ this.agentParallelGroups.set(agentId, groupCounter);
118
+ }
119
+ groupCounter++;
120
+ }
121
+ // Check 2: Traverse direct edges in order to find fan-out patterns
122
+ // Build a simple execution order by following edges from starting nodes
123
+ const visited = new Set();
124
+ const queue = [...this.startingNodes];
125
+ while (queue.length > 0) {
126
+ const current = queue.shift();
127
+ if (visited.has(current))
128
+ continue;
129
+ visited.add(current);
130
+ // Find direct edges from this node
131
+ for (const edge of this.directEdges) {
132
+ const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
133
+ if (!sources.includes(current))
134
+ continue;
135
+ const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
136
+ // Fan-out: multiple destinations = parallel group
137
+ if (destinations.length > 1) {
138
+ for (const dest of destinations) {
139
+ // Only set if not already in a group (first group wins)
140
+ if (!this.agentParallelGroups.has(dest)) {
141
+ this.agentParallelGroups.set(dest, groupCounter);
142
+ }
143
+ if (!visited.has(dest)) {
144
+ queue.push(dest);
145
+ }
146
+ }
147
+ groupCounter++;
148
+ }
149
+ else {
150
+ // Single destination - add to queue for traversal
151
+ for (const dest of destinations) {
152
+ if (!visited.has(dest)) {
153
+ queue.push(dest);
154
+ }
155
+ }
156
+ }
157
+ }
158
+ // Also follow handoff edges for traversal (but they don't create parallel groups)
159
+ for (const edge of this.handoffEdges) {
160
+ const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
161
+ if (!sources.includes(current))
162
+ continue;
163
+ const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
164
+ for (const dest of destinations) {
165
+ if (!visited.has(dest)) {
166
+ queue.push(dest);
167
+ }
168
+ }
169
+ }
170
+ }
171
+ }
172
+ /**
173
+ * Get the parallel group ID for an agent, if any.
174
+ * Returns undefined if the agent is not part of a parallel group.
175
+ * Group IDs are incrementing numbers reflecting execution order.
176
+ */
177
+ getParallelGroupId(agentId) {
178
+ return this.agentParallelGroups.get(agentId);
179
+ }
180
+ /**
181
+ * Override to indicate this is a multi-agent graph.
182
+ * Enables agentId to be included in RunStep for frontend agent labeling.
183
+ */
184
+ isMultiAgentGraph() {
185
+ return true;
186
+ }
187
+ /**
188
+ * Override base class method to provide parallel group IDs for run steps.
189
+ */
190
+ getParallelGroupIdForAgent(agentId) {
191
+ return this.agentParallelGroups.get(agentId);
192
+ }
193
+ /**
194
+ * Create handoff tools for agents based on handoff edges only
195
+ */
196
+ createHandoffTools() {
197
+ // Group handoff edges by source agent(s)
198
+ const handoffsByAgent = new Map();
199
+ // Only process handoff edges for tool creation
200
+ for (const edge of this.handoffEdges) {
201
+ const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
202
+ sources.forEach((source) => {
203
+ if (!handoffsByAgent.has(source)) {
204
+ handoffsByAgent.set(source, []);
205
+ }
206
+ handoffsByAgent.get(source).push(edge);
207
+ });
208
+ }
209
+ // Create handoff tools for each agent
210
+ for (const [agentId, edges] of handoffsByAgent) {
211
+ const agentContext = this.agentContexts.get(agentId);
212
+ if (!agentContext)
213
+ continue;
214
+ // Create handoff tools for this agent's outgoing edges
215
+ const handoffTools = [];
216
+ const sourceAgentName = agentContext.name ?? agentId;
217
+ for (const edge of edges) {
218
+ handoffTools.push(...this.createHandoffToolsForEdge(edge, agentId, sourceAgentName));
219
+ }
220
+ // Add handoff tools to the agent's existing tools
221
+ if (!agentContext.tools) {
222
+ agentContext.tools = [];
223
+ }
224
+ agentContext.tools.push(...handoffTools);
225
+ }
226
+ }
227
+ /**
228
+ * Create handoff tools for an edge (handles multiple destinations)
229
+ * @param edge - The graph edge defining the handoff
230
+ * @param sourceAgentId - The ID of the agent that will perform the handoff
231
+ * @param sourceAgentName - The human-readable name of the source agent
232
+ */
233
+ createHandoffToolsForEdge(edge, sourceAgentId, sourceAgentName) {
234
+ const tools = [];
235
+ const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
236
+ /** If there's a condition, create a single conditional handoff tool */
237
+ if (edge.condition != null) {
238
+ const toolName = 'conditional_transfer';
239
+ const toolDescription = edge.description ?? 'Conditionally transfer control based on state';
240
+ /** Check if we have a prompt for handoff input */
241
+ const hasHandoffInput = edge.prompt != null && typeof edge.prompt === 'string';
242
+ const handoffInputDescription = hasHandoffInput ? edge.prompt : undefined;
243
+ const promptKey = edge.promptKey ?? 'instructions';
244
+ tools.push(tool(async (rawInput, config) => {
245
+ const input = rawInput;
246
+ const state = getCurrentTaskInput();
247
+ const toolCallId = config?.toolCall?.id ??
248
+ 'unknown';
249
+ /** Evaluated condition */
250
+ const result = edge.condition(state);
251
+ let destination;
252
+ if (typeof result === 'boolean') {
253
+ /** If true, use first destination; if false, don't transfer */
254
+ if (!result)
255
+ return null;
256
+ destination = destinations[0];
257
+ }
258
+ else if (typeof result === 'string') {
259
+ destination = result;
260
+ }
261
+ else {
262
+ /** Array of destinations - for now, use the first */
263
+ destination = Array.isArray(result) ? result[0] : destinations[0];
264
+ }
265
+ let content = `Conditionally transferred to ${destination}`;
266
+ if (hasHandoffInput &&
267
+ promptKey in input &&
268
+ input[promptKey] != null) {
269
+ content += `\n\n${promptKey.charAt(0).toUpperCase() + promptKey.slice(1)}: ${input[promptKey]}`;
270
+ }
271
+ const toolMessage = new ToolMessage({
272
+ content,
273
+ name: toolName,
274
+ tool_call_id: toolCallId,
275
+ additional_kwargs: {
276
+ /** Store destination for programmatic access in handoff detection */
277
+ handoff_destination: destination,
278
+ /** Store source agent name for receiving agent to know who handed off */
279
+ handoff_source_name: sourceAgentName,
280
+ },
281
+ });
282
+ return new Command({
283
+ goto: destination,
284
+ update: { messages: state.messages.concat(toolMessage) },
285
+ graph: Command.PARENT,
286
+ });
287
+ }, {
288
+ name: toolName,
289
+ schema: hasHandoffInput
290
+ ? {
291
+ type: 'object',
292
+ properties: {
293
+ [promptKey]: {
294
+ type: 'string',
295
+ description: handoffInputDescription,
296
+ },
297
+ },
298
+ required: [],
299
+ }
300
+ : { type: 'object', properties: {}, required: [] },
301
+ description: toolDescription,
302
+ }));
303
+ }
304
+ else {
305
+ /** Create individual tools for each destination */
306
+ for (const destination of destinations) {
307
+ const toolName = `${Constants.LC_TRANSFER_TO_}${destination}`;
308
+ const toolDescription = edge.description ?? `Transfer control to agent '${destination}'`;
309
+ /** Check if we have a prompt for handoff input */
310
+ const hasHandoffInput = edge.prompt != null && typeof edge.prompt === 'string';
311
+ const handoffInputDescription = hasHandoffInput
312
+ ? edge.prompt
313
+ : undefined;
314
+ const promptKey = edge.promptKey ?? 'instructions';
315
+ tools.push(tool(async (rawInput, config) => {
316
+ const input = rawInput;
317
+ const toolCallId = config?.toolCall?.id ??
318
+ 'unknown';
319
+ let content = `Successfully transferred to ${destination}`;
320
+ if (hasHandoffInput &&
321
+ promptKey in input &&
322
+ input[promptKey] != null) {
323
+ content += `\n\n${promptKey.charAt(0).toUpperCase() + promptKey.slice(1)}: ${input[promptKey]}`;
324
+ }
325
+ const toolMessage = new ToolMessage({
326
+ content,
327
+ name: toolName,
328
+ tool_call_id: toolCallId,
329
+ additional_kwargs: {
330
+ /** Store source agent name for receiving agent to know who handed off */
331
+ handoff_source_name: sourceAgentName,
332
+ },
333
+ });
334
+ const state = getCurrentTaskInput();
335
+ /**
336
+ * For parallel handoff support:
337
+ * Build messages that include ONLY this tool call's context.
338
+ * This prevents errors when LLM calls multiple transfers simultaneously -
339
+ * each destination gets a valid AIMessage with matching tool_call and tool_result.
340
+ *
341
+ * Strategy:
342
+ * 1. Find the AIMessage containing this tool call
343
+ * 2. Create a filtered AIMessage with ONLY this tool_call
344
+ * 3. Include all messages before the AIMessage plus the filtered pair
345
+ */
346
+ const messages = state.messages;
347
+ let filteredMessages = messages;
348
+ let aiMessageIndex = -1;
349
+ /** Find the AIMessage containing this tool call */
350
+ for (let i = messages.length - 1; i >= 0; i--) {
351
+ const msg = messages[i];
352
+ if (msg.getType() === 'ai') {
353
+ const aiMsg = msg;
354
+ const hasThisCall = aiMsg.tool_calls?.some((tc) => tc.id === toolCallId);
355
+ if (hasThisCall === true) {
356
+ aiMessageIndex = i;
357
+ break;
358
+ }
359
+ }
360
+ }
361
+ if (aiMessageIndex >= 0) {
362
+ const originalAiMsg = messages[aiMessageIndex];
363
+ const thisToolCall = originalAiMsg.tool_calls?.find((tc) => tc.id === toolCallId);
364
+ if (thisToolCall != null &&
365
+ (originalAiMsg.tool_calls?.length ?? 0) > 1) {
366
+ /**
367
+ * Multiple tool calls - create filtered AIMessage with ONLY this call.
368
+ * This ensures valid message structure for parallel handoffs.
369
+ */
370
+ const filteredAiMsg = new AIMessage({
371
+ content: originalAiMsg.content,
372
+ tool_calls: [thisToolCall],
373
+ id: originalAiMsg.id,
374
+ });
375
+ filteredMessages = [
376
+ ...messages.slice(0, aiMessageIndex),
377
+ filteredAiMsg,
378
+ toolMessage,
379
+ ];
380
+ }
381
+ else {
382
+ /** Single tool call - use messages as-is */
383
+ filteredMessages = messages.concat(toolMessage);
384
+ }
385
+ }
386
+ else {
387
+ /** Fallback - append tool message */
388
+ filteredMessages = messages.concat(toolMessage);
389
+ }
390
+ return new Command({
391
+ goto: destination,
392
+ update: { messages: filteredMessages },
393
+ graph: Command.PARENT,
394
+ });
395
+ }, {
396
+ name: toolName,
397
+ schema: hasHandoffInput
398
+ ? {
399
+ type: 'object',
400
+ properties: {
401
+ [promptKey]: {
402
+ type: 'string',
403
+ description: handoffInputDescription,
404
+ },
405
+ },
406
+ required: [],
407
+ }
408
+ : { type: 'object', properties: {}, required: [] },
409
+ description: toolDescription,
410
+ }));
411
+ }
412
+ }
413
+ return tools;
414
+ }
415
+ /**
416
+ * Create a complete agent subgraph (similar to createReactAgent)
417
+ */
418
+ createAgentSubgraph(agentId) {
419
+ /** This is essentially the same as `createAgentNode` from `StandardGraph` */
420
+ return this.createAgentNode(agentId);
421
+ }
422
+ /**
423
+ * Detects if the current agent is receiving a handoff and processes the messages accordingly.
424
+ * Returns filtered messages with the transfer tool call/message removed, plus any instructions,
425
+ * source agent, and parallel sibling information extracted from the transfer.
426
+ *
427
+ * Supports both single handoffs (last message is the transfer) and parallel handoffs
428
+ * (multiple transfer ToolMessages, need to find the one targeting this agent).
429
+ *
430
+ * @param messages - Current state messages
431
+ * @param agentId - The agent ID to check for handoff reception
432
+ * @returns Object with filtered messages, extracted instructions, source agent, and parallel siblings
433
+ */
434
+ processHandoffReception(messages, agentId) {
435
+ if (messages.length === 0)
436
+ return null;
437
+ /**
438
+ * Search for a transfer ToolMessage targeting this agent.
439
+ * For parallel handoffs, multiple transfer messages may exist - find ours.
440
+ * Search backwards from the end to find the most recent transfer to this agent.
441
+ */
442
+ let toolMessage = null;
443
+ let toolMessageIndex = -1;
444
+ for (let i = messages.length - 1; i >= 0; i--) {
445
+ const msg = messages[i];
446
+ if (msg.getType() !== 'tool')
447
+ continue;
448
+ const candidateMsg = msg;
449
+ const toolName = candidateMsg.name;
450
+ if (typeof toolName !== 'string')
451
+ continue;
452
+ /** Check for standard transfer pattern */
453
+ const isTransferMessage = toolName.startsWith(Constants.LC_TRANSFER_TO_);
454
+ const isConditionalTransfer = toolName === 'conditional_transfer';
455
+ if (!isTransferMessage && !isConditionalTransfer)
456
+ continue;
457
+ /** Extract destination from tool name or additional_kwargs */
458
+ let destinationAgent = null;
459
+ if (isTransferMessage) {
460
+ destinationAgent = toolName.replace(Constants.LC_TRANSFER_TO_, '');
461
+ }
462
+ else if (isConditionalTransfer) {
463
+ const handoffDest = candidateMsg.additional_kwargs.handoff_destination;
464
+ destinationAgent = typeof handoffDest === 'string' ? handoffDest : null;
465
+ }
466
+ /** Check if this transfer targets our agent */
467
+ if (destinationAgent === agentId) {
468
+ toolMessage = candidateMsg;
469
+ toolMessageIndex = i;
470
+ break;
471
+ }
472
+ }
473
+ /** No transfer targeting this agent found */
474
+ if (toolMessage === null || toolMessageIndex < 0)
475
+ return null;
476
+ /** Extract instructions from the ToolMessage content */
477
+ const contentStr = typeof toolMessage.content === 'string'
478
+ ? toolMessage.content
479
+ : JSON.stringify(toolMessage.content);
480
+ const instructionsMatch = contentStr.match(HANDOFF_INSTRUCTIONS_PATTERN);
481
+ const instructions = instructionsMatch?.[1]?.trim() ?? null;
482
+ /** Extract source agent name from additional_kwargs */
483
+ const handoffSourceName = toolMessage.additional_kwargs.handoff_source_name;
484
+ const sourceAgentName = typeof handoffSourceName === 'string' ? handoffSourceName : null;
485
+ /** Extract parallel siblings (set by ToolNode for parallel handoffs) */
486
+ const rawSiblings = toolMessage.additional_kwargs.handoff_parallel_siblings;
487
+ const siblingIds = Array.isArray(rawSiblings)
488
+ ? rawSiblings.filter((s) => typeof s === 'string')
489
+ : [];
490
+ /** Convert IDs to display names */
491
+ const parallelSiblings = siblingIds.map((id) => {
492
+ const ctx = this.agentContexts.get(id);
493
+ return ctx?.name ?? id;
494
+ });
495
+ /** Get the tool_call_id to find and filter the AI message's tool call */
496
+ const toolCallId = toolMessage.tool_call_id;
497
+ /**
498
+ * Collect all transfer tool_call_ids to filter out.
499
+ * For parallel handoffs, we filter ALL transfer messages (not just ours)
500
+ * to give the receiving agent a clean context without handoff noise.
501
+ */
502
+ const transferToolCallIds = new Set([toolCallId]);
503
+ for (const msg of messages) {
504
+ if (msg.getType() !== 'tool')
505
+ continue;
506
+ const tm = msg;
507
+ const tName = tm.name;
508
+ if (typeof tName !== 'string')
509
+ continue;
510
+ if (tName.startsWith(Constants.LC_TRANSFER_TO_) ||
511
+ tName === 'conditional_transfer') {
512
+ transferToolCallIds.add(tm.tool_call_id);
513
+ }
514
+ }
515
+ /** Filter out all transfer messages */
516
+ const filteredMessages = [];
517
+ for (let i = 0; i < messages.length; i++) {
518
+ const msg = messages[i];
519
+ const msgType = msg.getType();
520
+ /** Skip transfer ToolMessages */
521
+ if (msgType === 'tool') {
522
+ const tm = msg;
523
+ if (transferToolCallIds.has(tm.tool_call_id)) {
524
+ continue;
525
+ }
526
+ }
527
+ if (msgType === 'ai') {
528
+ /** Check if this AI message contains any transfer tool calls */
529
+ const aiMsg = msg;
530
+ const toolCalls = aiMsg.tool_calls;
531
+ if (toolCalls && toolCalls.length > 0) {
532
+ /** Filter out all transfer tool calls */
533
+ const remainingToolCalls = toolCalls.filter((tc) => tc.id == null || !transferToolCallIds.has(tc.id));
534
+ const hasTransferCalls = remainingToolCalls.length < toolCalls.length;
535
+ if (hasTransferCalls) {
536
+ if (remainingToolCalls.length > 0 ||
537
+ (typeof aiMsg.content === 'string' && aiMsg.content.trim())) {
538
+ /** Keep the message but without transfer tool calls */
539
+ const filteredAiMsg = new AIMessage({
540
+ content: aiMsg.content,
541
+ tool_calls: remainingToolCalls,
542
+ id: aiMsg.id,
543
+ });
544
+ filteredMessages.push(filteredAiMsg);
545
+ }
546
+ /** If no remaining content or tool calls, skip this message entirely */
547
+ continue;
548
+ }
549
+ }
550
+ }
551
+ /** Keep all other messages */
552
+ filteredMessages.push(msg);
553
+ }
554
+ return {
555
+ filteredMessages,
556
+ instructions,
557
+ sourceAgentName,
558
+ parallelSiblings,
559
+ };
560
+ }
561
+ /**
562
+ * Create the multi-agent workflow with dynamic handoffs
563
+ */
564
+ createWorkflow() {
565
+ const StateAnnotation = Annotation.Root({
566
+ messages: Annotation({
567
+ reducer: (a, b) => {
568
+ if (!a.length) {
569
+ this.startIndex = a.length + b.length;
570
+ }
571
+ const result = messagesStateReducer(a, b);
572
+ this.messages = result;
573
+ return result;
574
+ },
575
+ default: () => [],
576
+ }),
577
+ /** Channel for passing filtered messages to agents when excludeResults is true */
578
+ agentMessages: Annotation({
579
+ /** Replaces state entirely */
580
+ reducer: (a, b) => b,
581
+ default: () => [],
582
+ }),
583
+ });
584
+ const builder = new StateGraph(StateAnnotation);
585
+ // Add all agents as complete subgraphs
586
+ for (const [agentId] of this.agentContexts) {
587
+ // Get all possible destinations for this agent
588
+ const handoffDestinations = new Set();
589
+ const directDestinations = new Set();
590
+ // Check handoff edges for destinations
591
+ for (const edge of this.handoffEdges) {
592
+ const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
593
+ if (sources.includes(agentId) === true) {
594
+ const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
595
+ dests.forEach((dest) => handoffDestinations.add(dest));
596
+ }
597
+ }
598
+ // Check direct edges for destinations
599
+ for (const edge of this.directEdges) {
600
+ const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
601
+ if (sources.includes(agentId) === true) {
602
+ const dests = Array.isArray(edge.to) ? edge.to : [edge.to];
603
+ dests.forEach((dest) => directDestinations.add(dest));
604
+ }
605
+ }
606
+ /** Check if this agent has BOTH handoff and direct edges */
607
+ const hasHandoffEdges = handoffDestinations.size > 0;
608
+ const hasDirectEdges = directDestinations.size > 0;
609
+ const needsCommandRouting = hasHandoffEdges && hasDirectEdges;
610
+ /** Collect all possible destinations for this agent */
611
+ const allDestinations = new Set([
612
+ ...handoffDestinations,
613
+ ...directDestinations,
614
+ ]);
615
+ if (handoffDestinations.size > 0 || directDestinations.size === 0) {
616
+ allDestinations.add(END);
617
+ }
618
+ /** Agent subgraph (includes agent + tools) */
619
+ const agentSubgraph = this.createAgentSubgraph(agentId);
620
+ /** Wrapper function that handles agentMessages channel, handoff reception, and conditional routing */
621
+ const agentWrapper = async (state) => {
622
+ let result;
623
+ /**
624
+ * Check if this agent is receiving a handoff.
625
+ * If so, filter out the transfer messages and inject instructions as preamble.
626
+ * This prevents the receiving agent from seeing the transfer as "completed work"
627
+ * and prematurely producing an end token.
628
+ */
629
+ const handoffContext = this.processHandoffReception(state.messages, agentId);
630
+ if (handoffContext !== null) {
631
+ const { filteredMessages, instructions, sourceAgentName, parallelSiblings, } = handoffContext;
632
+ /**
633
+ * Set handoff context on the receiving agent.
634
+ * Uses pre-computed graph position for depth and parallel info.
635
+ */
636
+ const agentContext = this.agentContexts.get(agentId);
637
+ if (agentContext &&
638
+ sourceAgentName != null &&
639
+ sourceAgentName !== '') {
640
+ agentContext.setHandoffContext(sourceAgentName, parallelSiblings);
641
+ }
642
+ /** Build messages for the receiving agent */
643
+ let messagesForAgent = filteredMessages;
644
+ /** If there are instructions, inject them as a HumanMessage to ground the agent */
645
+ const hasInstructions = instructions !== null && instructions !== '';
646
+ if (hasInstructions) {
647
+ messagesForAgent = [
648
+ ...filteredMessages,
649
+ new HumanMessage(instructions),
650
+ ];
651
+ }
652
+ /** Update token map if we have a token counter */
653
+ if (agentContext?.tokenCounter && hasInstructions) {
654
+ const freshTokenMap = {};
655
+ for (let i = 0; i < Math.min(filteredMessages.length, this.startIndex); i++) {
656
+ const tokenCount = agentContext.indexTokenCountMap[i];
657
+ if (tokenCount !== undefined) {
658
+ freshTokenMap[i] = tokenCount;
659
+ }
660
+ }
661
+ /** Add tokens for the instructions message */
662
+ const instructionsMsg = new HumanMessage(instructions);
663
+ freshTokenMap[messagesForAgent.length - 1] =
664
+ agentContext.tokenCounter(instructionsMsg);
665
+ agentContext.updateTokenMapWithInstructions(freshTokenMap);
666
+ }
667
+ const transformedState = {
668
+ ...state,
669
+ messages: messagesForAgent,
670
+ };
671
+ result = await agentSubgraph.invoke(transformedState);
672
+ result = {
673
+ ...result,
674
+ agentMessages: [],
675
+ };
676
+ }
677
+ else if (state.agentMessages != null &&
678
+ state.agentMessages.length > 0) {
679
+ /**
680
+ * When using agentMessages (excludeResults=true), we need to update
681
+ * the token map to account for the new prompt message
682
+ */
683
+ const agentContext = this.agentContexts.get(agentId);
684
+ if (agentContext && agentContext.tokenCounter) {
685
+ /** The agentMessages contains:
686
+ * 1. Filtered messages (0 to startIndex) - already have token counts
687
+ * 2. New prompt message - needs token counting
688
+ */
689
+ const freshTokenMap = {};
690
+ /** Copy existing token counts for filtered messages (0 to startIndex) */
691
+ for (let i = 0; i < this.startIndex; i++) {
692
+ const tokenCount = agentContext.indexTokenCountMap[i];
693
+ if (tokenCount !== undefined) {
694
+ freshTokenMap[i] = tokenCount;
695
+ }
696
+ }
697
+ /** Calculate tokens only for the new prompt message (last message) */
698
+ const promptMessageIndex = state.agentMessages.length - 1;
699
+ if (promptMessageIndex >= this.startIndex) {
700
+ const promptMessage = state.agentMessages[promptMessageIndex];
701
+ freshTokenMap[promptMessageIndex] =
702
+ agentContext.tokenCounter(promptMessage);
703
+ }
704
+ /** Update the agent's token map with instructions added */
705
+ agentContext.updateTokenMapWithInstructions(freshTokenMap);
706
+ }
707
+ /** Temporary state with messages replaced by `agentMessages` */
708
+ const transformedState = {
709
+ ...state,
710
+ messages: state.agentMessages,
711
+ };
712
+ result = await agentSubgraph.invoke(transformedState);
713
+ result = {
714
+ ...result,
715
+ /** Clear agentMessages for next agent */
716
+ agentMessages: [],
717
+ };
718
+ }
719
+ else {
720
+ result = await agentSubgraph.invoke(state);
721
+ }
722
+ /** If agent has both handoff and direct edges, use Command for exclusive routing */
723
+ if (needsCommandRouting) {
724
+ /** Check if a handoff occurred */
725
+ const lastMessage = result.messages[result.messages.length - 1];
726
+ if (lastMessage != null &&
727
+ lastMessage.getType() === 'tool' &&
728
+ typeof lastMessage.name === 'string' &&
729
+ lastMessage.name.startsWith(Constants.LC_TRANSFER_TO_)) {
730
+ /** Handoff occurred - extract destination and navigate there exclusively */
731
+ const handoffDest = lastMessage.name.replace(Constants.LC_TRANSFER_TO_, '');
732
+ return new Command({
733
+ update: result,
734
+ goto: handoffDest,
735
+ });
736
+ }
737
+ else {
738
+ /** No handoff - proceed with direct edges */
739
+ const directDests = Array.from(directDestinations);
740
+ if (directDests.length === 1) {
741
+ return new Command({
742
+ update: result,
743
+ goto: directDests[0],
744
+ });
745
+ }
746
+ else if (directDests.length > 1) {
747
+ /** Multiple direct destinations - they'll run in parallel */
748
+ return new Command({
749
+ update: result,
750
+ goto: directDests,
751
+ });
752
+ }
753
+ }
754
+ }
755
+ /** No special routing needed - return state normally */
756
+ return result;
757
+ };
758
+ /** Wrapped agent as a node with its possible destinations */
759
+ builder.addNode(agentId, agentWrapper, {
760
+ ends: Array.from(allDestinations),
761
+ });
762
+ }
763
+ // Add starting edges for all starting nodes
764
+ for (const startNode of this.startingNodes) {
765
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
766
+ /** @ts-ignore */
767
+ builder.addEdge(START, startNode);
768
+ }
769
+ /**
770
+ * Add direct edges for automatic transitions
771
+ * Group edges by destination to handle fan-in scenarios
772
+ */
773
+ const edgesByDestination = new Map();
774
+ for (const edge of this.directEdges) {
775
+ const destinations = Array.isArray(edge.to) ? edge.to : [edge.to];
776
+ for (const destination of destinations) {
777
+ if (!edgesByDestination.has(destination)) {
778
+ edgesByDestination.set(destination, []);
779
+ }
780
+ edgesByDestination.get(destination).push(edge);
781
+ }
782
+ }
783
+ for (const [destination, edges] of edgesByDestination) {
784
+ /** Checks if this is a fan-in scenario with prompt instructions */
785
+ const edgesWithPrompt = edges.filter((edge) => edge.prompt != null && edge.prompt !== '');
786
+ if (edgesWithPrompt.length > 0) {
787
+ /**
788
+ * Single wrapper node for destination (Fan-in with prompt)
789
+ */
790
+ const wrapperNodeId = `fan_in_${destination}_prompt`;
791
+ /**
792
+ * First edge's `prompt`
793
+ * (they should all be the same for fan-in)
794
+ */
795
+ const prompt = edgesWithPrompt[0].prompt;
796
+ /**
797
+ * First edge's `excludeResults` flag
798
+ * (they should all be the same for fan-in)
799
+ */
800
+ const excludeResults = edgesWithPrompt[0].excludeResults;
801
+ builder.addNode(wrapperNodeId, async (state) => {
802
+ let promptText;
803
+ let effectiveExcludeResults = excludeResults;
804
+ if (typeof prompt === 'function') {
805
+ promptText = await prompt(state.messages, this.startIndex);
806
+ }
807
+ else if (prompt != null) {
808
+ if (prompt.includes('{results}')) {
809
+ const resultsMessages = state.messages.slice(this.startIndex);
810
+ const resultsString = getBufferString(resultsMessages);
811
+ const promptTemplate = PromptTemplate.fromTemplate(prompt);
812
+ const result = await promptTemplate.invoke({
813
+ results: resultsString,
814
+ });
815
+ promptText = result.value;
816
+ effectiveExcludeResults =
817
+ excludeResults !== false && promptText !== '';
818
+ }
819
+ else {
820
+ promptText = prompt;
821
+ }
822
+ }
823
+ if (promptText != null && promptText !== '') {
824
+ if (effectiveExcludeResults == null ||
825
+ effectiveExcludeResults === false) {
826
+ return {
827
+ messages: [new HumanMessage(promptText)],
828
+ };
829
+ }
830
+ /** When `excludeResults` is true, use agentMessages channel
831
+ * to pass filtered messages + prompt to the destination agent
832
+ */
833
+ const filteredMessages = state.messages.slice(0, this.startIndex);
834
+ return {
835
+ messages: [new HumanMessage(promptText)],
836
+ agentMessages: messagesStateReducer(filteredMessages, [
837
+ new HumanMessage(promptText),
838
+ ]),
839
+ };
840
+ }
841
+ /** No prompt needed, return empty update */
842
+ return {};
843
+ });
844
+ /** Add edges from all sources to the wrapper, then wrapper to destination */
845
+ for (const edge of edges) {
846
+ const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
847
+ for (const source of sources) {
848
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
849
+ /** @ts-ignore */
850
+ builder.addEdge(source, wrapperNodeId);
851
+ }
852
+ }
853
+ /** Single edge from wrapper to destination */
854
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
855
+ /** @ts-ignore */
856
+ builder.addEdge(wrapperNodeId, destination);
857
+ }
858
+ else {
859
+ /** No prompt instructions, add direct edges (skip if source uses Command routing) */
860
+ for (const edge of edges) {
861
+ const sources = Array.isArray(edge.from) ? edge.from : [edge.from];
862
+ for (const source of sources) {
863
+ /** Check if this source node has both handoff and direct edges */
864
+ const sourceHandoffEdges = this.handoffEdges.filter((e) => {
865
+ const eSources = Array.isArray(e.from) ? e.from : [e.from];
866
+ return eSources.includes(source);
867
+ });
868
+ const sourceDirectEdges = this.directEdges.filter((e) => {
869
+ const eSources = Array.isArray(e.from) ? e.from : [e.from];
870
+ return eSources.includes(source);
871
+ });
872
+ /** Skip adding edge if source uses Command routing (has both types) */
873
+ if (sourceHandoffEdges.length > 0 && sourceDirectEdges.length > 0) {
874
+ continue;
875
+ }
876
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
877
+ /** @ts-ignore */
878
+ builder.addEdge(source, destination);
879
+ }
880
+ }
881
+ }
882
+ }
883
+ return builder.compile(this.compileOptions);
884
+ }
885
+ }
886
+
887
+ export { MultiAgentGraph };
888
+ //# sourceMappingURL=MultiAgentGraph.mjs.map