@langchain/langgraph 1.0.6 → 1.0.12

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 (383) hide show
  1. package/package.json +7 -7
  2. package/CHANGELOG.md +0 -280
  3. package/dist/_virtual/rolldown_runtime.cjs +0 -25
  4. package/dist/channels/any_value.cjs +0 -46
  5. package/dist/channels/any_value.cjs.map +0 -1
  6. package/dist/channels/any_value.d.cts +0 -24
  7. package/dist/channels/any_value.d.cts.map +0 -1
  8. package/dist/channels/any_value.d.ts +0 -24
  9. package/dist/channels/any_value.d.ts.map +0 -1
  10. package/dist/channels/any_value.js +0 -46
  11. package/dist/channels/any_value.js.map +0 -1
  12. package/dist/channels/base.cjs +0 -102
  13. package/dist/channels/base.cjs.map +0 -1
  14. package/dist/channels/base.d.cts +0 -79
  15. package/dist/channels/base.d.cts.map +0 -1
  16. package/dist/channels/base.d.ts +0 -79
  17. package/dist/channels/base.d.ts.map +0 -1
  18. package/dist/channels/base.js +0 -97
  19. package/dist/channels/base.js.map +0 -1
  20. package/dist/channels/binop.cjs +0 -49
  21. package/dist/channels/binop.cjs.map +0 -1
  22. package/dist/channels/binop.d.cts +0 -22
  23. package/dist/channels/binop.d.cts.map +0 -1
  24. package/dist/channels/binop.d.ts +0 -22
  25. package/dist/channels/binop.d.ts.map +0 -1
  26. package/dist/channels/binop.js +0 -49
  27. package/dist/channels/binop.js.map +0 -1
  28. package/dist/channels/dynamic_barrier_value.cjs +0 -76
  29. package/dist/channels/dynamic_barrier_value.cjs.map +0 -1
  30. package/dist/channels/dynamic_barrier_value.d.cts +0 -42
  31. package/dist/channels/dynamic_barrier_value.d.cts.map +0 -1
  32. package/dist/channels/dynamic_barrier_value.d.ts +0 -42
  33. package/dist/channels/dynamic_barrier_value.d.ts.map +0 -1
  34. package/dist/channels/dynamic_barrier_value.js +0 -76
  35. package/dist/channels/dynamic_barrier_value.js.map +0 -1
  36. package/dist/channels/ephemeral_value.cjs +0 -46
  37. package/dist/channels/ephemeral_value.cjs.map +0 -1
  38. package/dist/channels/ephemeral_value.d.cts +0 -22
  39. package/dist/channels/ephemeral_value.d.cts.map +0 -1
  40. package/dist/channels/ephemeral_value.d.ts +0 -22
  41. package/dist/channels/ephemeral_value.d.ts.map +0 -1
  42. package/dist/channels/ephemeral_value.js +0 -46
  43. package/dist/channels/ephemeral_value.js.map +0 -1
  44. package/dist/channels/index.cjs +0 -21
  45. package/dist/channels/index.d.cts +0 -9
  46. package/dist/channels/index.d.ts +0 -9
  47. package/dist/channels/index.js +0 -10
  48. package/dist/channels/last_value.cjs +0 -98
  49. package/dist/channels/last_value.cjs.map +0 -1
  50. package/dist/channels/last_value.d.cts +0 -44
  51. package/dist/channels/last_value.d.cts.map +0 -1
  52. package/dist/channels/last_value.d.ts +0 -44
  53. package/dist/channels/last_value.d.ts.map +0 -1
  54. package/dist/channels/last_value.js +0 -97
  55. package/dist/channels/last_value.js.map +0 -1
  56. package/dist/channels/named_barrier_value.cjs +0 -118
  57. package/dist/channels/named_barrier_value.cjs.map +0 -1
  58. package/dist/channels/named_barrier_value.d.cts +0 -46
  59. package/dist/channels/named_barrier_value.d.cts.map +0 -1
  60. package/dist/channels/named_barrier_value.d.ts +0 -46
  61. package/dist/channels/named_barrier_value.d.ts.map +0 -1
  62. package/dist/channels/named_barrier_value.js +0 -116
  63. package/dist/channels/named_barrier_value.js.map +0 -1
  64. package/dist/channels/topic.cjs +0 -65
  65. package/dist/channels/topic.cjs.map +0 -1
  66. package/dist/channels/topic.d.cts +0 -32
  67. package/dist/channels/topic.d.cts.map +0 -1
  68. package/dist/channels/topic.d.ts +0 -32
  69. package/dist/channels/topic.d.ts.map +0 -1
  70. package/dist/channels/topic.js +0 -65
  71. package/dist/channels/topic.js.map +0 -1
  72. package/dist/constants.cjs +0 -406
  73. package/dist/constants.cjs.map +0 -1
  74. package/dist/constants.d.cts +0 -285
  75. package/dist/constants.d.cts.map +0 -1
  76. package/dist/constants.d.ts +0 -285
  77. package/dist/constants.d.ts.map +0 -1
  78. package/dist/constants.js +0 -362
  79. package/dist/constants.js.map +0 -1
  80. package/dist/errors.cjs +0 -163
  81. package/dist/errors.cjs.map +0 -1
  82. package/dist/errors.d.cts +0 -81
  83. package/dist/errors.d.cts.map +0 -1
  84. package/dist/errors.d.ts +0 -81
  85. package/dist/errors.d.ts.map +0 -1
  86. package/dist/errors.js +0 -146
  87. package/dist/errors.js.map +0 -1
  88. package/dist/func/index.cjs +0 -301
  89. package/dist/func/index.cjs.map +0 -1
  90. package/dist/func/index.d.cts +0 -293
  91. package/dist/func/index.d.cts.map +0 -1
  92. package/dist/func/index.d.ts +0 -293
  93. package/dist/func/index.d.ts.map +0 -1
  94. package/dist/func/index.js +0 -298
  95. package/dist/func/index.js.map +0 -1
  96. package/dist/func/types.d.cts +0 -64
  97. package/dist/func/types.d.cts.map +0 -1
  98. package/dist/func/types.d.ts +0 -64
  99. package/dist/func/types.d.ts.map +0 -1
  100. package/dist/graph/annotation.cjs +0 -101
  101. package/dist/graph/annotation.cjs.map +0 -1
  102. package/dist/graph/annotation.d.cts +0 -116
  103. package/dist/graph/annotation.d.cts.map +0 -1
  104. package/dist/graph/annotation.d.ts +0 -116
  105. package/dist/graph/annotation.d.ts.map +0 -1
  106. package/dist/graph/annotation.js +0 -99
  107. package/dist/graph/annotation.js.map +0 -1
  108. package/dist/graph/graph.cjs +0 -423
  109. package/dist/graph/graph.cjs.map +0 -1
  110. package/dist/graph/graph.d.cts +0 -132
  111. package/dist/graph/graph.d.cts.map +0 -1
  112. package/dist/graph/graph.d.ts +0 -132
  113. package/dist/graph/graph.d.ts.map +0 -1
  114. package/dist/graph/graph.js +0 -420
  115. package/dist/graph/graph.js.map +0 -1
  116. package/dist/graph/index.cjs +0 -5
  117. package/dist/graph/index.js +0 -7
  118. package/dist/graph/message.cjs +0 -99
  119. package/dist/graph/message.cjs.map +0 -1
  120. package/dist/graph/message.d.cts +0 -40
  121. package/dist/graph/message.d.cts.map +0 -1
  122. package/dist/graph/message.d.ts +0 -40
  123. package/dist/graph/message.d.ts.map +0 -1
  124. package/dist/graph/message.js +0 -95
  125. package/dist/graph/message.js.map +0 -1
  126. package/dist/graph/messages_annotation.cjs +0 -110
  127. package/dist/graph/messages_annotation.cjs.map +0 -1
  128. package/dist/graph/messages_annotation.d.cts +0 -112
  129. package/dist/graph/messages_annotation.d.cts.map +0 -1
  130. package/dist/graph/messages_annotation.d.ts +0 -112
  131. package/dist/graph/messages_annotation.d.ts.map +0 -1
  132. package/dist/graph/messages_annotation.js +0 -107
  133. package/dist/graph/messages_annotation.js.map +0 -1
  134. package/dist/graph/state.cjs +0 -501
  135. package/dist/graph/state.cjs.map +0 -1
  136. package/dist/graph/state.d.cts +0 -236
  137. package/dist/graph/state.d.cts.map +0 -1
  138. package/dist/graph/state.d.ts +0 -236
  139. package/dist/graph/state.d.ts.map +0 -1
  140. package/dist/graph/state.js +0 -499
  141. package/dist/graph/state.js.map +0 -1
  142. package/dist/graph/zod/index.cjs +0 -10
  143. package/dist/graph/zod/index.d.cts +0 -3
  144. package/dist/graph/zod/index.d.ts +0 -3
  145. package/dist/graph/zod/index.js +0 -5
  146. package/dist/graph/zod/meta.cjs +0 -145
  147. package/dist/graph/zod/meta.cjs.map +0 -1
  148. package/dist/graph/zod/meta.d.cts +0 -116
  149. package/dist/graph/zod/meta.d.cts.map +0 -1
  150. package/dist/graph/zod/meta.d.ts +0 -116
  151. package/dist/graph/zod/meta.d.ts.map +0 -1
  152. package/dist/graph/zod/meta.js +0 -141
  153. package/dist/graph/zod/meta.js.map +0 -1
  154. package/dist/graph/zod/plugin.cjs +0 -41
  155. package/dist/graph/zod/plugin.cjs.map +0 -1
  156. package/dist/graph/zod/plugin.js +0 -41
  157. package/dist/graph/zod/plugin.js.map +0 -1
  158. package/dist/graph/zod/schema.cjs +0 -99
  159. package/dist/graph/zod/schema.cjs.map +0 -1
  160. package/dist/graph/zod/schema.d.cts +0 -38
  161. package/dist/graph/zod/schema.d.cts.map +0 -1
  162. package/dist/graph/zod/schema.d.ts +0 -38
  163. package/dist/graph/zod/schema.d.ts.map +0 -1
  164. package/dist/graph/zod/schema.js +0 -94
  165. package/dist/graph/zod/schema.js.map +0 -1
  166. package/dist/graph/zod/zod-registry.cjs +0 -43
  167. package/dist/graph/zod/zod-registry.cjs.map +0 -1
  168. package/dist/graph/zod/zod-registry.d.cts +0 -51
  169. package/dist/graph/zod/zod-registry.d.cts.map +0 -1
  170. package/dist/graph/zod/zod-registry.d.ts +0 -51
  171. package/dist/graph/zod/zod-registry.d.ts.map +0 -1
  172. package/dist/graph/zod/zod-registry.js +0 -41
  173. package/dist/graph/zod/zod-registry.js.map +0 -1
  174. package/dist/hash.cjs +0 -271
  175. package/dist/hash.cjs.map +0 -1
  176. package/dist/hash.js +0 -269
  177. package/dist/hash.js.map +0 -1
  178. package/dist/index.cjs +0 -112
  179. package/dist/index.cjs.map +0 -1
  180. package/dist/index.d.cts +0 -26
  181. package/dist/index.d.ts +0 -26
  182. package/dist/index.js +0 -22
  183. package/dist/index.js.map +0 -1
  184. package/dist/interrupt.cjs +0 -82
  185. package/dist/interrupt.cjs.map +0 -1
  186. package/dist/interrupt.d.cts +0 -58
  187. package/dist/interrupt.d.cts.map +0 -1
  188. package/dist/interrupt.d.ts +0 -58
  189. package/dist/interrupt.d.ts.map +0 -1
  190. package/dist/interrupt.js +0 -81
  191. package/dist/interrupt.js.map +0 -1
  192. package/dist/prebuilt/agentName.cjs +0 -153
  193. package/dist/prebuilt/agentName.cjs.map +0 -1
  194. package/dist/prebuilt/agentName.d.cts +0 -42
  195. package/dist/prebuilt/agentName.d.cts.map +0 -1
  196. package/dist/prebuilt/agentName.d.ts +0 -42
  197. package/dist/prebuilt/agentName.d.ts.map +0 -1
  198. package/dist/prebuilt/agentName.js +0 -152
  199. package/dist/prebuilt/agentName.js.map +0 -1
  200. package/dist/prebuilt/agent_executor.cjs +0 -44
  201. package/dist/prebuilt/agent_executor.cjs.map +0 -1
  202. package/dist/prebuilt/agent_executor.d.cts +0 -58
  203. package/dist/prebuilt/agent_executor.d.cts.map +0 -1
  204. package/dist/prebuilt/agent_executor.d.ts +0 -58
  205. package/dist/prebuilt/agent_executor.d.ts.map +0 -1
  206. package/dist/prebuilt/agent_executor.js +0 -44
  207. package/dist/prebuilt/agent_executor.js.map +0 -1
  208. package/dist/prebuilt/chat_agent_executor.cjs +0 -68
  209. package/dist/prebuilt/chat_agent_executor.cjs.map +0 -1
  210. package/dist/prebuilt/chat_agent_executor.d.cts +0 -23
  211. package/dist/prebuilt/chat_agent_executor.d.cts.map +0 -1
  212. package/dist/prebuilt/chat_agent_executor.d.ts +0 -23
  213. package/dist/prebuilt/chat_agent_executor.d.ts.map +0 -1
  214. package/dist/prebuilt/chat_agent_executor.js +0 -67
  215. package/dist/prebuilt/chat_agent_executor.js.map +0 -1
  216. package/dist/prebuilt/index.cjs +0 -15
  217. package/dist/prebuilt/index.d.cts +0 -8
  218. package/dist/prebuilt/index.d.ts +0 -8
  219. package/dist/prebuilt/index.js +0 -8
  220. package/dist/prebuilt/interrupt.d.cts +0 -61
  221. package/dist/prebuilt/interrupt.d.cts.map +0 -1
  222. package/dist/prebuilt/interrupt.d.ts +0 -61
  223. package/dist/prebuilt/interrupt.d.ts.map +0 -1
  224. package/dist/prebuilt/react_agent_executor.cjs +0 -344
  225. package/dist/prebuilt/react_agent_executor.cjs.map +0 -1
  226. package/dist/prebuilt/react_agent_executor.d.cts +0 -230
  227. package/dist/prebuilt/react_agent_executor.d.cts.map +0 -1
  228. package/dist/prebuilt/react_agent_executor.d.ts +0 -230
  229. package/dist/prebuilt/react_agent_executor.d.ts.map +0 -1
  230. package/dist/prebuilt/react_agent_executor.js +0 -342
  231. package/dist/prebuilt/react_agent_executor.js.map +0 -1
  232. package/dist/prebuilt/tool_executor.cjs +0 -48
  233. package/dist/prebuilt/tool_executor.cjs.map +0 -1
  234. package/dist/prebuilt/tool_executor.d.cts +0 -42
  235. package/dist/prebuilt/tool_executor.d.cts.map +0 -1
  236. package/dist/prebuilt/tool_executor.d.ts +0 -42
  237. package/dist/prebuilt/tool_executor.d.ts.map +0 -1
  238. package/dist/prebuilt/tool_executor.js +0 -47
  239. package/dist/prebuilt/tool_executor.js.map +0 -1
  240. package/dist/prebuilt/tool_node.cjs +0 -248
  241. package/dist/prebuilt/tool_node.cjs.map +0 -1
  242. package/dist/prebuilt/tool_node.d.cts +0 -182
  243. package/dist/prebuilt/tool_node.d.cts.map +0 -1
  244. package/dist/prebuilt/tool_node.d.ts +0 -182
  245. package/dist/prebuilt/tool_node.d.ts.map +0 -1
  246. package/dist/prebuilt/tool_node.js +0 -246
  247. package/dist/prebuilt/tool_node.js.map +0 -1
  248. package/dist/pregel/algo.cjs +0 -573
  249. package/dist/pregel/algo.cjs.map +0 -1
  250. package/dist/pregel/algo.d.cts +0 -13
  251. package/dist/pregel/algo.d.cts.map +0 -1
  252. package/dist/pregel/algo.d.ts +0 -13
  253. package/dist/pregel/algo.d.ts.map +0 -1
  254. package/dist/pregel/algo.js +0 -567
  255. package/dist/pregel/algo.js.map +0 -1
  256. package/dist/pregel/call.cjs +0 -53
  257. package/dist/pregel/call.cjs.map +0 -1
  258. package/dist/pregel/call.js +0 -50
  259. package/dist/pregel/call.js.map +0 -1
  260. package/dist/pregel/debug.cjs +0 -175
  261. package/dist/pregel/debug.cjs.map +0 -1
  262. package/dist/pregel/debug.js +0 -169
  263. package/dist/pregel/debug.js.map +0 -1
  264. package/dist/pregel/index.cjs +0 -1170
  265. package/dist/pregel/index.cjs.map +0 -1
  266. package/dist/pregel/index.d.cts +0 -546
  267. package/dist/pregel/index.d.cts.map +0 -1
  268. package/dist/pregel/index.d.ts +0 -546
  269. package/dist/pregel/index.d.ts.map +0 -1
  270. package/dist/pregel/index.js +0 -1168
  271. package/dist/pregel/index.js.map +0 -1
  272. package/dist/pregel/io.cjs +0 -140
  273. package/dist/pregel/io.cjs.map +0 -1
  274. package/dist/pregel/io.js +0 -135
  275. package/dist/pregel/io.js.map +0 -1
  276. package/dist/pregel/loop.cjs +0 -548
  277. package/dist/pregel/loop.cjs.map +0 -1
  278. package/dist/pregel/loop.js +0 -547
  279. package/dist/pregel/loop.js.map +0 -1
  280. package/dist/pregel/messages.cjs +0 -108
  281. package/dist/pregel/messages.cjs.map +0 -1
  282. package/dist/pregel/messages.js +0 -107
  283. package/dist/pregel/messages.js.map +0 -1
  284. package/dist/pregel/read.cjs +0 -152
  285. package/dist/pregel/read.cjs.map +0 -1
  286. package/dist/pregel/read.d.cts +0 -51
  287. package/dist/pregel/read.d.cts.map +0 -1
  288. package/dist/pregel/read.d.ts +0 -51
  289. package/dist/pregel/read.d.ts.map +0 -1
  290. package/dist/pregel/read.js +0 -150
  291. package/dist/pregel/read.js.map +0 -1
  292. package/dist/pregel/remote.cjs +0 -346
  293. package/dist/pregel/remote.cjs.map +0 -1
  294. package/dist/pregel/remote.d.cts +0 -121
  295. package/dist/pregel/remote.d.cts.map +0 -1
  296. package/dist/pregel/remote.d.ts +0 -121
  297. package/dist/pregel/remote.d.ts.map +0 -1
  298. package/dist/pregel/remote.js +0 -345
  299. package/dist/pregel/remote.js.map +0 -1
  300. package/dist/pregel/retry.cjs +0 -92
  301. package/dist/pregel/retry.cjs.map +0 -1
  302. package/dist/pregel/retry.js +0 -92
  303. package/dist/pregel/retry.js.map +0 -1
  304. package/dist/pregel/runnable_types.d.cts +0 -49
  305. package/dist/pregel/runnable_types.d.cts.map +0 -1
  306. package/dist/pregel/runnable_types.d.ts +0 -49
  307. package/dist/pregel/runnable_types.d.ts.map +0 -1
  308. package/dist/pregel/runner.cjs +0 -228
  309. package/dist/pregel/runner.cjs.map +0 -1
  310. package/dist/pregel/runner.js +0 -228
  311. package/dist/pregel/runner.js.map +0 -1
  312. package/dist/pregel/stream.cjs +0 -199
  313. package/dist/pregel/stream.cjs.map +0 -1
  314. package/dist/pregel/stream.js +0 -196
  315. package/dist/pregel/stream.js.map +0 -1
  316. package/dist/pregel/types.cjs +0 -27
  317. package/dist/pregel/types.cjs.map +0 -1
  318. package/dist/pregel/types.d.cts +0 -453
  319. package/dist/pregel/types.d.cts.map +0 -1
  320. package/dist/pregel/types.d.ts +0 -453
  321. package/dist/pregel/types.d.ts.map +0 -1
  322. package/dist/pregel/types.js +0 -25
  323. package/dist/pregel/types.js.map +0 -1
  324. package/dist/pregel/utils/config.cjs +0 -122
  325. package/dist/pregel/utils/config.cjs.map +0 -1
  326. package/dist/pregel/utils/config.d.cts +0 -36
  327. package/dist/pregel/utils/config.d.cts.map +0 -1
  328. package/dist/pregel/utils/config.d.ts +0 -36
  329. package/dist/pregel/utils/config.d.ts.map +0 -1
  330. package/dist/pregel/utils/config.js +0 -115
  331. package/dist/pregel/utils/config.js.map +0 -1
  332. package/dist/pregel/utils/index.cjs +0 -103
  333. package/dist/pregel/utils/index.cjs.map +0 -1
  334. package/dist/pregel/utils/index.d.cts +0 -51
  335. package/dist/pregel/utils/index.d.cts.map +0 -1
  336. package/dist/pregel/utils/index.d.ts +0 -51
  337. package/dist/pregel/utils/index.d.ts.map +0 -1
  338. package/dist/pregel/utils/index.js +0 -97
  339. package/dist/pregel/utils/index.js.map +0 -1
  340. package/dist/pregel/utils/subgraph.cjs +0 -19
  341. package/dist/pregel/utils/subgraph.cjs.map +0 -1
  342. package/dist/pregel/utils/subgraph.js +0 -17
  343. package/dist/pregel/utils/subgraph.js.map +0 -1
  344. package/dist/pregel/validate.cjs +0 -45
  345. package/dist/pregel/validate.cjs.map +0 -1
  346. package/dist/pregel/validate.js +0 -44
  347. package/dist/pregel/validate.js.map +0 -1
  348. package/dist/pregel/write.cjs +0 -97
  349. package/dist/pregel/write.cjs.map +0 -1
  350. package/dist/pregel/write.d.cts +0 -35
  351. package/dist/pregel/write.d.cts.map +0 -1
  352. package/dist/pregel/write.d.ts +0 -35
  353. package/dist/pregel/write.d.ts.map +0 -1
  354. package/dist/pregel/write.js +0 -95
  355. package/dist/pregel/write.js.map +0 -1
  356. package/dist/remote.cjs +0 -3
  357. package/dist/remote.d.cts +0 -2
  358. package/dist/remote.d.ts +0 -2
  359. package/dist/remote.js +0 -3
  360. package/dist/setup/async_local_storage.cjs +0 -12
  361. package/dist/setup/async_local_storage.cjs.map +0 -1
  362. package/dist/setup/async_local_storage.js +0 -11
  363. package/dist/setup/async_local_storage.js.map +0 -1
  364. package/dist/utils.cjs +0 -88
  365. package/dist/utils.cjs.map +0 -1
  366. package/dist/utils.d.cts +0 -32
  367. package/dist/utils.d.cts.map +0 -1
  368. package/dist/utils.d.ts +0 -32
  369. package/dist/utils.d.ts.map +0 -1
  370. package/dist/utils.js +0 -81
  371. package/dist/utils.js.map +0 -1
  372. package/dist/web.cjs +0 -96
  373. package/dist/web.d.cts +0 -23
  374. package/dist/web.d.ts +0 -23
  375. package/dist/web.js +0 -15
  376. package/dist/writer.cjs +0 -15
  377. package/dist/writer.cjs.map +0 -1
  378. package/dist/writer.d.cts +0 -7
  379. package/dist/writer.d.cts.map +0 -1
  380. package/dist/writer.d.ts +0 -7
  381. package/dist/writer.d.ts.map +0 -1
  382. package/dist/writer.js +0 -14
  383. package/dist/writer.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool_executor.js","names":[],"sources":["../../src/prebuilt/tool_executor.ts"],"sourcesContent":["import {\n RunnableBinding,\n RunnableConfig,\n RunnableLambda,\n RunnableToolLike,\n} from \"@langchain/core/runnables\";\nimport { StructuredToolInterface } from \"@langchain/core/tools\";\n\nconst INVALID_TOOL_MSG_TEMPLATE = `{requestedToolName} is not a valid tool, try one of {availableToolNamesString}.`;\n\n/** @deprecated Use {@link ToolNode} instead. */\nexport interface ToolExecutorArgs {\n tools: Array<StructuredToolInterface | RunnableToolLike>;\n /**\n * @default {INVALID_TOOL_MSG_TEMPLATE}\n */\n invalidToolMsgTemplate?: string;\n}\n\n/**\n * Interface for invoking a tool\n */\nexport interface ToolInvocationInterface {\n tool: string;\n toolInput: string;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ToolExecutorInputType = any;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ToolExecutorOutputType = any;\n\n/** @deprecated Use {@link ToolNode} instead. */\nexport class ToolExecutor extends RunnableBinding<\n ToolExecutorInputType,\n ToolExecutorOutputType\n> {\n lc_graph_name = \"ToolExecutor\";\n\n tools: Array<StructuredToolInterface | RunnableToolLike>;\n\n toolMap: Record<string, StructuredToolInterface | RunnableToolLike>;\n\n invalidToolMsgTemplate: string;\n\n constructor(fields: ToolExecutorArgs) {\n const fieldsWithDefaults = {\n invalidToolMsgTemplate: INVALID_TOOL_MSG_TEMPLATE,\n ...fields,\n };\n const bound = RunnableLambda.from(\n async (input: ToolInvocationInterface, config?: RunnableConfig) =>\n this._execute(input, config)\n );\n super({\n bound,\n config: {},\n });\n this.tools = fieldsWithDefaults.tools;\n this.invalidToolMsgTemplate = fieldsWithDefaults.invalidToolMsgTemplate;\n this.toolMap = this.tools.reduce((acc, tool) => {\n acc[tool.name] = tool;\n return acc;\n }, {} as Record<string, StructuredToolInterface | RunnableToolLike>);\n }\n\n /**\n * Execute a tool invocation\n *\n * @param {ToolInvocationInterface} toolInvocation The tool to invoke and the input to pass to it.\n * @param {RunnableConfig | undefined} config Optional configuration to pass to the tool when invoked.\n * @returns Either the result of the tool invocation (`string` or `ToolMessage`, set by the `ToolOutput` generic) or a string error message.\n */\n async _execute(\n toolInvocation: ToolInvocationInterface,\n config?: RunnableConfig\n ): Promise<ToolExecutorOutputType> {\n if (!(toolInvocation.tool in this.toolMap)) {\n return this.invalidToolMsgTemplate\n .replace(\"{requestedToolName}\", toolInvocation.tool)\n .replace(\n \"{availableToolNamesString}\",\n Object.keys(this.toolMap).join(\", \")\n );\n } else {\n const tool = this.toolMap[toolInvocation.tool];\n const output = await tool.invoke(toolInvocation.toolInput, config);\n return output;\n }\n }\n}\n"],"mappings":";;;AAQA,MAAM,4BAA4B;;AA0BlC,IAAa,eAAb,cAAkC,gBAGhC;CACA,gBAAgB;CAEhB;CAEA;CAEA;CAEA,YAAY,QAA0B;EACpC,MAAM,qBAAqB;GACzB,wBAAwB;GACxB,GAAG;;EAEL,MAAM,QAAQ,eAAe,KAC3B,OAAO,OAAgC,WACrC,KAAK,SAAS,OAAO;AAEzB,QAAM;GACJ;GACA,QAAQ;;AAEV,OAAK,QAAQ,mBAAmB;AAChC,OAAK,yBAAyB,mBAAmB;AACjD,OAAK,UAAU,KAAK,MAAM,QAAQ,KAAK,SAAS;AAC9C,OAAI,KAAK,QAAQ;AACjB,UAAO;KACN;;;;;;;;;CAUL,MAAM,SACJ,gBACA,QACiC;AACjC,MAAI,EAAE,eAAe,QAAQ,KAAK,SAChC,QAAO,KAAK,uBACT,QAAQ,uBAAuB,eAAe,MAC9C,QACC,8BACA,OAAO,KAAK,KAAK,SAAS,KAAK;OAE9B;GACL,MAAM,OAAO,KAAK,QAAQ,eAAe;GACzC,MAAM,SAAS,MAAM,KAAK,OAAO,eAAe,WAAW;AAC3D,UAAO"}
