@langchain/langgraph 1.0.7 → 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 -286
  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 -349
  293. package/dist/pregel/remote.cjs.map +0 -1
  294. package/dist/pregel/remote.d.cts +0 -123
  295. package/dist/pregel/remote.d.cts.map +0 -1
  296. package/dist/pregel/remote.d.ts +0 -123
  297. package/dist/pregel/remote.d.ts.map +0 -1
  298. package/dist/pregel/remote.js +0 -348
  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,342 +0,0 @@
1
- import { Annotation } from "../graph/annotation.js";
2
- import { END, START, Send } from "../constants.js";
3
- import { StateGraph } from "../graph/state.js";
4
- import { messagesStateReducer } from "../graph/message.js";
5
- import "../graph/index.js";
6
- import { ToolNode } from "./tool_node.js";
7
- import { withAgentName } from "./agentName.js";
8
- import { Runnable, RunnableBinding, RunnableLambda, RunnableSequence } from "@langchain/core/runnables";
9
- import { SystemMessage, isAIMessage, isBaseMessage, isToolMessage } from "@langchain/core/messages";
10
-
11
- //#region src/prebuilt/react_agent_executor.ts
12
- function _convertMessageModifierToPrompt(messageModifier) {
13
- if (typeof messageModifier === "string" || isBaseMessage(messageModifier) && messageModifier._getType() === "system") return messageModifier;
14
- if (typeof messageModifier === "function") return async (state) => messageModifier(state.messages);
15
- if (Runnable.isRunnable(messageModifier)) return RunnableLambda.from((state) => state.messages).pipe(messageModifier);
16
- throw new Error(`Unexpected type for messageModifier: ${typeof messageModifier}`);
17
- }
18
- const PROMPT_RUNNABLE_NAME = "prompt";
19
- function _getPromptRunnable(prompt) {
20
- let promptRunnable;
21
- if (prompt == null) promptRunnable = RunnableLambda.from((state) => state.messages).withConfig({ runName: PROMPT_RUNNABLE_NAME });
22
- else if (typeof prompt === "string") {
23
- const systemMessage = new SystemMessage(prompt);
24
- promptRunnable = RunnableLambda.from((state) => {
25
- return [systemMessage, ...state.messages ?? []];
26
- }).withConfig({ runName: PROMPT_RUNNABLE_NAME });
27
- } else if (isBaseMessage(prompt) && prompt._getType() === "system") promptRunnable = RunnableLambda.from((state) => [prompt, ...state.messages]).withConfig({ runName: PROMPT_RUNNABLE_NAME });
28
- else if (typeof prompt === "function") promptRunnable = RunnableLambda.from(prompt).withConfig({ runName: PROMPT_RUNNABLE_NAME });
29
- else if (Runnable.isRunnable(prompt)) promptRunnable = prompt;
30
- else throw new Error(`Got unexpected type for 'prompt': ${typeof prompt}`);
31
- return promptRunnable;
32
- }
33
- function isClientTool(tool) {
34
- return Runnable.isRunnable(tool);
35
- }
36
- function _getPrompt(prompt, stateModifier, messageModifier) {
37
- const definedCount = [
38
- prompt,
39
- stateModifier,
40
- messageModifier
41
- ].filter((x) => x != null).length;
42
- if (definedCount > 1) throw new Error("Expected only one of prompt, stateModifier, or messageModifier, got multiple values");
43
- let finalPrompt = prompt;
44
- if (stateModifier != null) finalPrompt = stateModifier;
45
- else if (messageModifier != null) finalPrompt = _convertMessageModifierToPrompt(messageModifier);
46
- return _getPromptRunnable(finalPrompt);
47
- }
48
- function _isBaseChatModel(model) {
49
- return "invoke" in model && typeof model.invoke === "function" && "_modelType" in model;
50
- }
51
- function _isConfigurableModel(model) {
52
- return "_queuedMethodOperations" in model && "_model" in model && typeof model._model === "function";
53
- }
54
- function _isChatModelWithBindTools(llm) {
55
- if (!_isBaseChatModel(llm)) return false;
56
- return "bindTools" in llm && typeof llm.bindTools === "function";
57
- }
58
- async function _shouldBindTools(llm, tools) {
59
- let model = llm;
60
- if (RunnableSequence.isRunnableSequence(model)) model = model.steps.find((step) => RunnableBinding.isRunnableBinding(step) || _isBaseChatModel(step) || _isConfigurableModel(step)) || model;
61
- if (_isConfigurableModel(model)) model = await model._model();
62
- if (!RunnableBinding.isRunnableBinding(model)) return true;
63
- let boundTools = (() => {
64
- if (model.kwargs != null && typeof model.kwargs === "object" && "tools" in model.kwargs && Array.isArray(model.kwargs.tools)) return model.kwargs.tools ?? null;
65
- if (model.config != null && typeof model.config === "object" && "tools" in model.config && Array.isArray(model.config.tools)) return model.config.tools ?? null;
66
- return null;
67
- })();
68
- if (boundTools != null && boundTools.length === 1 && "functionDeclarations" in boundTools[0]) boundTools = boundTools[0].functionDeclarations;
69
- if (boundTools == null) return true;
70
- if (tools.length !== boundTools.length) throw new Error("Number of tools in the model.bindTools() and tools passed to createReactAgent must match");
71
- const toolNames = new Set(tools.flatMap((tool) => isClientTool(tool) ? tool.name : []));
72
- const boundToolNames = /* @__PURE__ */ new Set();
73
- for (const boundTool of boundTools) {
74
- let boundToolName;
75
- if ("type" in boundTool && boundTool.type === "function") boundToolName = boundTool.function.name;
76
- else if ("name" in boundTool) boundToolName = boundTool.name;
77
- else if ("toolSpec" in boundTool && "name" in boundTool.toolSpec) boundToolName = boundTool.toolSpec.name;
78
- else continue;
79
- if (boundToolName) boundToolNames.add(boundToolName);
80
- }
81
- const missingTools = [...toolNames].filter((x) => !boundToolNames.has(x));
82
- if (missingTools.length > 0) throw new Error(`Missing tools '${missingTools}' in the model.bindTools().Tools in the model.bindTools() must match the tools passed to createReactAgent.`);
83
- return false;
84
- }
85
- const _simpleBindTools = (llm, toolClasses) => {
86
- if (_isChatModelWithBindTools(llm)) return llm.bindTools(toolClasses);
87
- if (RunnableBinding.isRunnableBinding(llm) && _isChatModelWithBindTools(llm.bound)) {
88
- const newBound = llm.bound.bindTools(toolClasses);
89
- if (RunnableBinding.isRunnableBinding(newBound)) return new RunnableBinding({
90
- bound: newBound.bound,
91
- config: {
92
- ...llm.config,
93
- ...newBound.config
94
- },
95
- kwargs: {
96
- ...llm.kwargs,
97
- ...newBound.kwargs
98
- },
99
- configFactories: newBound.configFactories ?? llm.configFactories
100
- });
101
- return new RunnableBinding({
102
- bound: newBound,
103
- config: llm.config,
104
- kwargs: llm.kwargs,
105
- configFactories: llm.configFactories
106
- });
107
- }
108
- return null;
109
- };
110
- async function _bindTools(llm, toolClasses) {
111
- const model = _simpleBindTools(llm, toolClasses);
112
- if (model) return model;
113
- if (_isConfigurableModel(llm)) {
114
- const model$1 = _simpleBindTools(await llm._model(), toolClasses);
115
- if (model$1) return model$1;
116
- }
117
- if (RunnableSequence.isRunnableSequence(llm)) {
118
- const modelStep = llm.steps.findIndex((step) => RunnableBinding.isRunnableBinding(step) || _isBaseChatModel(step) || _isConfigurableModel(step));
119
- if (modelStep >= 0) {
120
- const model$1 = _simpleBindTools(llm.steps[modelStep], toolClasses);
121
- if (model$1) {
122
- const nextSteps = llm.steps.slice();
123
- nextSteps.splice(modelStep, 1, model$1);
124
- return RunnableSequence.from(nextSteps);
125
- }
126
- }
127
- }
128
- throw new Error(`llm ${llm} must define bindTools method.`);
129
- }
130
- async function _getModel(llm) {
131
- let model = llm;
132
- if (RunnableSequence.isRunnableSequence(model)) model = model.steps.find((step) => RunnableBinding.isRunnableBinding(step) || _isBaseChatModel(step) || _isConfigurableModel(step)) || model;
133
- if (_isConfigurableModel(model)) model = await model._model();
134
- if (RunnableBinding.isRunnableBinding(model)) model = model.bound;
135
- if (!_isBaseChatModel(model)) throw new Error(`Expected \`llm\` to be a ChatModel or RunnableBinding (e.g. llm.bind_tools(...)) with invoke() and generate() methods, got ${model.constructor.name}`);
136
- return model;
137
- }
138
- const createReactAgentAnnotation = () => Annotation.Root({
139
- messages: Annotation({
140
- reducer: messagesStateReducer,
141
- default: () => []
142
- }),
143
- structuredResponse: Annotation
144
- });
145
- const PreHookAnnotation = Annotation.Root({ llmInputMessages: Annotation({
146
- reducer: (_, update) => messagesStateReducer([], update),
147
- default: () => []
148
- }) });
149
- /**
150
- * @deprecated `createReactAgent` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.
151
- * Update your import to `import { createAgent } from "langchain";`
152
- *
153
- * Creates a StateGraph agent that relies on a chat model utilizing tool calling.
154
- *
155
- * @example
156
- * ```ts
157
- * import { ChatOpenAI } from "@langchain/openai";
158
- * import { tool } from "@langchain/core/tools";
159
- * import { z } from "zod";
160
- * import { createReactAgent } from "@langchain/langgraph/prebuilt";
161
- *
162
- * const model = new ChatOpenAI({
163
- * model: "gpt-4o",
164
- * });
165
- *
166
- * const getWeather = tool((input) => {
167
- * if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
168
- * return "It's 60 degrees and foggy.";
169
- * } else {
170
- * return "It's 90 degrees and sunny.";
171
- * }
172
- * }, {
173
- * name: "get_weather",
174
- * description: "Call to get the current weather.",
175
- * schema: z.object({
176
- * location: z.string().describe("Location to get the weather for."),
177
- * })
178
- * })
179
- *
180
- * const agent = createReactAgent({ llm: model, tools: [getWeather] });
181
- *
182
- * const inputs = {
183
- * messages: [{ role: "user", content: "what is the weather in SF?" }],
184
- * };
185
- *
186
- * const stream = await agent.stream(inputs, { streamMode: "values" });
187
- *
188
- * for await (const { messages } of stream) {
189
- * console.log(messages);
190
- * }
191
- * // Returns the messages in the state at each step of execution
192
- * ```
193
- */
194
- function createReactAgent(params) {
195
- const { llm, tools, messageModifier, stateModifier, prompt, stateSchema, contextSchema, checkpointSaver, checkpointer, interruptBefore, interruptAfter, store, responseFormat, preModelHook, postModelHook, name, description, version = "v1", includeAgentName } = params;
196
- let toolClasses;
197
- let toolNode;
198
- if (!Array.isArray(tools)) {
199
- toolClasses = tools.tools;
200
- toolNode = tools;
201
- } else {
202
- toolClasses = tools;
203
- toolNode = new ToolNode(toolClasses.filter(isClientTool));
204
- }
205
- let cachedStaticModel = null;
206
- const _getStaticModel = async (llm$1) => {
207
- if (cachedStaticModel) return cachedStaticModel;
208
- let modelWithTools;
209
- if (await _shouldBindTools(llm$1, toolClasses)) modelWithTools = await _bindTools(llm$1, toolClasses);
210
- else modelWithTools = llm$1;
211
- const promptRunnable = _getPrompt(prompt, stateModifier, messageModifier);
212
- const modelRunnable = includeAgentName === "inline" ? withAgentName(modelWithTools, includeAgentName) : modelWithTools;
213
- cachedStaticModel = promptRunnable.pipe(modelRunnable);
214
- return cachedStaticModel;
215
- };
216
- const _getDynamicModel = async (llm$1, state, config) => {
217
- const model = await llm$1(state, config);
218
- return _getPrompt(prompt, stateModifier, messageModifier).pipe(includeAgentName === "inline" ? withAgentName(model, includeAgentName) : model);
219
- };
220
- const shouldReturnDirect = new Set(toolClasses.filter(isClientTool).filter((tool) => "returnDirect" in tool && tool.returnDirect).map((tool) => tool.name));
221
- function getModelInputState(state) {
222
- const { messages, llmInputMessages,...rest } = state;
223
- if (llmInputMessages != null && llmInputMessages.length > 0) return {
224
- messages: llmInputMessages,
225
- ...rest
226
- };
227
- return {
228
- messages,
229
- ...rest
230
- };
231
- }
232
- const generateStructuredResponse = async (state, config) => {
233
- if (responseFormat == null) throw new Error("Attempted to generate structured output with no passed response schema. Please contact us for help.");
234
- const messages = [...state.messages];
235
- let modelWithStructuredOutput;
236
- const model = typeof llm === "function" ? await llm(state, config) : await _getModel(llm);
237
- if (!_isBaseChatModel(model)) throw new Error(`Expected \`llm\` to be a ChatModel with .withStructuredOutput() method, got ${model.constructor.name}`);
238
- if (typeof responseFormat === "object" && "schema" in responseFormat) {
239
- const { prompt: prompt$1, schema: schema$1,...options } = responseFormat;
240
- modelWithStructuredOutput = model.withStructuredOutput(schema$1, options);
241
- if (prompt$1 != null) messages.unshift(new SystemMessage({ content: prompt$1 }));
242
- } else modelWithStructuredOutput = model.withStructuredOutput(responseFormat);
243
- const response = await modelWithStructuredOutput.invoke(messages, config);
244
- return { structuredResponse: response };
245
- };
246
- const callModel = async (state, config) => {
247
- const modelRunnable = typeof llm === "function" ? await _getDynamicModel(llm, state, config) : await _getStaticModel(llm);
248
- const response = await modelRunnable.invoke(getModelInputState(state), config);
249
- response.name = name;
250
- response.lc_kwargs.name = name;
251
- return { messages: [response] };
252
- };
253
- const schema = stateSchema ?? createReactAgentAnnotation();
254
- const workflow = new StateGraph(schema, contextSchema).addNode("tools", toolNode);
255
- if (!("messages" in workflow._schemaDefinition)) throw new Error("Missing required `messages` key in state schema.");
256
- const allNodeWorkflows = workflow;
257
- const conditionalMap = (map) => {
258
- return Object.fromEntries(Object.entries(map).filter(([_, v]) => v != null));
259
- };
260
- let entrypoint = "agent";
261
- let inputSchema;
262
- if (preModelHook != null) {
263
- allNodeWorkflows.addNode("pre_model_hook", preModelHook).addEdge("pre_model_hook", "agent");
264
- entrypoint = "pre_model_hook";
265
- inputSchema = Annotation.Root({
266
- ...workflow._schemaDefinition,
267
- ...PreHookAnnotation.spec
268
- });
269
- } else entrypoint = "agent";
270
- allNodeWorkflows.addNode("agent", callModel, { input: inputSchema }).addEdge(START, entrypoint);
271
- if (postModelHook != null) allNodeWorkflows.addNode("post_model_hook", postModelHook).addEdge("agent", "post_model_hook").addConditionalEdges("post_model_hook", (state) => {
272
- const { messages } = state;
273
- const toolMessageIds = new Set(messages.filter(isToolMessage).map((msg) => msg.tool_call_id));
274
- let lastAiMessage;
275
- for (let i = messages.length - 1; i >= 0; i -= 1) {
276
- const message = messages[i];
277
- if (isAIMessage(message)) {
278
- lastAiMessage = message;
279
- break;
280
- }
281
- }
282
- const pendingToolCalls = lastAiMessage?.tool_calls?.filter((i) => i.id == null || !toolMessageIds.has(i.id)) ?? [];
283
- const lastMessage = messages.at(-1);
284
- if (pendingToolCalls.length > 0) {
285
- if (version === "v2") return pendingToolCalls.map((toolCall) => new Send("tools", {
286
- ...state,
287
- lg_tool_call: toolCall
288
- }));
289
- return "tools";
290
- }
291
- if (lastMessage && isToolMessage(lastMessage)) return entrypoint;
292
- if (responseFormat != null) return "generate_structured_response";
293
- return END;
294
- }, conditionalMap({
295
- tools: "tools",
296
- [entrypoint]: entrypoint,
297
- generate_structured_response: responseFormat != null ? "generate_structured_response" : null,
298
- [END]: responseFormat != null ? null : END
299
- }));
300
- if (responseFormat !== void 0) workflow.addNode("generate_structured_response", generateStructuredResponse).addEdge("generate_structured_response", END);
301
- if (postModelHook == null) allNodeWorkflows.addConditionalEdges("agent", (state) => {
302
- const { messages } = state;
303
- const lastMessage = messages[messages.length - 1];
304
- if (!isAIMessage(lastMessage) || !lastMessage.tool_calls?.length) {
305
- if (responseFormat != null) return "generate_structured_response";
306
- return END;
307
- }
308
- if (version === "v2") return lastMessage.tool_calls.map((toolCall) => new Send("tools", {
309
- ...state,
310
- lg_tool_call: toolCall
311
- }));
312
- return "tools";
313
- }, conditionalMap({
314
- tools: "tools",
315
- generate_structured_response: responseFormat != null ? "generate_structured_response" : null,
316
- [END]: responseFormat != null ? null : END
317
- }));
318
- if (shouldReturnDirect.size > 0) allNodeWorkflows.addConditionalEdges("tools", (state) => {
319
- for (let i = state.messages.length - 1; i >= 0; i -= 1) {
320
- const message = state.messages[i];
321
- if (!isToolMessage(message)) break;
322
- if (message.name !== void 0 && shouldReturnDirect.has(message.name)) return END;
323
- }
324
- return entrypoint;
325
- }, conditionalMap({
326
- [entrypoint]: entrypoint,
327
- [END]: END
328
- }));
329
- else allNodeWorkflows.addEdge("tools", entrypoint);
330
- return allNodeWorkflows.compile({
331
- checkpointer: checkpointer ?? checkpointSaver,
332
- interruptBefore,
333
- interruptAfter,
334
- store,
335
- name,
336
- description
337
- });
338
- }
339
-
340
- //#endregion
341
- export { createReactAgent, createReactAgentAnnotation };
342
- //# sourceMappingURL=react_agent_executor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"react_agent_executor.js","names":["promptRunnable: Runnable","boundToolName: string | undefined","model","nextSteps: unknown[]","toolClasses: (ClientTool | ServerTool)[]","toolNode: ToolNode","cachedStaticModel: Runnable | null","modelWithTools: LanguageModelLike","llm","model: LanguageModelLike","schema","prompt","modelRunnable: Runnable","entrypoint: \"agent\" | \"pre_model_hook\"","inputSchema: AnnotationRoot<ToAnnotationRoot<A>[\"spec\"]> | undefined","toolMessageIds: Set<string>","lastAiMessage: AIMessage | undefined"],"sources":["../../src/prebuilt/react_agent_executor.ts"],"sourcesContent":["import {\n BaseChatModel,\n BindToolsInput,\n} from \"@langchain/core/language_models/chat_models\";\nimport { LanguageModelLike } from \"@langchain/core/language_models/base\";\nimport {\n BaseMessage,\n BaseMessageLike,\n isAIMessage,\n isBaseMessage,\n isToolMessage,\n SystemMessage,\n type AIMessage,\n} from \"@langchain/core/messages\";\nimport {\n Runnable,\n RunnableLambda,\n RunnableToolLike,\n RunnableSequence,\n RunnableBinding,\n type RunnableLike,\n} from \"@langchain/core/runnables\";\nimport { DynamicTool, StructuredToolInterface } from \"@langchain/core/tools\";\nimport type {\n InteropZodObject,\n InteropZodType,\n} from \"@langchain/core/utils/types\";\nimport {\n All,\n BaseCheckpointSaver,\n BaseStore,\n} from \"@langchain/langgraph-checkpoint\";\n\nimport {\n StateGraph,\n type CompiledStateGraph,\n AnnotationRoot,\n} from \"../graph/index.js\";\nimport { MessagesAnnotation } from \"../graph/messages_annotation.js\";\nimport { ToolNode } from \"./tool_node.js\";\nimport { LangGraphRunnableConfig, Runtime } from \"../pregel/runnable_types.js\";\nimport { Annotation } from \"../graph/annotation.js\";\nimport { Messages, messagesStateReducer } from \"../graph/message.js\";\nimport { END, Send, START } from \"../constants.js\";\nimport { withAgentName } from \"./agentName.js\";\nimport type { InteropZodToStateDefinition } from \"../graph/zod/meta.js\";\n\n/**\n * @deprecated `AgentState` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.\n * Update your import to `import { AgentState } from \"langchain\";`\n */\nexport interface AgentState<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n StructuredResponseType extends Record<string, any> = Record<string, any>\n> {\n messages: BaseMessage[];\n // TODO: This won't be set until we\n // implement managed values in LangGraphJS\n // Will be useful for inserting a message on\n // graph recursion end\n // is_last_step: boolean;\n structuredResponse: StructuredResponseType;\n}\n\nexport type N = typeof START | \"agent\" | \"tools\";\n\ntype StructuredResponseSchemaOptions<StructuredResponseType> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: InteropZodType<StructuredResponseType> | Record<string, any>;\n prompt?: string;\n\n strict?: boolean;\n [key: string]: unknown;\n};\n\nfunction _convertMessageModifierToPrompt(\n messageModifier: MessageModifier\n): Prompt {\n // Handle string or SystemMessage\n if (\n typeof messageModifier === \"string\" ||\n (isBaseMessage(messageModifier) && messageModifier._getType() === \"system\")\n ) {\n return messageModifier;\n }\n\n // Handle callable function\n if (typeof messageModifier === \"function\") {\n return async (state: typeof MessagesAnnotation.State) =>\n messageModifier(state.messages);\n }\n\n // Handle Runnable\n if (Runnable.isRunnable(messageModifier)) {\n return RunnableLambda.from(\n (state: typeof MessagesAnnotation.State) => state.messages\n ).pipe(messageModifier);\n }\n\n throw new Error(\n `Unexpected type for messageModifier: ${typeof messageModifier}`\n );\n}\n\nconst PROMPT_RUNNABLE_NAME = \"prompt\";\n\nfunction _getPromptRunnable(prompt?: Prompt): Runnable {\n let promptRunnable: Runnable;\n\n if (prompt == null) {\n promptRunnable = RunnableLambda.from(\n (state: typeof MessagesAnnotation.State) => state.messages\n ).withConfig({ runName: PROMPT_RUNNABLE_NAME });\n } else if (typeof prompt === \"string\") {\n const systemMessage = new SystemMessage(prompt);\n promptRunnable = RunnableLambda.from(\n (state: typeof MessagesAnnotation.State) => {\n return [systemMessage, ...(state.messages ?? [])];\n }\n ).withConfig({ runName: PROMPT_RUNNABLE_NAME });\n } else if (isBaseMessage(prompt) && prompt._getType() === \"system\") {\n promptRunnable = RunnableLambda.from(\n (state: typeof MessagesAnnotation.State) => [prompt, ...state.messages]\n ).withConfig({ runName: PROMPT_RUNNABLE_NAME });\n } else if (typeof prompt === \"function\") {\n promptRunnable = RunnableLambda.from(prompt).withConfig({\n runName: PROMPT_RUNNABLE_NAME,\n });\n } else if (Runnable.isRunnable(prompt)) {\n promptRunnable = prompt;\n } else {\n throw new Error(`Got unexpected type for 'prompt': ${typeof prompt}`);\n }\n\n return promptRunnable;\n}\n\ntype ServerTool = Record<string, unknown>;\ntype ClientTool = StructuredToolInterface | DynamicTool | RunnableToolLike;\n\nfunction isClientTool(tool: ClientTool | ServerTool): tool is ClientTool {\n return Runnable.isRunnable(tool);\n}\n\nfunction _getPrompt(\n prompt?: Prompt,\n stateModifier?: CreateReactAgentParams[\"stateModifier\"],\n messageModifier?: CreateReactAgentParams[\"messageModifier\"]\n): Runnable {\n // Check if multiple modifiers exist\n const definedCount = [prompt, stateModifier, messageModifier].filter(\n (x) => x != null\n ).length;\n if (definedCount > 1) {\n throw new Error(\n \"Expected only one of prompt, stateModifier, or messageModifier, got multiple values\"\n );\n }\n\n let finalPrompt = prompt;\n if (stateModifier != null) {\n finalPrompt = stateModifier;\n } else if (messageModifier != null) {\n finalPrompt = _convertMessageModifierToPrompt(messageModifier);\n }\n\n return _getPromptRunnable(finalPrompt);\n}\n\nfunction _isBaseChatModel(model: LanguageModelLike): model is BaseChatModel {\n return (\n \"invoke\" in model &&\n typeof model.invoke === \"function\" &&\n \"_modelType\" in model\n );\n}\n\ninterface ConfigurableModelInterface {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _queuedMethodOperations: Record<string, any>;\n _model: () => Promise<BaseChatModel>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction _isConfigurableModel(model: any): model is ConfigurableModelInterface {\n return (\n \"_queuedMethodOperations\" in model &&\n \"_model\" in model &&\n typeof model._model === \"function\"\n );\n}\n\nfunction _isChatModelWithBindTools(\n llm: LanguageModelLike\n): llm is BaseChatModel & Required<Pick<BaseChatModel, \"bindTools\">> {\n if (!_isBaseChatModel(llm)) return false;\n return \"bindTools\" in llm && typeof llm.bindTools === \"function\";\n}\n\nexport async function _shouldBindTools(\n llm: LanguageModelLike,\n tools: (ClientTool | ServerTool)[]\n): Promise<boolean> {\n // If model is a RunnableSequence, find a RunnableBinding or BaseChatModel in its steps\n let model = llm;\n if (RunnableSequence.isRunnableSequence(model)) {\n model =\n model.steps.find(\n (step) =>\n RunnableBinding.isRunnableBinding(step) ||\n _isBaseChatModel(step) ||\n _isConfigurableModel(step)\n ) || model;\n }\n\n if (_isConfigurableModel(model)) {\n model = await model._model();\n }\n\n // If not a RunnableBinding, we should bind tools\n if (!RunnableBinding.isRunnableBinding(model)) {\n return true;\n }\n\n let boundTools = (() => {\n // check if model.kwargs contain the tools key\n if (\n model.kwargs != null &&\n typeof model.kwargs === \"object\" &&\n \"tools\" in model.kwargs &&\n Array.isArray(model.kwargs.tools)\n ) {\n return (model.kwargs.tools ?? null) as BindToolsInput[] | null;\n }\n\n // Some models can bind the tools via `withConfig()` instead of `bind()`\n if (\n model.config != null &&\n typeof model.config === \"object\" &&\n \"tools\" in model.config &&\n Array.isArray(model.config.tools)\n ) {\n return (model.config.tools ?? null) as BindToolsInput[] | null;\n }\n\n return null;\n })();\n\n // google-style\n if (\n boundTools != null &&\n boundTools.length === 1 &&\n \"functionDeclarations\" in boundTools[0]\n ) {\n boundTools = boundTools[0].functionDeclarations;\n }\n\n // If no tools in kwargs, we should bind tools\n if (boundTools == null) return true;\n\n // Check if tools count matches\n if (tools.length !== boundTools.length) {\n throw new Error(\n \"Number of tools in the model.bindTools() and tools passed to createReactAgent must match\"\n );\n }\n\n const toolNames = new Set<string>(\n tools.flatMap((tool) => (isClientTool(tool) ? tool.name : []))\n );\n\n const boundToolNames = new Set<string>();\n\n for (const boundTool of boundTools) {\n let boundToolName: string | undefined;\n\n // OpenAI-style tool\n if (\"type\" in boundTool && boundTool.type === \"function\") {\n boundToolName = boundTool.function.name;\n }\n // Anthropic or Google-style tool\n else if (\"name\" in boundTool) {\n boundToolName = boundTool.name;\n }\n // Bedrock-style tool\n else if (\"toolSpec\" in boundTool && \"name\" in boundTool.toolSpec) {\n boundToolName = boundTool.toolSpec.name;\n }\n // unknown tool type so we'll ignore it\n else {\n continue;\n }\n\n if (boundToolName) {\n boundToolNames.add(boundToolName);\n }\n }\n\n const missingTools = [...toolNames].filter((x) => !boundToolNames.has(x));\n if (missingTools.length > 0) {\n throw new Error(\n `Missing tools '${missingTools}' in the model.bindTools().` +\n `Tools in the model.bindTools() must match the tools passed to createReactAgent.`\n );\n }\n\n return false;\n}\n\nconst _simpleBindTools = (\n llm: LanguageModelLike,\n toolClasses: (ClientTool | ServerTool)[]\n) => {\n if (_isChatModelWithBindTools(llm)) {\n return llm.bindTools(toolClasses);\n }\n\n if (\n RunnableBinding.isRunnableBinding(llm) &&\n _isChatModelWithBindTools(llm.bound)\n ) {\n const newBound = llm.bound.bindTools(toolClasses);\n\n if (RunnableBinding.isRunnableBinding(newBound)) {\n return new RunnableBinding({\n bound: newBound.bound,\n config: { ...llm.config, ...newBound.config },\n kwargs: { ...llm.kwargs, ...newBound.kwargs },\n configFactories: newBound.configFactories ?? llm.configFactories,\n });\n }\n\n return new RunnableBinding({\n bound: newBound,\n config: llm.config,\n kwargs: llm.kwargs,\n configFactories: llm.configFactories,\n });\n }\n\n return null;\n};\n\nexport async function _bindTools(\n llm: LanguageModelLike,\n toolClasses: (ClientTool | ServerTool)[]\n) {\n const model = _simpleBindTools(llm, toolClasses);\n if (model) return model;\n\n if (_isConfigurableModel(llm)) {\n const model = _simpleBindTools(await llm._model(), toolClasses);\n if (model) return model;\n }\n\n if (RunnableSequence.isRunnableSequence(llm)) {\n const modelStep = llm.steps.findIndex(\n (step) =>\n RunnableBinding.isRunnableBinding(step) ||\n _isBaseChatModel(step) ||\n _isConfigurableModel(step)\n );\n\n if (modelStep >= 0) {\n const model = _simpleBindTools(llm.steps[modelStep], toolClasses);\n if (model) {\n const nextSteps: unknown[] = llm.steps.slice();\n nextSteps.splice(modelStep, 1, model);\n\n return RunnableSequence.from(\n nextSteps as [RunnableLike, ...RunnableLike[], RunnableLike]\n );\n }\n }\n }\n\n throw new Error(`llm ${llm} must define bindTools method.`);\n}\n\nexport async function _getModel(\n llm: LanguageModelLike | ConfigurableModelInterface\n): Promise<LanguageModelLike> {\n // If model is a RunnableSequence, find a RunnableBinding or BaseChatModel in its steps\n let model = llm;\n if (RunnableSequence.isRunnableSequence(model)) {\n model =\n model.steps.find(\n (step) =>\n RunnableBinding.isRunnableBinding(step) ||\n _isBaseChatModel(step) ||\n _isConfigurableModel(step)\n ) || model;\n }\n\n if (_isConfigurableModel(model)) {\n model = await model._model();\n }\n\n // Get the underlying model from a RunnableBinding\n if (RunnableBinding.isRunnableBinding(model)) {\n model = model.bound;\n }\n\n if (!_isBaseChatModel(model)) {\n throw new Error(\n `Expected \\`llm\\` to be a ChatModel or RunnableBinding (e.g. llm.bind_tools(...)) with invoke() and generate() methods, got ${model.constructor.name}`\n );\n }\n\n return model;\n}\n\nexport type Prompt =\n | SystemMessage\n | string\n | ((\n state: typeof MessagesAnnotation.State,\n config: LangGraphRunnableConfig\n ) => BaseMessageLike[])\n | ((\n state: typeof MessagesAnnotation.State,\n config: LangGraphRunnableConfig\n ) => Promise<BaseMessageLike[]>)\n | Runnable;\n\n/** @deprecated Use Prompt instead. */\nexport type StateModifier = Prompt;\n\n/** @deprecated Use Prompt instead. */\nexport type MessageModifier =\n | SystemMessage\n | string\n | ((messages: BaseMessage[]) => BaseMessage[])\n | ((messages: BaseMessage[]) => Promise<BaseMessage[]>)\n | Runnable;\n\nexport const createReactAgentAnnotation = <\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>\n>() =>\n Annotation.Root({\n messages: Annotation<BaseMessage[], Messages>({\n reducer: messagesStateReducer,\n default: () => [],\n }),\n structuredResponse: Annotation<T>,\n });\n\ntype WithStateGraphNodes<K extends string, Graph> = Graph extends StateGraph<\n infer SD,\n infer S,\n infer U,\n infer N,\n infer I,\n infer O,\n infer C\n>\n ? StateGraph<SD, S, U, N | K, I, O, C>\n : never;\n\nconst PreHookAnnotation = Annotation.Root({\n llmInputMessages: Annotation<BaseMessage[], Messages>({\n reducer: (_, update) => messagesStateReducer([], update),\n default: () => [],\n }),\n});\n\ntype PreHookAnnotation = typeof PreHookAnnotation;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyAnnotationRoot = AnnotationRoot<any>;\n\ntype ToAnnotationRoot<A extends AnyAnnotationRoot | InteropZodObject> =\n A extends AnyAnnotationRoot\n ? A\n : A extends InteropZodObject\n ? AnnotationRoot<InteropZodToStateDefinition<A>>\n : never;\n\n/**\n * @deprecated `CreateReactAgentParams` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.\n * Update your import to `import { CreateAgentParams } from \"langchain\";`\n */\nexport type CreateReactAgentParams<\n A extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n StructuredResponseType extends Record<string, any> = Record<string, any>,\n C extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n> = {\n /** The chat model that can utilize OpenAI-style tool calling. */\n llm:\n | LanguageModelLike\n | ((\n state: ToAnnotationRoot<A>[\"State\"] & PreHookAnnotation[\"State\"],\n runtime: Runtime<ToAnnotationRoot<C>[\"State\"]>\n ) => Promise<LanguageModelLike> | LanguageModelLike);\n\n /** A list of tools or a ToolNode. */\n tools: ToolNode | (ServerTool | ClientTool)[];\n\n /**\n * @deprecated Use prompt instead.\n */\n messageModifier?: MessageModifier;\n\n /**\n * @deprecated Use prompt instead.\n */\n stateModifier?: StateModifier;\n\n /**\n * An optional prompt for the LLM. This takes full graph state BEFORE the LLM is called and prepares the input to LLM.\n *\n * Can take a few different forms:\n *\n * - str: This is converted to a SystemMessage and added to the beginning of the list of messages in state[\"messages\"].\n * - SystemMessage: this is added to the beginning of the list of messages in state[\"messages\"].\n * - Function: This function should take in full graph state and the output is then passed to the language model.\n * - Runnable: This runnable should take in full graph state and the output is then passed to the language model.\n *\n * Note:\n * Prior to `v0.2.46`, the prompt was set using `stateModifier` / `messagesModifier` parameters.\n * This is now deprecated and will be removed in a future release.\n */\n prompt?: Prompt;\n\n /**\n * Additional state schema for the agent.\n */\n stateSchema?: A;\n\n /**\n * An optional schema for the context.\n */\n contextSchema?: C;\n /** An optional checkpoint saver to persist the agent's state. */\n checkpointSaver?: BaseCheckpointSaver | boolean;\n /** An optional checkpoint saver to persist the agent's state. Alias of \"checkpointSaver\". */\n checkpointer?: BaseCheckpointSaver | boolean;\n /** An optional list of node names to interrupt before running. */\n interruptBefore?: N[] | All;\n /** An optional list of node names to interrupt after running. */\n interruptAfter?: N[] | All;\n store?: BaseStore;\n /**\n * An optional schema for the final agent output.\n *\n * If provided, output will be formatted to match the given schema and returned in the 'structuredResponse' state key.\n * If not provided, `structuredResponse` will not be present in the output state.\n *\n * Can be passed in as:\n * - Zod schema\n * - JSON schema\n * - { prompt, schema }, where schema is one of the above.\n * The prompt will be used together with the model that is being used to generate the structured response.\n *\n * @remarks\n * **Important**: `responseFormat` requires the model to support `.withStructuredOutput()`.\n *\n * **Note**: The graph will make a separate call to the LLM to generate the structured response after the agent loop is finished.\n * This is not the only strategy to get structured responses, see more options in [this guide](https://langchain-ai.github.io/langgraph/how-tos/react-agent-structured-output/).\n */\n responseFormat?:\n | InteropZodType<StructuredResponseType>\n | StructuredResponseSchemaOptions<StructuredResponseType>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>;\n\n /**\n * An optional name for the agent.\n */\n name?: string;\n\n /**\n * An optional description for the agent.\n * This can be used to describe the agent to the underlying supervisor LLM.\n */\n description?: string | undefined;\n\n /**\n * Use to specify how to expose the agent name to the underlying supervisor LLM.\n\n - undefined: Relies on the LLM provider {@link AIMessage#name}. Currently, only OpenAI supports this.\n - `\"inline\"`: Add the agent name directly into the content field of the {@link AIMessage} using XML-style tags.\n Example: `\"How can I help you\"` -> `\"<name>agent_name</name><content>How can I help you?</content>\"`\n */\n includeAgentName?: \"inline\" | undefined;\n\n /**\n * An optional node to add before the `agent` node (i.e., the node that calls the LLM).\n * Useful for managing long message histories (e.g., message trimming, summarization, etc.).\n */\n preModelHook?: RunnableLike<\n ToAnnotationRoot<A>[\"State\"] & PreHookAnnotation[\"State\"],\n ToAnnotationRoot<A>[\"Update\"] & PreHookAnnotation[\"Update\"],\n LangGraphRunnableConfig\n >;\n\n /**\n * An optional node to add after the `agent` node (i.e., the node that calls the LLM).\n * Useful for implementing human-in-the-loop, guardrails, validation, or other post-processing.\n */\n postModelHook?: RunnableLike<\n ToAnnotationRoot<A>[\"State\"],\n ToAnnotationRoot<A>[\"Update\"],\n LangGraphRunnableConfig\n >;\n\n /**\n * Determines the version of the graph to create.\n *\n * Can be one of\n * - `\"v1\"`: The tool node processes a single message. All tool calls in the message are\n * executed in parallel within the tool node.\n * - `\"v2\"`: The tool node processes a single tool call. Tool calls are distributed across\n * multiple instances of the tool node using the Send API.\n *\n * @default `\"v1\"`\n */\n version?: \"v1\" | \"v2\";\n};\n\n/**\n * @deprecated `createReactAgent` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.\n * Update your import to `import { createAgent } from \"langchain\";`\n *\n * Creates a StateGraph agent that relies on a chat model utilizing tool calling.\n *\n * @example\n * ```ts\n * import { ChatOpenAI } from \"@langchain/openai\";\n * import { tool } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n * import { createReactAgent } from \"@langchain/langgraph/prebuilt\";\n *\n * const model = new ChatOpenAI({\n * model: \"gpt-4o\",\n * });\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 agent = createReactAgent({ llm: model, tools: [getWeather] });\n *\n * const inputs = {\n * messages: [{ role: \"user\", content: \"what is the weather in SF?\" }],\n * };\n *\n * const stream = await agent.stream(inputs, { streamMode: \"values\" });\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 */\nexport function createReactAgent<\n A extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n C extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateReactAgentParams<A, StructuredResponseFormat, C>\n): CompiledStateGraph<\n ToAnnotationRoot<A>[\"State\"],\n ToAnnotationRoot<A>[\"Update\"],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any,\n typeof MessagesAnnotation.spec & ToAnnotationRoot<A>[\"spec\"],\n ReturnType<\n typeof createReactAgentAnnotation<StructuredResponseFormat>\n >[\"spec\"] &\n ToAnnotationRoot<A>[\"spec\"]\n> {\n const {\n llm,\n tools,\n messageModifier,\n stateModifier,\n prompt,\n stateSchema,\n contextSchema,\n checkpointSaver,\n checkpointer,\n interruptBefore,\n interruptAfter,\n store,\n responseFormat,\n preModelHook,\n postModelHook,\n name,\n description,\n version = \"v1\",\n includeAgentName,\n } = params;\n\n let toolClasses: (ClientTool | ServerTool)[];\n\n let toolNode: ToolNode;\n if (!Array.isArray(tools)) {\n toolClasses = tools.tools;\n toolNode = tools;\n } else {\n toolClasses = tools;\n toolNode = new ToolNode(toolClasses.filter(isClientTool));\n }\n\n let cachedStaticModel: Runnable | null = null;\n\n const _getStaticModel = async (llm: LanguageModelLike): Promise<Runnable> => {\n if (cachedStaticModel) return cachedStaticModel;\n\n let modelWithTools: LanguageModelLike;\n if (await _shouldBindTools(llm, toolClasses)) {\n modelWithTools = await _bindTools(llm, toolClasses);\n } else {\n modelWithTools = llm;\n }\n\n const promptRunnable = _getPrompt(prompt, stateModifier, messageModifier);\n const modelRunnable =\n includeAgentName === \"inline\"\n ? withAgentName(modelWithTools, includeAgentName)\n : modelWithTools;\n\n cachedStaticModel = promptRunnable.pipe(modelRunnable);\n return cachedStaticModel;\n };\n\n const _getDynamicModel = async (\n llm: (\n state: AgentState<StructuredResponseFormat> & PreHookAnnotation[\"State\"],\n runtime: Runtime<ToAnnotationRoot<C>[\"State\"]>\n ) => Promise<LanguageModelLike> | LanguageModelLike,\n state: AgentState<StructuredResponseFormat> & PreHookAnnotation[\"State\"],\n config: Runtime<ToAnnotationRoot<C>[\"State\"]>\n ) => {\n const model = await llm(state, config);\n\n return _getPrompt(prompt, stateModifier, messageModifier).pipe(\n includeAgentName === \"inline\"\n ? withAgentName(model, includeAgentName)\n : model\n );\n };\n\n // If any of the tools are configured to return_directly after running,\n // our graph needs to check if these were called\n const shouldReturnDirect = new Set(\n toolClasses\n .filter(isClientTool)\n .filter((tool) => \"returnDirect\" in tool && tool.returnDirect)\n .map((tool) => tool.name)\n );\n\n function getModelInputState(\n state: AgentState<StructuredResponseFormat> & PreHookAnnotation[\"State\"]\n ): Omit<AgentState<StructuredResponseFormat>, \"llmInputMessages\"> {\n const { messages, llmInputMessages, ...rest } = state;\n if (llmInputMessages != null && llmInputMessages.length > 0) {\n return { messages: llmInputMessages, ...rest };\n }\n return { messages, ...rest };\n }\n\n const generateStructuredResponse = async (\n state: AgentState<StructuredResponseFormat> & PreHookAnnotation[\"State\"],\n config: Runtime<ToAnnotationRoot<C>[\"State\"]>\n ) => {\n if (responseFormat == null) {\n throw new Error(\n \"Attempted to generate structured output with no passed response schema. Please contact us for help.\"\n );\n }\n const messages = [...state.messages];\n let modelWithStructuredOutput;\n\n const model: LanguageModelLike =\n typeof llm === \"function\"\n ? await llm(state, config)\n : await _getModel(llm);\n\n if (!_isBaseChatModel(model)) {\n throw new Error(\n `Expected \\`llm\\` to be a ChatModel with .withStructuredOutput() method, got ${model.constructor.name}`\n );\n }\n\n if (typeof responseFormat === \"object\" && \"schema\" in responseFormat) {\n const { prompt, schema, ...options } =\n responseFormat as StructuredResponseSchemaOptions<StructuredResponseFormat>;\n\n modelWithStructuredOutput = model.withStructuredOutput(schema, options);\n if (prompt != null) {\n messages.unshift(new SystemMessage({ content: prompt }));\n }\n } else {\n modelWithStructuredOutput = model.withStructuredOutput(responseFormat);\n }\n\n const response = await modelWithStructuredOutput.invoke(messages, config);\n return { structuredResponse: response };\n };\n\n const callModel = async (\n state: AgentState<StructuredResponseFormat> & PreHookAnnotation[\"State\"],\n config: Runtime<ToAnnotationRoot<C>[\"State\"]>\n ) => {\n // NOTE: we're dynamically creating the model runnable here\n // to ensure that we can validate ConfigurableModel properly\n const modelRunnable: Runnable =\n typeof llm === \"function\"\n ? await _getDynamicModel(llm, state, config)\n : await _getStaticModel(llm);\n\n // TODO: Auto-promote streaming.\n const response = (await modelRunnable.invoke(\n getModelInputState(state),\n config\n )) as BaseMessage;\n // add agent name to the AIMessage\n // TODO: figure out if we can avoid mutating the message directly\n response.name = name;\n response.lc_kwargs.name = name;\n return { messages: [response] };\n };\n\n const schema =\n stateSchema ?? createReactAgentAnnotation<StructuredResponseFormat>();\n\n const workflow = new StateGraph(\n schema as AnyAnnotationRoot,\n contextSchema\n ).addNode(\"tools\", toolNode);\n\n if (!(\"messages\" in workflow._schemaDefinition)) {\n throw new Error(\"Missing required `messages` key in state schema.\");\n }\n\n const allNodeWorkflows = workflow as WithStateGraphNodes<\n | \"pre_model_hook\"\n | \"post_model_hook\"\n | \"generate_structured_response\"\n | \"agent\",\n typeof workflow\n >;\n\n const conditionalMap = <T extends string>(map: Record<string, T | null>) => {\n return Object.fromEntries(\n Object.entries(map).filter(([_, v]) => v != null) as [string, T][]\n );\n };\n\n let entrypoint: \"agent\" | \"pre_model_hook\" = \"agent\";\n let inputSchema: AnnotationRoot<ToAnnotationRoot<A>[\"spec\"]> | undefined;\n if (preModelHook != null) {\n allNodeWorkflows\n .addNode(\"pre_model_hook\", preModelHook)\n .addEdge(\"pre_model_hook\", \"agent\");\n entrypoint = \"pre_model_hook\";\n\n inputSchema = Annotation.Root({\n ...workflow._schemaDefinition,\n ...PreHookAnnotation.spec,\n });\n } else {\n entrypoint = \"agent\";\n }\n\n allNodeWorkflows\n .addNode(\"agent\", callModel, { input: inputSchema })\n .addEdge(START, entrypoint);\n\n if (postModelHook != null) {\n allNodeWorkflows\n .addNode(\"post_model_hook\", postModelHook)\n .addEdge(\"agent\", \"post_model_hook\")\n .addConditionalEdges(\n \"post_model_hook\",\n (state: AgentState<StructuredResponseFormat>) => {\n const { messages } = state;\n\n const toolMessageIds: Set<string> = new Set(\n messages.filter(isToolMessage).map((msg) => msg.tool_call_id)\n );\n\n let lastAiMessage: AIMessage | undefined;\n for (let i = messages.length - 1; i >= 0; i -= 1) {\n const message = messages[i];\n if (isAIMessage(message)) {\n lastAiMessage = message;\n break;\n }\n }\n\n const pendingToolCalls =\n lastAiMessage?.tool_calls?.filter(\n (i) => i.id == null || !toolMessageIds.has(i.id)\n ) ?? [];\n\n const lastMessage = messages.at(-1);\n if (pendingToolCalls.length > 0) {\n if (version === \"v2\") {\n return pendingToolCalls.map(\n (toolCall) =>\n new Send(\"tools\", { ...state, lg_tool_call: toolCall })\n );\n }\n return \"tools\";\n }\n\n if (lastMessage && isToolMessage(lastMessage)) return entrypoint;\n if (responseFormat != null) return \"generate_structured_response\";\n return END;\n },\n conditionalMap({\n tools: \"tools\",\n [entrypoint]: entrypoint,\n generate_structured_response:\n responseFormat != null ? \"generate_structured_response\" : null,\n [END]: responseFormat != null ? null : END,\n })\n );\n }\n\n if (responseFormat !== undefined) {\n workflow\n .addNode(\"generate_structured_response\", generateStructuredResponse)\n .addEdge(\"generate_structured_response\", END);\n }\n\n if (postModelHook == null) {\n allNodeWorkflows.addConditionalEdges(\n \"agent\",\n (state: AgentState<StructuredResponseFormat>) => {\n const { messages } = state;\n const lastMessage = messages[messages.length - 1];\n\n // if there's no function call, we finish\n if (!isAIMessage(lastMessage) || !lastMessage.tool_calls?.length) {\n if (responseFormat != null) return \"generate_structured_response\";\n return END;\n }\n\n // there are function calls, we continue\n if (version === \"v2\") {\n return lastMessage.tool_calls.map(\n (toolCall) =>\n new Send(\"tools\", { ...state, lg_tool_call: toolCall })\n );\n }\n\n return \"tools\";\n },\n conditionalMap({\n tools: \"tools\",\n generate_structured_response:\n responseFormat != null ? \"generate_structured_response\" : null,\n [END]: responseFormat != null ? null : END,\n })\n );\n }\n\n if (shouldReturnDirect.size > 0) {\n allNodeWorkflows.addConditionalEdges(\n \"tools\",\n (state: AgentState<StructuredResponseFormat>) => {\n // Check the last consecutive tool calls\n for (let i = state.messages.length - 1; i >= 0; i -= 1) {\n const message = state.messages[i];\n if (!isToolMessage(message)) break;\n\n // Check if this tool is configured to return directly\n if (\n message.name !== undefined &&\n shouldReturnDirect.has(message.name)\n ) {\n return END;\n }\n }\n\n return entrypoint;\n },\n conditionalMap({ [entrypoint]: entrypoint, [END]: END })\n );\n } else {\n allNodeWorkflows.addEdge(\"tools\", entrypoint);\n }\n\n return allNodeWorkflows.compile({\n checkpointer: checkpointer ?? checkpointSaver,\n interruptBefore,\n interruptAfter,\n store,\n name,\n description,\n });\n}\n"],"mappings":";;;;;;;;;;;AA2EA,SAAS,gCACP,iBACQ;AAER,KACE,OAAO,oBAAoB,YAC1B,cAAc,oBAAoB,gBAAgB,eAAe,SAElE,QAAO;AAIT,KAAI,OAAO,oBAAoB,WAC7B,QAAO,OAAO,UACZ,gBAAgB,MAAM;AAI1B,KAAI,SAAS,WAAW,iBACtB,QAAO,eAAe,MACnB,UAA2C,MAAM,UAClD,KAAK;AAGT,OAAM,IAAI,MACR,wCAAwC,OAAO;;AAInD,MAAM,uBAAuB;AAE7B,SAAS,mBAAmB,QAA2B;CACrD,IAAIA;AAEJ,KAAI,UAAU,KACZ,kBAAiB,eAAe,MAC7B,UAA2C,MAAM,UAClD,WAAW,EAAE,SAAS;UACf,OAAO,WAAW,UAAU;EACrC,MAAM,gBAAgB,IAAI,cAAc;AACxC,mBAAiB,eAAe,MAC7B,UAA2C;AAC1C,UAAO,CAAC,eAAe,GAAI,MAAM,YAAY;KAE/C,WAAW,EAAE,SAAS;YACf,cAAc,WAAW,OAAO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,OAAO,EAC5B,kBAAiB,oBACf,UACC,UAAgD;AAE/C,OAAK,IAAI,IAAI,MAAM,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG;GACtD,MAAM,UAAU,MAAM,SAAS;AAC/B,OAAI,CAAC,cAAc,SAAU;AAG7B,OACE,QAAQ,SAAS,UACjB,mBAAmB,IAAI,QAAQ,MAE/B,QAAO;;AAIX,SAAO;IAET,eAAe;GAAG,aAAa;GAAa,MAAM;;KAGpD,kBAAiB,QAAQ,SAAS;AAGpC,QAAO,iBAAiB,QAAQ;EAC9B,cAAc,gBAAgB;EAC9B;EACA;EACA;EACA;EACA"}
@@ -1,48 +0,0 @@
1
- const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
- const __langchain_core_runnables = require_rolldown_runtime.__toESM(require("@langchain/core/runnables"));
3
-
4
- //#region src/prebuilt/tool_executor.ts
5
- const INVALID_TOOL_MSG_TEMPLATE = `{requestedToolName} is not a valid tool, try one of {availableToolNamesString}.`;
6
- /** @deprecated Use {@link ToolNode} instead. */
7
- var ToolExecutor = class extends __langchain_core_runnables.RunnableBinding {
8
- lc_graph_name = "ToolExecutor";
9
- tools;
10
- toolMap;
11
- invalidToolMsgTemplate;
12
- constructor(fields) {
13
- const fieldsWithDefaults = {
14
- invalidToolMsgTemplate: INVALID_TOOL_MSG_TEMPLATE,
15
- ...fields
16
- };
17
- const bound = __langchain_core_runnables.RunnableLambda.from(async (input, config) => this._execute(input, config));
18
- super({
19
- bound,
20
- config: {}
21
- });
22
- this.tools = fieldsWithDefaults.tools;
23
- this.invalidToolMsgTemplate = fieldsWithDefaults.invalidToolMsgTemplate;
24
- this.toolMap = this.tools.reduce((acc, tool) => {
25
- acc[tool.name] = tool;
26
- return acc;
27
- }, {});
28
- }
29
- /**
30
- * Execute a tool invocation
31
- *
32
- * @param {ToolInvocationInterface} toolInvocation The tool to invoke and the input to pass to it.
33
- * @param {RunnableConfig | undefined} config Optional configuration to pass to the tool when invoked.
34
- * @returns Either the result of the tool invocation (`string` or `ToolMessage`, set by the `ToolOutput` generic) or a string error message.
35
- */
36
- async _execute(toolInvocation, config) {
37
- if (!(toolInvocation.tool in this.toolMap)) return this.invalidToolMsgTemplate.replace("{requestedToolName}", toolInvocation.tool).replace("{availableToolNamesString}", Object.keys(this.toolMap).join(", "));
38
- else {
39
- const tool = this.toolMap[toolInvocation.tool];
40
- const output = await tool.invoke(toolInvocation.toolInput, config);
41
- return output;
42
- }
43
- }
44
- };
45
-
46
- //#endregion
47
- exports.ToolExecutor = ToolExecutor;
48
- //# sourceMappingURL=tool_executor.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool_executor.cjs","names":["RunnableBinding","RunnableLambda"],"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,cAAkCA,2CAGhC;CACA,gBAAgB;CAEhB;CAEA;CAEA;CAEA,YAAY,QAA0B;EACpC,MAAM,qBAAqB;GACzB,wBAAwB;GACxB,GAAG;;EAEL,MAAM,QAAQC,0CAAe,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,42 +0,0 @@
1
- import { RunnableBinding, RunnableConfig, RunnableToolLike } from "@langchain/core/runnables";
2
- import { StructuredToolInterface } from "@langchain/core/tools";
3
-
4
- //#region src/prebuilt/tool_executor.d.ts
5
- /** @deprecated Use {@link ToolNode} instead. */
6
- interface ToolExecutorArgs {
7
- tools: Array<StructuredToolInterface | RunnableToolLike>;
8
- /**
9
- * @default {INVALID_TOOL_MSG_TEMPLATE}
10
- */
11
- invalidToolMsgTemplate?: string;
12
- }
13
- /**
14
- * Interface for invoking a tool
15
- */
16
- interface ToolInvocationInterface {
17
- tool: string;
18
- toolInput: string;
19
- }
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- type ToolExecutorInputType = any;
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
- type ToolExecutorOutputType = any;
24
- /** @deprecated Use {@link ToolNode} instead. */
25
- declare class ToolExecutor extends RunnableBinding<ToolExecutorInputType, ToolExecutorOutputType> {
26
- lc_graph_name: string;
27
- tools: Array<StructuredToolInterface | RunnableToolLike>;
28
- toolMap: Record<string, StructuredToolInterface | RunnableToolLike>;
29
- invalidToolMsgTemplate: string;
30
- constructor(fields: ToolExecutorArgs);
31
- /**
32
- * Execute a tool invocation
33
- *
34
- * @param {ToolInvocationInterface} toolInvocation The tool to invoke and the input to pass to it.
35
- * @param {RunnableConfig | undefined} config Optional configuration to pass to the tool when invoked.
36
- * @returns Either the result of the tool invocation (`string` or `ToolMessage`, set by the `ToolOutput` generic) or a string error message.
37
- */
38
- _execute(toolInvocation: ToolInvocationInterface, config?: RunnableConfig): Promise<ToolExecutorOutputType>;
39
- }
40
- //#endregion
41
- export { ToolExecutor, ToolExecutorArgs, ToolInvocationInterface };
42
- //# sourceMappingURL=tool_executor.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool_executor.d.cts","names":["RunnableBinding","RunnableConfig","RunnableToolLike","StructuredToolInterface","ToolExecutorArgs","Array","ToolInvocationInterface","ToolExecutorInputType","ToolExecutorOutputType","ToolExecutor","Record","Promise"],"sources":["../../src/prebuilt/tool_executor.d.ts"],"sourcesContent":["import { RunnableBinding, RunnableConfig, RunnableToolLike } from \"@langchain/core/runnables\";\nimport { StructuredToolInterface } from \"@langchain/core/tools\";\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 * Interface for invoking a tool\n */\nexport interface ToolInvocationInterface {\n tool: string;\n toolInput: string;\n}\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ToolExecutorInputType = any;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ToolExecutorOutputType = any;\n/** @deprecated Use {@link ToolNode} instead. */\nexport declare class ToolExecutor extends RunnableBinding<ToolExecutorInputType, ToolExecutorOutputType> {\n lc_graph_name: string;\n tools: Array<StructuredToolInterface | RunnableToolLike>;\n toolMap: Record<string, StructuredToolInterface | RunnableToolLike>;\n invalidToolMsgTemplate: string;\n constructor(fields: ToolExecutorArgs);\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 _execute(toolInvocation: ToolInvocationInterface, config?: RunnableConfig): Promise<ToolExecutorOutputType>;\n}\nexport {};\n"],"mappings":";;;;;UAGiBI,gBAAAA;EAAAA,KAAAA,EACNC,KADMD,CACAD,uBADgB,GACUD,gBADV,CAAA;EAAA;;;wBACtBG,CAAAA,EAAAA,MAAAA;;AASX;AAGC;AAEyB;AAILI,UATJH,uBAAAA,CASgB;EAAA,IAAA,EAAA,MAAA;WAAyBC,EAAAA,MAAAA;;;KAJrDA,qBAAAA,GAMsCL,GAAAA;;KAJtCM,sBAAAA,GAKuBL,GAAAA;;AAAfO,cAHQD,YAAAA,SAAqBT,eAG7BU,CAH6CH,qBAG7CG,EAHoEF,sBAGpEE,CAAAA,CAAAA;eAEWN,EAAAA,MAAAA;OAQKE,EAXlBD,KAWkBC,CAXZH,uBAWYG,GAXcJ,gBAWdI,CAAAA;SAAkCL,EAVlDS,MAUkDT,CAAAA,MAAAA,EAVnCE,uBAUmCF,GAVTC,gBAUSD,CAAAA;wBAAyBO,EAAAA,MAAAA;aAARG,CAAAA,MAAAA,EARxDP,gBAQwDO;;;;;;;;2BAAnDL,kCAAkCL,iBAAiBU,QAAQH"}
@@ -1,42 +0,0 @@
1
- import { RunnableBinding, RunnableConfig, RunnableToolLike } from "@langchain/core/runnables";
2
- import { StructuredToolInterface } from "@langchain/core/tools";
3
-
4
- //#region src/prebuilt/tool_executor.d.ts
5
- /** @deprecated Use {@link ToolNode} instead. */
6
- interface ToolExecutorArgs {
7
- tools: Array<StructuredToolInterface | RunnableToolLike>;
8
- /**
9
- * @default {INVALID_TOOL_MSG_TEMPLATE}
10
- */
11
- invalidToolMsgTemplate?: string;
12
- }
13
- /**
14
- * Interface for invoking a tool
15
- */
16
- interface ToolInvocationInterface {
17
- tool: string;
18
- toolInput: string;
19
- }
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- type ToolExecutorInputType = any;
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
- type ToolExecutorOutputType = any;
24
- /** @deprecated Use {@link ToolNode} instead. */
25
- declare class ToolExecutor extends RunnableBinding<ToolExecutorInputType, ToolExecutorOutputType> {
26
- lc_graph_name: string;
27
- tools: Array<StructuredToolInterface | RunnableToolLike>;
28
- toolMap: Record<string, StructuredToolInterface | RunnableToolLike>;
29
- invalidToolMsgTemplate: string;
30
- constructor(fields: ToolExecutorArgs);
31
- /**
32
- * Execute a tool invocation
33
- *
34
- * @param {ToolInvocationInterface} toolInvocation The tool to invoke and the input to pass to it.
35
- * @param {RunnableConfig | undefined} config Optional configuration to pass to the tool when invoked.
36
- * @returns Either the result of the tool invocation (`string` or `ToolMessage`, set by the `ToolOutput` generic) or a string error message.
37
- */
38
- _execute(toolInvocation: ToolInvocationInterface, config?: RunnableConfig): Promise<ToolExecutorOutputType>;
39
- }
40
- //#endregion
41
- export { ToolExecutor, ToolExecutorArgs, ToolInvocationInterface };
42
- //# sourceMappingURL=tool_executor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool_executor.d.ts","names":["RunnableBinding","RunnableConfig","RunnableToolLike","StructuredToolInterface","ToolExecutorArgs","Array","ToolInvocationInterface","ToolExecutorInputType","ToolExecutorOutputType","ToolExecutor","Record","Promise"],"sources":["../../src/prebuilt/tool_executor.d.ts"],"sourcesContent":["import { RunnableBinding, RunnableConfig, RunnableToolLike } from \"@langchain/core/runnables\";\nimport { StructuredToolInterface } from \"@langchain/core/tools\";\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 * Interface for invoking a tool\n */\nexport interface ToolInvocationInterface {\n tool: string;\n toolInput: string;\n}\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ToolExecutorInputType = any;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype ToolExecutorOutputType = any;\n/** @deprecated Use {@link ToolNode} instead. */\nexport declare class ToolExecutor extends RunnableBinding<ToolExecutorInputType, ToolExecutorOutputType> {\n lc_graph_name: string;\n tools: Array<StructuredToolInterface | RunnableToolLike>;\n toolMap: Record<string, StructuredToolInterface | RunnableToolLike>;\n invalidToolMsgTemplate: string;\n constructor(fields: ToolExecutorArgs);\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 _execute(toolInvocation: ToolInvocationInterface, config?: RunnableConfig): Promise<ToolExecutorOutputType>;\n}\nexport {};\n"],"mappings":";;;;;UAGiBI,gBAAAA;EAAAA,KAAAA,EACNC,KADMD,CACAD,uBADgB,GACUD,gBADV,CAAA;EAAA;;;wBACtBG,CAAAA,EAAAA,MAAAA;;AASX;AAGC;AAEyB;AAILI,UATJH,uBAAAA,CASgB;EAAA,IAAA,EAAA,MAAA;WAAyBC,EAAAA,MAAAA;;;KAJrDA,qBAAAA,GAMsCL,GAAAA;;KAJtCM,sBAAAA,GAKuBL,GAAAA;;AAAfO,cAHQD,YAAAA,SAAqBT,eAG7BU,CAH6CH,qBAG7CG,EAHoEF,sBAGpEE,CAAAA,CAAAA;eAEWN,EAAAA,MAAAA;OAQKE,EAXlBD,KAWkBC,CAXZH,uBAWYG,GAXcJ,gBAWdI,CAAAA;SAAkCL,EAVlDS,MAUkDT,CAAAA,MAAAA,EAVnCE,uBAUmCF,GAVTC,gBAUSD,CAAAA;wBAAyBO,EAAAA,MAAAA;aAARG,CAAAA,MAAAA,EARxDP,gBAQwDO;;;;;;;;2BAAnDL,kCAAkCL,iBAAiBU,QAAQH"}
@@ -1,47 +0,0 @@
1
- import { RunnableBinding, RunnableLambda } from "@langchain/core/runnables";
2
-
3
- //#region src/prebuilt/tool_executor.ts
4
- const INVALID_TOOL_MSG_TEMPLATE = `{requestedToolName} is not a valid tool, try one of {availableToolNamesString}.`;
5
- /** @deprecated Use {@link ToolNode} instead. */
6
- var ToolExecutor = class extends RunnableBinding {
7
- lc_graph_name = "ToolExecutor";
8
- tools;
9
- toolMap;
10
- invalidToolMsgTemplate;
11
- constructor(fields) {
12
- const fieldsWithDefaults = {
13
- invalidToolMsgTemplate: INVALID_TOOL_MSG_TEMPLATE,
14
- ...fields
15
- };
16
- const bound = RunnableLambda.from(async (input, config) => this._execute(input, config));
17
- super({
18
- bound,
19
- config: {}
20
- });
21
- this.tools = fieldsWithDefaults.tools;
22
- this.invalidToolMsgTemplate = fieldsWithDefaults.invalidToolMsgTemplate;
23
- this.toolMap = this.tools.reduce((acc, tool) => {
24
- acc[tool.name] = tool;
25
- return acc;
26
- }, {});
27
- }
28
- /**
29
- * Execute a tool invocation
30
- *
31
- * @param {ToolInvocationInterface} toolInvocation The tool to invoke and the input to pass to it.
32
- * @param {RunnableConfig | undefined} config Optional configuration to pass to the tool when invoked.
33
- * @returns Either the result of the tool invocation (`string` or `ToolMessage`, set by the `ToolOutput` generic) or a string error message.
34
- */
35
- async _execute(toolInvocation, config) {
36
- if (!(toolInvocation.tool in this.toolMap)) return this.invalidToolMsgTemplate.replace("{requestedToolName}", toolInvocation.tool).replace("{availableToolNamesString}", Object.keys(this.toolMap).join(", "));
37
- else {
38
- const tool = this.toolMap[toolInvocation.tool];
39
- const output = await tool.invoke(toolInvocation.toolInput, config);
40
- return output;
41
- }
42
- }
43
- };
44
-
45
- //#endregion
46
- export { ToolExecutor };
47
- //# sourceMappingURL=tool_executor.js.map