@@ -1,248 +0,0 @@
1
- const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
- const require_errors = require('../errors.cjs');
3
- const require_constants = require('../constants.cjs');
4
- const require_utils = require('../utils.cjs');
5
- const __langchain_core_messages = require_rolldown_runtime.__toESM(require("@langchain/core/messages"));
6
-
7
- //#region src/prebuilt/tool_node.ts
8
- const isBaseMessageArray = (input) => Array.isArray(input) && input.every(__langchain_core_messages.isBaseMessage);
9
- const isMessagesState = (input) => typeof input === "object" && input != null && "messages" in input && isBaseMessageArray(input.messages);
10
- const isSendInput = (input) => typeof input === "object" && input != null && "lg_tool_call" in input;
11
- /**
12
- * A node that runs the tools requested in the last AIMessage. It can be used
13
- * either in StateGraph with a "messages" key or in MessageGraph. If multiple
14
- * tool calls are requested, they will be run in parallel. The output will be
15
- * a list of ToolMessages, one for each tool call.
16
- *
17
- * @example
18
- * ```ts
19
- * import { ToolNode } from "@langchain/langgraph/prebuilt";
20
- * import { tool } from "@langchain/core/tools";
21
- * import { z } from "zod";
22
- * import { AIMessage } from "@langchain/core/messages";
23
- *
24
- * const getWeather = tool((input) => {
25
- * if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
26
- * return "It's 60 degrees and foggy.";
27
- * } else {
28
- * return "It's 90 degrees and sunny.";
29
- * }
30
- * }, {
31
- * name: "get_weather",
32
- * description: "Call to get the current weather.",
33
- * schema: z.object({
34
- * location: z.string().describe("Location to get the weather for."),
35
- * }),
36
- * });
37
- *
38
- * const tools = [getWeather];
39
- * const toolNode = new ToolNode(tools);
40
- *
41
- * const messageWithSingleToolCall = new AIMessage({
42
- * content: "",
43
- * tool_calls: [
44
- * {
45
- * name: "get_weather",
46
- * args: { location: "sf" },
47
- * id: "tool_call_id",
48
- * type: "tool_call",
49
- * }
50
- * ]
51
- * })
52
- *
53
- * await toolNode.invoke({ messages: [messageWithSingleToolCall] });
54
- * // Returns tool invocation responses as:
55
- * // { messages: ToolMessage[] }
56
- * ```
57
- *
58
- * @example
59
- * ```ts
60
- * import {
61
- * StateGraph,
62
- * MessagesAnnotation,
63
- * } from "@langchain/langgraph";
64
- * import { ToolNode } from "@langchain/langgraph/prebuilt";
65
- * import { tool } from "@langchain/core/tools";
66
- * import { z } from "zod";
67
- * import { ChatAnthropic } from "@langchain/anthropic";
68
- *
69
- * const getWeather = tool((input) => {
70
- * if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
71
- * return "It's 60 degrees and foggy.";
72
- * } else {
73
- * return "It's 90 degrees and sunny.";
74
- * }
75
- * }, {
76
- * name: "get_weather",
77
- * description: "Call to get the current weather.",
78
- * schema: z.object({
79
- * location: z.string().describe("Location to get the weather for."),
80
- * }),
81
- * });
82
- *
83
- * const tools = [getWeather];
84
- * const modelWithTools = new ChatAnthropic({
85
- * model: "claude-3-haiku-20240307",
86
- * temperature: 0
87
- * }).bindTools(tools);
88
- *
89
- * const toolNodeForGraph = new ToolNode(tools)
90
- *
91
- * const shouldContinue = (state: typeof MessagesAnnotation.State) => {
92
- * const { messages } = state;
93
- * const lastMessage = messages[messages.length - 1];
94
- * if ("tool_calls" in lastMessage && Array.isArray(lastMessage.tool_calls) && lastMessage.tool_calls?.length) {
95
- * return "tools";
96
- * }
97
- * return "__end__";
98
- * }
99
- *
100
- * const callModel = async (state: typeof MessagesAnnotation.State) => {
101
- * const { messages } = state;
102
- * const response = await modelWithTools.invoke(messages);
103
- * return { messages: response };
104
- * }
105
- *
106
- * const graph = new StateGraph(MessagesAnnotation)
107
- * .addNode("agent", callModel)
108
- * .addNode("tools", toolNodeForGraph)
109
- * .addEdge("__start__", "agent")
110
- * .addConditionalEdges("agent", shouldContinue)
111
- * .addEdge("tools", "agent")
112
- * .compile();
113
- *
114
- * const inputs = {
115
- * messages: [{ role: "user", content: "what is the weather in SF?" }],
116
- * };
117
- *
118
- * const stream = await graph.stream(inputs, {
119
- * streamMode: "values",
120
- * });
121
- *
122
- * for await (const { messages } of stream) {
123
- * console.log(messages);
124
- * }
125
- * // Returns the messages in the state at each step of execution
126
- * ```
127
- */
128
- var ToolNode = class extends require_utils.RunnableCallable {
129
- tools;
130
- handleToolErrors = true;
131
- trace = false;
132
- constructor(tools, options) {
133
- const { name, tags, handleToolErrors } = options ?? {};
134
- super({
135
- name,
136
- tags,
137
- func: (input, config) => this.run(input, config)
138
- });
139
- this.tools = tools;
140
- this.handleToolErrors = handleToolErrors ?? this.handleToolErrors;
141
- }
142
- async runTool(call, config) {
143
- const tool = this.tools.find((tool$1) => tool$1.name === call.name);
144
- try {
145
- if (tool === void 0) throw new Error(`Tool "${call.name}" not found.`);
146
- const output = await tool.invoke({
147
- ...call,
148
- type: "tool_call"
149
- }, config);
150
- if ((0, __langchain_core_messages.isBaseMessage)(output) && output.getType() === "tool" || require_constants.isCommand(output)) return output;
151
- return new __langchain_core_messages.ToolMessage({
152
- status: "success",
153
- name: tool.name,
154
- content: typeof output === "string" ? output : JSON.stringify(output),
155
- tool_call_id: call.id
156
- });
157
- } catch (e) {
158
- if (!this.handleToolErrors) throw e;
159
- if (require_errors.isGraphInterrupt(e)) throw e;
160
- return new __langchain_core_messages.ToolMessage({
161
- status: "error",
162
- content: `Error: ${e.message}\n Please fix your mistakes.`,
163
- name: call.name,
164
- tool_call_id: call.id ?? ""
165
- });
166
- }
167
- }
168
- async run(input, config) {
169
- let outputs;
170
- if (isSendInput(input)) outputs = [await this.runTool(input.lg_tool_call, config)];
171
- else {
172
- let messages;
173
- if (isBaseMessageArray(input)) messages = input;
174
- else if (isMessagesState(input)) messages = input.messages;
175
- else throw new Error("ToolNode only accepts BaseMessage[] or { messages: BaseMessage[] } as input.");
176
- const toolMessageIds = new Set(messages.filter((msg) => msg.getType() === "tool").map((msg) => msg.tool_call_id));
177
- let aiMessage;
178
- for (let i = messages.length - 1; i >= 0; i -= 1) {
179
- const message = messages[i];
180
- if ((0, __langchain_core_messages.isAIMessage)(message)) {
181
- aiMessage = message;
182
- break;
183
- }
184
- }
185
- if (aiMessage == null || !(0, __langchain_core_messages.isAIMessage)(aiMessage)) throw new Error("ToolNode only accepts AIMessages as input.");
186
- outputs = await Promise.all(aiMessage.tool_calls?.filter((call) => call.id == null || !toolMessageIds.has(call.id)).map((call) => this.runTool(call, config)) ?? []);
187
- }
188
- if (!outputs.some(require_constants.isCommand)) return Array.isArray(input) ? outputs : { messages: outputs };
189
- const combinedOutputs = [];
190
- let parentCommand = null;
191
- for (const output of outputs) if (require_constants.isCommand(output)) if (output.graph === require_constants.Command.PARENT && Array.isArray(output.goto) && output.goto.every((send) => require_constants._isSend(send))) if (parentCommand) parentCommand.goto.push(...output.goto);
192
- else parentCommand = new require_constants.Command({
193
- graph: require_constants.Command.PARENT,
194
- goto: output.goto
195
- });
196
- else combinedOutputs.push(output);
197
- else combinedOutputs.push(Array.isArray(input) ? [output] : { messages: [output] });
198
- if (parentCommand) combinedOutputs.push(parentCommand);
199
- return combinedOutputs;
200
- }
201
- };
202
- /**
203
- * A conditional edge function that determines whether to route to a tools node or end the graph.
204
- *
205
- * This function is designed to be used as a conditional edge in a LangGraph state graph to implement
206
- * the common pattern of checking if an AI message contains tool calls that need to be executed.
207
- *
208
- * @param state - The current state of the graph, which can be either:
209
- * - An array of `BaseMessage` objects, where the last message is checked for tool calls
210
- * - A state object conforming to `MessagesAnnotation.State`, which contains a `messages` array
211
- *
212
- * @returns A string indicating the next node to route to:
213
- * - `"tools"` - If the last message contains tool calls that need to be executed
214
- * - `END` - If there are no tool calls, indicating the graph should terminate
215
- *
216
- * @example
217
- * ```typescript
218
- * import { StateGraph, MessagesAnnotation, END, START } from "@langchain/langgraph";
219
- * import { ToolNode, toolsCondition } from "@langchain/langgraph/prebuilt";
220
- *
221
- * const graph = new StateGraph(MessagesAnnotation)
222
- * .addNode("agent", agentNode)
223
- * .addNode("tools", new ToolNode([searchTool, calculatorTool]))
224
- * .addEdge(START, "agent")
225
- * .addConditionalEdges("agent", toolsCondition, ["tools", END])
226
- * .addEdge("tools", "agent")
227
- * .compile();
228
- * ```
229
- *
230
- * @remarks
231
- * The function checks the last message in the state for the presence of `tool_calls`.
232
- * If the message is an `AIMessage` with one or more tool calls, it returns `"tools"`,
233
- * indicating that the graph should route to a tools node (typically a `ToolNode`) to
234
- * execute those tool calls. Otherwise, it returns `END` to terminate the graph execution.
235
- *
236
- * This is a common pattern in agentic workflows where an AI model decides whether to
237
- * use tools or provide a final response.
238
- */
239
- function toolsCondition(state) {
240
- const message = Array.isArray(state) ? state[state.length - 1] : state.messages[state.messages.length - 1];
241
- if (message !== void 0 && "tool_calls" in message && (message.tool_calls?.length ?? 0) > 0) return "tools";
242
- else return require_constants.END;
243
- }
244
-
245
- //#endregion
246
- exports.ToolNode = ToolNode;
247
- exports.toolsCondition = toolsCondition;
248
- //# sourceMappingURL=tool_node.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool_node.cjs","names":["isBaseMessage","RunnableCallable","tool","isCommand","ToolMessage","e: any","isGraphInterrupt","outputs: (ToolMessage | Command)[]","messages: BaseMessage[]","toolMessageIds: Set<string>","aiMessage: AIMessage | undefined","combinedOutputs: (\n | { messages: BaseMessage[] }\n | BaseMessage[]\n | Command\n )[]","parentCommand: Command | null","Command","_isSend","END"],"sources":["../../src/prebuilt/tool_node.ts"],"sourcesContent":["import {\n BaseMessage,\n ToolMessage,\n AIMessage,\n isBaseMessage,\n isAIMessage,\n} from \"@langchain/core/messages\";\nimport { RunnableConfig, RunnableToolLike } from \"@langchain/core/runnables\";\nimport { DynamicTool, StructuredToolInterface } from \"@langchain/core/tools\";\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\nimport { RunnableCallable } from \"../utils.js\";\nimport { MessagesAnnotation } from \"../graph/messages_annotation.js\";\nimport { isGraphInterrupt } from \"../errors.js\";\nimport { END, isCommand, Command, _isSend, Send } from \"../constants.js\";\n\nexport type ToolNodeOptions = {\n name?: string;\n tags?: string[];\n handleToolErrors?: boolean;\n};\n\nconst isBaseMessageArray = (input: unknown): input is BaseMessage[] =>\n Array.isArray(input) && input.every(isBaseMessage);\n\nconst isMessagesState = (\n input: unknown\n): input is { messages: BaseMessage[] } =>\n typeof input === \"object\" &&\n input != null &&\n \"messages\" in input &&\n isBaseMessageArray(input.messages);\n\nconst isSendInput = (input: unknown): input is { lg_tool_call: ToolCall } =>\n typeof input === \"object\" && input != null && \"lg_tool_call\" in input;\n\n/**\n * A node that runs the tools requested in the last AIMessage. It can be used\n * either in StateGraph with a \"messages\" key or in MessageGraph. If multiple\n * tool calls are requested, they will be run in parallel. The output will be\n * a list of ToolMessages, one for each tool call.\n *\n * @example\n * ```ts\n * import { ToolNode } from \"@langchain/langgraph/prebuilt\";\n * import { tool } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n * import { AIMessage } from \"@langchain/core/messages\";\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * }),\n * });\n *\n * const tools = [getWeather];\n * const toolNode = new ToolNode(tools);\n *\n * const messageWithSingleToolCall = new AIMessage({\n * content: \"\",\n * tool_calls: [\n * {\n * name: \"get_weather\",\n * args: { location: \"sf\" },\n * id: \"tool_call_id\",\n * type: \"tool_call\",\n * }\n * ]\n * })\n *\n * await toolNode.invoke({ messages: [messageWithSingleToolCall] });\n * // Returns tool invocation responses as:\n * // { messages: ToolMessage[] }\n * ```\n *\n * @example\n * ```ts\n * import {\n * StateGraph,\n * MessagesAnnotation,\n * } from \"@langchain/langgraph\";\n * import { ToolNode } from \"@langchain/langgraph/prebuilt\";\n * import { tool } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * }),\n * });\n *\n * const tools = [getWeather];\n * const modelWithTools = new ChatAnthropic({\n * model: \"claude-3-haiku-20240307\",\n * temperature: 0\n * }).bindTools(tools);\n *\n * const toolNodeForGraph = new ToolNode(tools)\n *\n * const shouldContinue = (state: typeof MessagesAnnotation.State) => {\n * const { messages } = state;\n * const lastMessage = messages[messages.length - 1];\n * if (\"tool_calls\" in lastMessage && Array.isArray(lastMessage.tool_calls) && lastMessage.tool_calls?.length) {\n * return \"tools\";\n * }\n * return \"__end__\";\n * }\n *\n * const callModel = async (state: typeof MessagesAnnotation.State) => {\n * const { messages } = state;\n * const response = await modelWithTools.invoke(messages);\n * return { messages: response };\n * }\n *\n * const graph = new StateGraph(MessagesAnnotation)\n * .addNode(\"agent\", callModel)\n * .addNode(\"tools\", toolNodeForGraph)\n * .addEdge(\"__start__\", \"agent\")\n * .addConditionalEdges(\"agent\", shouldContinue)\n * .addEdge(\"tools\", \"agent\")\n * .compile();\n *\n * const inputs = {\n * messages: [{ role: \"user\", content: \"what is the weather in SF?\" }],\n * };\n *\n * const stream = await graph.stream(inputs, {\n * streamMode: \"values\",\n * });\n *\n * for await (const { messages } of stream) {\n * console.log(messages);\n * }\n * // Returns the messages in the state at each step of execution\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class ToolNode<T = any> extends RunnableCallable<T, T> {\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[];\n\n handleToolErrors = true;\n\n trace = false;\n\n constructor(\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[],\n options?: ToolNodeOptions\n ) {\n const { name, tags, handleToolErrors } = options ?? {};\n super({ name, tags, func: (input, config) => this.run(input, config) });\n this.tools = tools;\n this.handleToolErrors = handleToolErrors ?? this.handleToolErrors;\n }\n\n protected async runTool(\n call: ToolCall,\n config: RunnableConfig\n ): Promise<ToolMessage | Command> {\n const tool = this.tools.find((tool) => tool.name === call.name);\n try {\n if (tool === undefined) {\n throw new Error(`Tool \"${call.name}\" not found.`);\n }\n const output = await tool.invoke({ ...call, type: \"tool_call\" }, config);\n\n if (\n (isBaseMessage(output) && output.getType() === \"tool\") ||\n isCommand(output)\n ) {\n return output as ToolMessage | Command;\n }\n\n return new ToolMessage({\n status: \"success\",\n name: tool.name,\n content: typeof output === \"string\" ? output : JSON.stringify(output),\n tool_call_id: call.id!,\n });\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n if (!this.handleToolErrors) throw e;\n\n if (isGraphInterrupt(e)) {\n // `NodeInterrupt` errors are a breakpoint to bring a human into the loop.\n // As such, they are not recoverable by the agent and shouldn't be fed\n // back. Instead, re-throw these errors even when `handleToolErrors = true`.\n throw e;\n }\n\n return new ToolMessage({\n status: \"error\",\n content: `Error: ${e.message}\\n Please fix your mistakes.`,\n name: call.name,\n tool_call_id: call.id ?? \"\",\n });\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected async run(input: unknown, config: RunnableConfig): Promise<T> {\n let outputs: (ToolMessage | Command)[];\n\n if (isSendInput(input)) {\n outputs = [await this.runTool(input.lg_tool_call, config)];\n } else {\n let messages: BaseMessage[];\n if (isBaseMessageArray(input)) {\n messages = input;\n } else if (isMessagesState(input)) {\n messages = input.messages;\n } else {\n throw new Error(\n \"ToolNode only accepts BaseMessage[] or { messages: BaseMessage[] } as input.\"\n );\n }\n\n const toolMessageIds: Set<string> = new Set(\n messages\n .filter((msg) => msg.getType() === \"tool\")\n .map((msg) => (msg as ToolMessage).tool_call_id)\n );\n\n let aiMessage: AIMessage | undefined;\n for (let i = messages.length - 1; i >= 0; i -= 1) {\n const message = messages[i];\n if (isAIMessage(message)) {\n aiMessage = message;\n break;\n }\n }\n\n if (aiMessage == null || !isAIMessage(aiMessage)) {\n throw new Error(\"ToolNode only accepts AIMessages as input.\");\n }\n\n outputs = await Promise.all(\n aiMessage.tool_calls\n ?.filter((call) => call.id == null || !toolMessageIds.has(call.id))\n .map((call) => this.runTool(call, config)) ?? []\n );\n }\n\n // Preserve existing behavior for non-command tool outputs for backwards compatibility\n if (!outputs.some(isCommand)) {\n return (Array.isArray(input) ? outputs : { messages: outputs }) as T;\n }\n\n // Handle mixed Command and non-Command outputs\n const combinedOutputs: (\n | { messages: BaseMessage[] }\n | BaseMessage[]\n | Command\n )[] = [];\n let parentCommand: Command | null = null;\n\n for (const output of outputs) {\n if (isCommand(output)) {\n if (\n output.graph === Command.PARENT &&\n Array.isArray(output.goto) &&\n output.goto.every((send) => _isSend(send))\n ) {\n if (parentCommand) {\n (parentCommand.goto as Send[]).push(...(output.goto as Send[]));\n } else {\n parentCommand = new Command({\n graph: Command.PARENT,\n goto: output.goto,\n });\n }\n } else {\n combinedOutputs.push(output);\n }\n } else {\n combinedOutputs.push(\n Array.isArray(input) ? [output] : { messages: [output] }\n );\n }\n }\n\n if (parentCommand) {\n combinedOutputs.push(parentCommand);\n }\n\n return combinedOutputs as T;\n }\n}\n\n/**\n * A conditional edge function that determines whether to route to a tools node or end the graph.\n *\n * This function is designed to be used as a conditional edge in a LangGraph state graph to implement\n * the common pattern of checking if an AI message contains tool calls that need to be executed.\n *\n * @param state - The current state of the graph, which can be either:\n * - An array of `BaseMessage` objects, where the last message is checked for tool calls\n * - A state object conforming to `MessagesAnnotation.State`, which contains a `messages` array\n *\n * @returns A string indicating the next node to route to:\n * - `\"tools\"` - If the last message contains tool calls that need to be executed\n * - `END` - If there are no tool calls, indicating the graph should terminate\n *\n * @example\n * ```typescript\n * import { StateGraph, MessagesAnnotation, END, START } from \"@langchain/langgraph\";\n * import { ToolNode, toolsCondition } from \"@langchain/langgraph/prebuilt\";\n *\n * const graph = new StateGraph(MessagesAnnotation)\n * .addNode(\"agent\", agentNode)\n * .addNode(\"tools\", new ToolNode([searchTool, calculatorTool]))\n * .addEdge(START, \"agent\")\n * .addConditionalEdges(\"agent\", toolsCondition, [\"tools\", END])\n * .addEdge(\"tools\", \"agent\")\n * .compile();\n * ```\n *\n * @remarks\n * The function checks the last message in the state for the presence of `tool_calls`.\n * If the message is an `AIMessage` with one or more tool calls, it returns `\"tools\"`,\n * indicating that the graph should route to a tools node (typically a `ToolNode`) to\n * execute those tool calls. Otherwise, it returns `END` to terminate the graph execution.\n *\n * This is a common pattern in agentic workflows where an AI model decides whether to\n * use tools or provide a final response.\n */\nexport function toolsCondition(\n state: BaseMessage[] | typeof MessagesAnnotation.State\n): \"tools\" | typeof END {\n const message = Array.isArray(state)\n ? state[state.length - 1]\n : state.messages[state.messages.length - 1];\n\n if (\n message !== undefined &&\n \"tool_calls\" in message &&\n ((message as AIMessage).tool_calls?.length ?? 0) > 0\n ) {\n return \"tools\";\n } else {\n return END;\n }\n}\n"],"mappings":";;;;;;;AAqBA,MAAM,sBAAsB,UAC1B,MAAM,QAAQ,UAAU,MAAM,MAAMA;AAEtC,MAAM,mBACJ,UAEA,OAAO,UAAU,YACjB,SAAS,QACT,cAAc,SACd,mBAAmB,MAAM;AAE3B,MAAM,eAAe,UACnB,OAAO,UAAU,YAAY,SAAS,QAAQ,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwHlE,IAAa,WAAb,cAAuCC,+BAAuB;CAC5D;CAEA,mBAAmB;CAEnB,QAAQ;CAER,YACE,OACA,SACA;EACA,MAAM,EAAE,MAAM,MAAM,qBAAqB,WAAW;AACpD,QAAM;GAAE;GAAM;GAAM,OAAO,OAAO,WAAW,KAAK,IAAI,OAAO;;AAC7D,OAAK,QAAQ;AACb,OAAK,mBAAmB,oBAAoB,KAAK;;CAGnD,MAAgB,QACd,MACA,QACgC;EAChC,MAAM,OAAO,KAAK,MAAM,MAAM,WAASC,OAAK,SAAS,KAAK;AAC1D,MAAI;AACF,OAAI,SAAS,OACX,OAAM,IAAI,MAAM,SAAS,KAAK,KAAK;GAErC,MAAM,SAAS,MAAM,KAAK,OAAO;IAAE,GAAG;IAAM,MAAM;MAAe;AAEjE,oDACiB,WAAW,OAAO,cAAc,UAC/CC,4BAAU,QAEV,QAAO;AAGT,UAAO,IAAIC,sCAAY;IACrB,QAAQ;IACR,MAAM,KAAK;IACX,SAAS,OAAO,WAAW,WAAW,SAAS,KAAK,UAAU;IAC9D,cAAc,KAAK;;WAGdC,GAAQ;AACf,OAAI,CAAC,KAAK,iBAAkB,OAAM;AAElC,OAAIC,gCAAiB,GAInB,OAAM;AAGR,UAAO,IAAIF,sCAAY;IACrB,QAAQ;IACR,SAAS,UAAU,EAAE,QAAQ;IAC7B,MAAM,KAAK;IACX,cAAc,KAAK,MAAM;;;;CAM/B,MAAgB,IAAI,OAAgB,QAAoC;EACtE,IAAIG;AAEJ,MAAI,YAAY,OACd,WAAU,CAAC,MAAM,KAAK,QAAQ,MAAM,cAAc;OAC7C;GACL,IAAIC;AACJ,OAAI,mBAAmB,OACrB,YAAW;YACF,gBAAgB,OACzB,YAAW,MAAM;OAEjB,OAAM,IAAI,MACR;GAIJ,MAAMC,iBAA8B,IAAI,IACtC,SACG,QAAQ,QAAQ,IAAI,cAAc,QAClC,KAAK,QAAS,IAAoB;GAGvC,IAAIC;AACJ,QAAK,IAAI,IAAI,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG;IAChD,MAAM,UAAU,SAAS;AACzB,mDAAgB,UAAU;AACxB,iBAAY;AACZ;;;AAIJ,OAAI,aAAa,QAAQ,4CAAa,WACpC,OAAM,IAAI,MAAM;AAGlB,aAAU,MAAM,QAAQ,IACtB,UAAU,YACN,QAAQ,SAAS,KAAK,MAAM,QAAQ,CAAC,eAAe,IAAI,KAAK,KAC9D,KAAK,SAAS,KAAK,QAAQ,MAAM,YAAY;;AAKpD,MAAI,CAAC,QAAQ,KAAKP,6BAChB,QAAQ,MAAM,QAAQ,SAAS,UAAU,EAAE,UAAU;EAIvD,MAAMQ,kBAIA;EACN,IAAIC,gBAAgC;AAEpC,OAAK,MAAM,UAAU,QACnB,KAAIT,4BAAU,QACZ,KACE,OAAO,UAAUU,0BAAQ,UACzB,MAAM,QAAQ,OAAO,SACrB,OAAO,KAAK,OAAO,SAASC,0BAAQ,OAEpC,KAAI,cACF,CAAC,cAAc,KAAgB,KAAK,GAAI,OAAO;MAE/C,iBAAgB,IAAID,0BAAQ;GAC1B,OAAOA,0BAAQ;GACf,MAAM,OAAO;;MAIjB,iBAAgB,KAAK;MAGvB,iBAAgB,KACd,MAAM,QAAQ,SAAS,CAAC,UAAU,EAAE,UAAU,CAAC;AAKrD,MAAI,cACF,iBAAgB,KAAK;AAGvB,SAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCX,SAAgB,eACd,OACsB;CACtB,MAAM,UAAU,MAAM,QAAQ,SAC1B,MAAM,MAAM,SAAS,KACrB,MAAM,SAAS,MAAM,SAAS,SAAS;AAE3C,KACE,YAAY,UACZ,gBAAgB,YACd,QAAsB,YAAY,UAAU,KAAK,EAEnD,QAAO;KAEP,QAAOE"}
@@ -1,182 +0,0 @@
1
- import { RunnableCallable } from "../utils.cjs";
2
- import { Command, END } from "../constants.cjs";
3
- import { MessagesAnnotation } from "../graph/messages_annotation.cjs";
4
- import { RunnableConfig, RunnableToolLike } from "@langchain/core/runnables";
5
- import { BaseMessage, ToolMessage } from "@langchain/core/messages";
6
- import { DynamicTool, StructuredToolInterface } from "@langchain/core/tools";
7
- import { ToolCall } from "@langchain/core/messages/tool";
8
-
9
- //#region src/prebuilt/tool_node.d.ts
10
- type ToolNodeOptions = {
11
- name?: string;
12
- tags?: string[];
13
- handleToolErrors?: boolean;
14
- };
15
- /**
16
- * A node that runs the tools requested in the last AIMessage. It can be used
17
- * either in StateGraph with a "messages" key or in MessageGraph. If multiple
18
- * tool calls are requested, they will be run in parallel. The output will be
19
- * a list of ToolMessages, one for each tool call.
20
- *
21
- * @example
22
- * ```ts
23
- * import { ToolNode } from "@langchain/langgraph/prebuilt";
24
- * import { tool } from "@langchain/core/tools";
25
- * import { z } from "zod";
26
- * import { AIMessage } from "@langchain/core/messages";
27
- *
28
- * const getWeather = tool((input) => {
29
- * if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
30
- * return "It's 60 degrees and foggy.";
31
- * } else {
32
- * return "It's 90 degrees and sunny.";
33
- * }
34
- * }, {
35
- * name: "get_weather",
36
- * description: "Call to get the current weather.",
37
- * schema: z.object({
38
- * location: z.string().describe("Location to get the weather for."),
39
- * }),
40
- * });
41
- *
42
- * const tools = [getWeather];
43
- * const toolNode = new ToolNode(tools);
44
- *
45
- * const messageWithSingleToolCall = new AIMessage({
46
- * content: "",
47
- * tool_calls: [
48
- * {
49
- * name: "get_weather",
50
- * args: { location: "sf" },
51
- * id: "tool_call_id",
52
- * type: "tool_call",
53
- * }
54
- * ]
55
- * })
56
- *
57
- * await toolNode.invoke({ messages: [messageWithSingleToolCall] });
58
- * // Returns tool invocation responses as:
59
- * // { messages: ToolMessage[] }
60
- * ```
61
- *
62
- * @example
63
- * ```ts
64
- * import {
65
- * StateGraph,
66
- * MessagesAnnotation,
67
- * } from "@langchain/langgraph";
68
- * import { ToolNode } from "@langchain/langgraph/prebuilt";
69
- * import { tool } from "@langchain/core/tools";
70
- * import { z } from "zod";
71
- * import { ChatAnthropic } from "@langchain/anthropic";
72
- *
73
- * const getWeather = tool((input) => {
74
- * if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
75
- * return "It's 60 degrees and foggy.";
76
- * } else {
77
- * return "It's 90 degrees and sunny.";
78
- * }
79
- * }, {
80
- * name: "get_weather",
81
- * description: "Call to get the current weather.",
82
- * schema: z.object({
83
- * location: z.string().describe("Location to get the weather for."),
84
- * }),
85
- * });
86
- *
87
- * const tools = [getWeather];
88
- * const modelWithTools = new ChatAnthropic({
89
- * model: "claude-3-haiku-20240307",
90
- * temperature: 0
91
- * }).bindTools(tools);
92
- *
93
- * const toolNodeForGraph = new ToolNode(tools)
94
- *
95
- * const shouldContinue = (state: typeof MessagesAnnotation.State) => {
96
- * const { messages } = state;
97
- * const lastMessage = messages[messages.length - 1];
98
- * if ("tool_calls" in lastMessage && Array.isArray(lastMessage.tool_calls) && lastMessage.tool_calls?.length) {
99
- * return "tools";
100
- * }
101
- * return "__end__";
102
- * }
103
- *
104
- * const callModel = async (state: typeof MessagesAnnotation.State) => {
105
- * const { messages } = state;
106
- * const response = await modelWithTools.invoke(messages);
107
- * return { messages: response };
108
- * }
109
- *
110
- * const graph = new StateGraph(MessagesAnnotation)
111
- * .addNode("agent", callModel)
112
- * .addNode("tools", toolNodeForGraph)
113
- * .addEdge("__start__", "agent")
114
- * .addConditionalEdges("agent", shouldContinue)
115
- * .addEdge("tools", "agent")
116
- * .compile();
117
- *
118
- * const inputs = {
119
- * messages: [{ role: "user", content: "what is the weather in SF?" }],
120
- * };
121
- *
122
- * const stream = await graph.stream(inputs, {
123
- * streamMode: "values",
124
- * });
125
- *
126
- * for await (const { messages } of stream) {
127
- * console.log(messages);
128
- * }
129
- * // Returns the messages in the state at each step of execution
130
- * ```
131
- */
132
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
- declare class ToolNode<T = any> extends RunnableCallable<T, T> {
134
- tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[];
135
- handleToolErrors: boolean;
136
- trace: boolean;
137
- constructor(tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[], options?: ToolNodeOptions);
138
- protected runTool(call: ToolCall, config: RunnableConfig): Promise<ToolMessage | Command>;
139
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
140
- protected run(input: unknown, config: RunnableConfig): Promise<T>;
141
- }
142
- /**
143
- * A conditional edge function that determines whether to route to a tools node or end the graph.
144
- *
145
- * This function is designed to be used as a conditional edge in a LangGraph state graph to implement
146
- * the common pattern of checking if an AI message contains tool calls that need to be executed.
147
- *
148
- * @param state - The current state of the graph, which can be either:
149
- * - An array of `BaseMessage` objects, where the last message is checked for tool calls
150
- * - A state object conforming to `MessagesAnnotation.State`, which contains a `messages` array
151
- *
152
- * @returns A string indicating the next node to route to:
153
- * - `"tools"` - If the last message contains tool calls that need to be executed
154
- * - `END` - If there are no tool calls, indicating the graph should terminate
155
- *
156
- * @example
157
- * ```typescript
158
- * import { StateGraph, MessagesAnnotation, END, START } from "@langchain/langgraph";
159
- * import { ToolNode, toolsCondition } from "@langchain/langgraph/prebuilt";
160
- *
161
- * const graph = new StateGraph(MessagesAnnotation)
162
- * .addNode("agent", agentNode)
163
- * .addNode("tools", new ToolNode([searchTool, calculatorTool]))
164
- * .addEdge(START, "agent")
165
- * .addConditionalEdges("agent", toolsCondition, ["tools", END])
166
- * .addEdge("tools", "agent")
167
- * .compile();
168
- * ```
169
- *
170
- * @remarks
171
- * The function checks the last message in the state for the presence of `tool_calls`.
172
- * If the message is an `AIMessage` with one or more tool calls, it returns `"tools"`,
173
- * indicating that the graph should route to a tools node (typically a `ToolNode`) to
174
- * execute those tool calls. Otherwise, it returns `END` to terminate the graph execution.
175
- *
176
- * This is a common pattern in agentic workflows where an AI model decides whether to
177
- * use tools or provide a final response.
178
- */
179
- declare function toolsCondition(state: BaseMessage[] | typeof MessagesAnnotation.State): "tools" | typeof END;
180
- //#endregion
181
- export { ToolNode, ToolNodeOptions, toolsCondition };
182
- //# sourceMappingURL=tool_node.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool_node.d.cts","names":["BaseMessage","ToolMessage","RunnableConfig","RunnableToolLike","DynamicTool","StructuredToolInterface","ToolCall","RunnableCallable","MessagesAnnotation","END","Command","ToolNodeOptions","ToolNode","T","Promise","toolsCondition","State"],"sources":["../../src/prebuilt/tool_node.d.ts"],"sourcesContent":["import { BaseMessage, ToolMessage } from \"@langchain/core/messages\";\nimport { RunnableConfig, RunnableToolLike } from \"@langchain/core/runnables\";\nimport { DynamicTool, StructuredToolInterface } from \"@langchain/core/tools\";\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\nimport { RunnableCallable } from \"../utils.js\";\nimport { MessagesAnnotation } from \"../graph/messages_annotation.js\";\nimport { END, Command } from \"../constants.js\";\nexport type ToolNodeOptions = {\n name?: string;\n tags?: string[];\n handleToolErrors?: boolean;\n};\n/**\n * A node that runs the tools requested in the last AIMessage. It can be used\n * either in StateGraph with a \"messages\" key or in MessageGraph. If multiple\n * tool calls are requested, they will be run in parallel. The output will be\n * a list of ToolMessages, one for each tool call.\n *\n * @example\n * ```ts\n * import { ToolNode } from \"@langchain/langgraph/prebuilt\";\n * import { tool } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n * import { AIMessage } from \"@langchain/core/messages\";\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * }),\n * });\n *\n * const tools = [getWeather];\n * const toolNode = new ToolNode(tools);\n *\n * const messageWithSingleToolCall = new AIMessage({\n * content: \"\",\n * tool_calls: [\n * {\n * name: \"get_weather\",\n * args: { location: \"sf\" },\n * id: \"tool_call_id\",\n * type: \"tool_call\",\n * }\n * ]\n * })\n *\n * await toolNode.invoke({ messages: [messageWithSingleToolCall] });\n * // Returns tool invocation responses as:\n * // { messages: ToolMessage[] }\n * ```\n *\n * @example\n * ```ts\n * import {\n * StateGraph,\n * MessagesAnnotation,\n * } from \"@langchain/langgraph\";\n * import { ToolNode } from \"@langchain/langgraph/prebuilt\";\n * import { tool } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * }),\n * });\n *\n * const tools = [getWeather];\n * const modelWithTools = new ChatAnthropic({\n * model: \"claude-3-haiku-20240307\",\n * temperature: 0\n * }).bindTools(tools);\n *\n * const toolNodeForGraph = new ToolNode(tools)\n *\n * const shouldContinue = (state: typeof MessagesAnnotation.State) => {\n * const { messages } = state;\n * const lastMessage = messages[messages.length - 1];\n * if (\"tool_calls\" in lastMessage && Array.isArray(lastMessage.tool_calls) && lastMessage.tool_calls?.length) {\n * return \"tools\";\n * }\n * return \"__end__\";\n * }\n *\n * const callModel = async (state: typeof MessagesAnnotation.State) => {\n * const { messages } = state;\n * const response = await modelWithTools.invoke(messages);\n * return { messages: response };\n * }\n *\n * const graph = new StateGraph(MessagesAnnotation)\n * .addNode(\"agent\", callModel)\n * .addNode(\"tools\", toolNodeForGraph)\n * .addEdge(\"__start__\", \"agent\")\n * .addConditionalEdges(\"agent\", shouldContinue)\n * .addEdge(\"tools\", \"agent\")\n * .compile();\n *\n * const inputs = {\n * messages: [{ role: \"user\", content: \"what is the weather in SF?\" }],\n * };\n *\n * const stream = await graph.stream(inputs, {\n * streamMode: \"values\",\n * });\n *\n * for await (const { messages } of stream) {\n * console.log(messages);\n * }\n * // Returns the messages in the state at each step of execution\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport declare class ToolNode<T = any> extends RunnableCallable<T, T> {\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[];\n handleToolErrors: boolean;\n trace: boolean;\n constructor(tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[], options?: ToolNodeOptions);\n protected runTool(call: ToolCall, config: RunnableConfig): Promise<ToolMessage | Command>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected run(input: unknown, config: RunnableConfig): Promise<T>;\n}\n/**\n * A conditional edge function that determines whether to route to a tools node or end the graph.\n *\n * This function is designed to be used as a conditional edge in a LangGraph state graph to implement\n * the common pattern of checking if an AI message contains tool calls that need to be executed.\n *\n * @param state - The current state of the graph, which can be either:\n * - An array of `BaseMessage` objects, where the last message is checked for tool calls\n * - A state object conforming to `MessagesAnnotation.State`, which contains a `messages` array\n *\n * @returns A string indicating the next node to route to:\n * - `\"tools\"` - If the last message contains tool calls that need to be executed\n * - `END` - If there are no tool calls, indicating the graph should terminate\n *\n * @example\n * ```typescript\n * import { StateGraph, MessagesAnnotation, END, START } from \"@langchain/langgraph\";\n * import { ToolNode, toolsCondition } from \"@langchain/langgraph/prebuilt\";\n *\n * const graph = new StateGraph(MessagesAnnotation)\n * .addNode(\"agent\", agentNode)\n * .addNode(\"tools\", new ToolNode([searchTool, calculatorTool]))\n * .addEdge(START, \"agent\")\n * .addConditionalEdges(\"agent\", toolsCondition, [\"tools\", END])\n * .addEdge(\"tools\", \"agent\")\n * .compile();\n * ```\n *\n * @remarks\n * The function checks the last message in the state for the presence of `tool_calls`.\n * If the message is an `AIMessage` with one or more tool calls, it returns `\"tools\"`,\n * indicating that the graph should route to a tools node (typically a `ToolNode`) to\n * execute those tool calls. Otherwise, it returns `END` to terminate the graph execution.\n *\n * This is a common pattern in agentic workflows where an AI model decides whether to\n * use tools or provide a final response.\n */\nexport declare function toolsCondition(state: BaseMessage[] | typeof MessagesAnnotation.State): \"tools\" | typeof END;\n"],"mappings":";;;;;;;;;KAOYW,eAAAA;;EAAAA,IAAAA,CAAAA,EAAAA,MAAAA,EAAAA;EA2HSC,gBAAQ,CAAA,EAAA,OAAA;CAAA;;;;;;;;;;;;;;;;;;;;AA8C7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA9CqBA,0BAA0BL,iBAAiBM,GAAGA;UACvDR,0BAA0BD,cAAcD;;;sBAG5BE,0BAA0BD,cAAcD,+BAA+BQ;0BACnEL,kBAAkBJ,iBAAiBY,QAAQb,cAAcS;;wCAE3CR,iBAAiBY,QAAQD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuC3CE,cAAAA,QAAsBf,uBAAuBQ,kBAAAA,CAAmBQ,yBAAyBP"}