@langchain/langgraph 0.4.8 → 1.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (494) hide show
  1. package/CHANGELOG.md +7 -2
  2. package/README.md +1 -2
  3. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  4. package/dist/channels/any_value.d.cts +26 -0
  5. package/dist/channels/any_value.d.cts.map +1 -0
  6. package/dist/channels/any_value.d.ts +16 -9
  7. package/dist/channels/any_value.d.ts.map +1 -0
  8. package/dist/channels/base.cjs +97 -133
  9. package/dist/channels/base.cjs.map +1 -0
  10. package/dist/channels/base.d.cts +73 -0
  11. package/dist/channels/base.d.cts.map +1 -0
  12. package/dist/channels/base.d.ts +73 -74
  13. package/dist/channels/base.d.ts.map +1 -0
  14. package/dist/channels/base.js +94 -127
  15. package/dist/channels/base.js.map +1 -1
  16. package/dist/channels/binop.cjs +47 -77
  17. package/dist/channels/binop.cjs.map +1 -0
  18. package/dist/channels/binop.d.cts +22 -0
  19. package/dist/channels/binop.d.cts.map +1 -0
  20. package/dist/channels/binop.d.ts +17 -12
  21. package/dist/channels/binop.d.ts.map +1 -0
  22. package/dist/channels/binop.js +45 -71
  23. package/dist/channels/binop.js.map +1 -1
  24. package/dist/channels/dynamic_barrier_value.d.cts +43 -0
  25. package/dist/channels/dynamic_barrier_value.d.cts.map +1 -0
  26. package/dist/channels/dynamic_barrier_value.d.ts +20 -34
  27. package/dist/channels/dynamic_barrier_value.d.ts.map +1 -0
  28. package/dist/channels/ephemeral_value.cjs +46 -70
  29. package/dist/channels/ephemeral_value.cjs.map +1 -0
  30. package/dist/channels/ephemeral_value.d.cts +23 -0
  31. package/dist/channels/ephemeral_value.d.cts.map +1 -0
  32. package/dist/channels/ephemeral_value.d.ts +18 -11
  33. package/dist/channels/ephemeral_value.d.ts.map +1 -0
  34. package/dist/channels/ephemeral_value.js +45 -65
  35. package/dist/channels/ephemeral_value.js.map +1 -1
  36. package/dist/channels/index.cjs +2 -10
  37. package/dist/channels/index.js +4 -3
  38. package/dist/channels/last_value.cjs +91 -140
  39. package/dist/channels/last_value.cjs.map +1 -0
  40. package/dist/channels/last_value.d.cts +30 -0
  41. package/dist/channels/last_value.d.cts.map +1 -0
  42. package/dist/channels/last_value.d.ts +15 -23
  43. package/dist/channels/last_value.d.ts.map +1 -0
  44. package/dist/channels/last_value.js +88 -133
  45. package/dist/channels/last_value.js.map +1 -1
  46. package/dist/channels/named_barrier_value.cjs +114 -170
  47. package/dist/channels/named_barrier_value.cjs.map +1 -0
  48. package/dist/channels/named_barrier_value.d.cts +33 -0
  49. package/dist/channels/named_barrier_value.d.cts.map +1 -0
  50. package/dist/channels/named_barrier_value.d.ts +19 -29
  51. package/dist/channels/named_barrier_value.d.ts.map +1 -0
  52. package/dist/channels/named_barrier_value.js +112 -163
  53. package/dist/channels/named_barrier_value.js.map +1 -1
  54. package/dist/channels/topic.cjs +63 -96
  55. package/dist/channels/topic.cjs.map +1 -0
  56. package/dist/channels/topic.d.cts +26 -0
  57. package/dist/channels/topic.d.cts.map +1 -0
  58. package/dist/channels/topic.d.ts +21 -18
  59. package/dist/channels/topic.d.ts.map +1 -0
  60. package/dist/channels/topic.js +61 -90
  61. package/dist/channels/topic.js.map +1 -1
  62. package/dist/constants.cjs +373 -452
  63. package/dist/constants.cjs.map +1 -0
  64. package/dist/constants.d.cts +284 -0
  65. package/dist/constants.d.cts.map +1 -0
  66. package/dist/constants.d.ts +112 -148
  67. package/dist/constants.d.ts.map +1 -0
  68. package/dist/constants.js +333 -444
  69. package/dist/constants.js.map +1 -1
  70. package/dist/errors.cjs +150 -179
  71. package/dist/errors.cjs.map +1 -0
  72. package/dist/errors.d.cts +80 -0
  73. package/dist/errors.d.cts.map +1 -0
  74. package/dist/errors.d.ts +55 -46
  75. package/dist/errors.d.ts.map +1 -0
  76. package/dist/errors.js +139 -165
  77. package/dist/errors.js.map +1 -1
  78. package/dist/func/index.cjs +289 -290
  79. package/dist/func/index.cjs.map +1 -0
  80. package/dist/func/index.d.cts +289 -0
  81. package/dist/func/index.d.cts.map +1 -0
  82. package/dist/func/index.d.ts +81 -71
  83. package/dist/func/index.d.ts.map +1 -0
  84. package/dist/func/index.js +285 -284
  85. package/dist/func/index.js.map +1 -1
  86. package/dist/func/types.d.cts +64 -0
  87. package/dist/func/types.d.cts.map +1 -0
  88. package/dist/func/types.d.ts +24 -19
  89. package/dist/func/types.d.ts.map +1 -0
  90. package/dist/graph/annotation.cjs +96 -120
  91. package/dist/graph/annotation.cjs.map +1 -0
  92. package/dist/graph/annotation.d.cts +116 -0
  93. package/dist/graph/annotation.d.cts.map +1 -0
  94. package/dist/graph/annotation.d.ts +33 -34
  95. package/dist/graph/annotation.d.ts.map +1 -0
  96. package/dist/graph/annotation.js +91 -112
  97. package/dist/graph/annotation.js.map +1 -1
  98. package/dist/graph/graph.cjs +419 -723
  99. package/dist/graph/graph.cjs.map +1 -0
  100. package/dist/graph/graph.d.cts +131 -0
  101. package/dist/graph/graph.d.cts.map +1 -0
  102. package/dist/graph/graph.d.ts +122 -91
  103. package/dist/graph/graph.d.ts.map +1 -0
  104. package/dist/graph/graph.js +412 -713
  105. package/dist/graph/graph.js.map +1 -1
  106. package/dist/graph/index.cjs +4 -17
  107. package/dist/graph/index.js +6 -5
  108. package/dist/graph/message.cjs +59 -104
  109. package/dist/graph/message.cjs.map +1 -0
  110. package/dist/graph/message.d.cts +19 -0
  111. package/dist/graph/message.d.cts.map +1 -0
  112. package/dist/graph/message.d.ts +11 -10
  113. package/dist/graph/message.d.ts.map +1 -0
  114. package/dist/graph/message.js +56 -98
  115. package/dist/graph/message.js.map +1 -1
  116. package/dist/graph/messages_annotation.cjs +106 -106
  117. package/dist/graph/messages_annotation.cjs.map +1 -0
  118. package/dist/graph/messages_annotation.d.cts +111 -0
  119. package/dist/graph/messages_annotation.d.cts.map +1 -0
  120. package/dist/graph/messages_annotation.d.ts +18 -9
  121. package/dist/graph/messages_annotation.d.ts.map +1 -0
  122. package/dist/graph/messages_annotation.js +100 -100
  123. package/dist/graph/messages_annotation.js.map +1 -1
  124. package/dist/graph/state.cjs +476 -777
  125. package/dist/graph/state.cjs.map +1 -0
  126. package/dist/graph/state.d.cts +216 -0
  127. package/dist/graph/state.d.cts.map +1 -0
  128. package/dist/graph/state.d.ts +129 -134
  129. package/dist/graph/state.d.ts.map +1 -0
  130. package/dist/graph/state.js +470 -768
  131. package/dist/graph/state.js.map +1 -1
  132. package/dist/graph/zod/index.cjs +10 -21
  133. package/dist/graph/zod/index.d.cts +3 -0
  134. package/dist/graph/zod/index.d.ts +3 -3
  135. package/dist/graph/zod/index.js +4 -4
  136. package/dist/graph/zod/meta.cjs +142 -177
  137. package/dist/graph/zod/meta.cjs.map +1 -0
  138. package/dist/graph/zod/meta.d.cts +116 -0
  139. package/dist/graph/zod/meta.d.cts.map +1 -0
  140. package/dist/graph/zod/meta.d.ts +99 -97
  141. package/dist/graph/zod/meta.d.ts.map +1 -0
  142. package/dist/graph/zod/meta.js +136 -170
  143. package/dist/graph/zod/meta.js.map +1 -1
  144. package/dist/graph/zod/plugin.cjs +36 -39
  145. package/dist/graph/zod/plugin.cjs.map +1 -0
  146. package/dist/graph/zod/plugin.js +34 -35
  147. package/dist/graph/zod/plugin.js.map +1 -1
  148. package/dist/graph/zod/schema.cjs +82 -110
  149. package/dist/graph/zod/schema.cjs.map +1 -0
  150. package/dist/graph/zod/schema.d.cts +38 -0
  151. package/dist/graph/zod/schema.d.cts.map +1 -0
  152. package/dist/graph/zod/schema.d.ts +12 -6
  153. package/dist/graph/zod/schema.d.ts.map +1 -0
  154. package/dist/graph/zod/schema.js +77 -103
  155. package/dist/graph/zod/schema.js.map +1 -1
  156. package/dist/graph/zod/zod-registry.cjs +41 -47
  157. package/dist/graph/zod/zod-registry.cjs.map +1 -0
  158. package/dist/graph/zod/zod-registry.d.cts +51 -0
  159. package/dist/graph/zod/zod-registry.d.cts.map +1 -0
  160. package/dist/graph/zod/zod-registry.d.ts +34 -26
  161. package/dist/graph/zod/zod-registry.d.ts.map +1 -0
  162. package/dist/graph/zod/zod-registry.js +37 -41
  163. package/dist/graph/zod/zod-registry.js.map +1 -1
  164. package/dist/hash.cjs +205 -267
  165. package/dist/hash.cjs.map +1 -0
  166. package/dist/hash.js +205 -265
  167. package/dist/hash.js.map +1 -1
  168. package/dist/index.cjs +110 -33
  169. package/dist/index.cjs.map +1 -0
  170. package/dist/index.d.cts +25 -0
  171. package/dist/index.d.ts +25 -5
  172. package/dist/index.js +18 -7
  173. package/dist/index.js.map +1 -1
  174. package/dist/interrupt.cjs +79 -85
  175. package/dist/interrupt.cjs.map +1 -0
  176. package/dist/interrupt.d.cts +49 -0
  177. package/dist/interrupt.d.cts.map +1 -0
  178. package/dist/interrupt.d.ts +6 -1
  179. package/dist/interrupt.d.ts.map +1 -0
  180. package/dist/interrupt.js +76 -80
  181. package/dist/interrupt.js.map +1 -1
  182. package/dist/prebuilt/agentName.cjs +139 -172
  183. package/dist/prebuilt/agentName.cjs.map +1 -0
  184. package/dist/prebuilt/agentName.d.cts +42 -0
  185. package/dist/prebuilt/agentName.d.cts.map +1 -0
  186. package/dist/prebuilt/agentName.d.ts +13 -21
  187. package/dist/prebuilt/agentName.d.ts.map +1 -0
  188. package/dist/prebuilt/agentName.js +139 -168
  189. package/dist/prebuilt/agentName.js.map +1 -1
  190. package/dist/prebuilt/agent_executor.cjs +42 -80
  191. package/dist/prebuilt/agent_executor.cjs.map +1 -0
  192. package/dist/prebuilt/agent_executor.d.cts +57 -0
  193. package/dist/prebuilt/agent_executor.d.cts.map +1 -0
  194. package/dist/prebuilt/agent_executor.d.ts +46 -37
  195. package/dist/prebuilt/agent_executor.d.ts.map +1 -0
  196. package/dist/prebuilt/agent_executor.js +40 -75
  197. package/dist/prebuilt/agent_executor.js.map +1 -1
  198. package/dist/prebuilt/chat_agent_executor.cjs +66 -128
  199. package/dist/prebuilt/chat_agent_executor.cjs.map +1 -0
  200. package/dist/prebuilt/chat_agent_executor.d.cts +23 -0
  201. package/dist/prebuilt/chat_agent_executor.d.cts.map +1 -0
  202. package/dist/prebuilt/chat_agent_executor.d.ts +18 -10
  203. package/dist/prebuilt/chat_agent_executor.d.ts.map +1 -0
  204. package/dist/prebuilt/chat_agent_executor.js +63 -123
  205. package/dist/prebuilt/chat_agent_executor.js.map +1 -1
  206. package/dist/prebuilt/index.cjs +15 -18
  207. package/dist/prebuilt/index.d.cts +8 -0
  208. package/dist/prebuilt/index.d.ts +8 -8
  209. package/dist/prebuilt/index.js +8 -7
  210. package/dist/prebuilt/interrupt.d.cts +73 -0
  211. package/dist/prebuilt/interrupt.d.cts.map +1 -0
  212. package/dist/prebuilt/interrupt.d.ts +32 -15
  213. package/dist/prebuilt/interrupt.d.ts.map +1 -0
  214. package/dist/prebuilt/react_agent_executor.cjs +317 -473
  215. package/dist/prebuilt/react_agent_executor.cjs.map +1 -0
  216. package/dist/prebuilt/react_agent_executor.d.cts +229 -0
  217. package/dist/prebuilt/react_agent_executor.d.cts.map +1 -0
  218. package/dist/prebuilt/react_agent_executor.d.ts +171 -143
  219. package/dist/prebuilt/react_agent_executor.d.ts.map +1 -0
  220. package/dist/prebuilt/react_agent_executor.js +315 -465
  221. package/dist/prebuilt/react_agent_executor.js.map +1 -1
  222. package/dist/prebuilt/tool_executor.cjs +45 -67
  223. package/dist/prebuilt/tool_executor.cjs.map +1 -0
  224. package/dist/prebuilt/tool_executor.d.cts +42 -0
  225. package/dist/prebuilt/tool_executor.d.cts.map +1 -0
  226. package/dist/prebuilt/tool_executor.d.ts +30 -24
  227. package/dist/prebuilt/tool_executor.d.ts.map +1 -0
  228. package/dist/prebuilt/tool_executor.js +44 -63
  229. package/dist/prebuilt/tool_executor.js.map +1 -1
  230. package/dist/prebuilt/tool_node.cjs +213 -275
  231. package/dist/prebuilt/tool_node.cjs.map +1 -0
  232. package/dist/prebuilt/tool_node.d.cts +151 -0
  233. package/dist/prebuilt/tool_node.d.cts.map +1 -0
  234. package/dist/prebuilt/tool_node.d.ts +30 -17
  235. package/dist/prebuilt/tool_node.d.ts.map +1 -0
  236. package/dist/prebuilt/tool_node.js +209 -268
  237. package/dist/prebuilt/tool_node.js.map +1 -1
  238. package/dist/pregel/algo.cjs +521 -692
  239. package/dist/pregel/algo.cjs.map +1 -0
  240. package/dist/pregel/algo.d.cts +13 -0
  241. package/dist/pregel/algo.d.cts.map +1 -0
  242. package/dist/pregel/algo.d.ts +8 -38
  243. package/dist/pregel/algo.d.ts.map +1 -0
  244. package/dist/pregel/algo.js +516 -683
  245. package/dist/pregel/algo.js.map +1 -1
  246. package/dist/pregel/call.cjs +46 -42
  247. package/dist/pregel/call.cjs.map +1 -0
  248. package/dist/pregel/call.js +43 -37
  249. package/dist/pregel/call.js.map +1 -1
  250. package/dist/pregel/debug.cjs +153 -223
  251. package/dist/pregel/debug.cjs.map +1 -0
  252. package/dist/pregel/debug.js +152 -215
  253. package/dist/pregel/debug.js.map +1 -1
  254. package/dist/pregel/index.cjs +1134 -1604
  255. package/dist/pregel/index.cjs.map +1 -0
  256. package/dist/pregel/index.d.cts +534 -0
  257. package/dist/pregel/index.d.cts.map +1 -0
  258. package/dist/pregel/index.d.ts +458 -422
  259. package/dist/pregel/index.d.ts.map +1 -0
  260. package/dist/pregel/index.js +1125 -1592
  261. package/dist/pregel/index.js.map +1 -1
  262. package/dist/pregel/io.cjs +127 -234
  263. package/dist/pregel/io.cjs.map +1 -0
  264. package/dist/pregel/io.js +122 -225
  265. package/dist/pregel/io.js.map +1 -1
  266. package/dist/pregel/loop.cjs +539 -954
  267. package/dist/pregel/loop.cjs.map +1 -0
  268. package/dist/pregel/loop.js +536 -948
  269. package/dist/pregel/loop.js.map +1 -1
  270. package/dist/pregel/messages.cjs +104 -196
  271. package/dist/pregel/messages.cjs.map +1 -0
  272. package/dist/pregel/messages.js +102 -191
  273. package/dist/pregel/messages.js.map +1 -1
  274. package/dist/pregel/read.cjs +150 -280
  275. package/dist/pregel/read.cjs.map +1 -0
  276. package/dist/pregel/read.d.cts +51 -0
  277. package/dist/pregel/read.d.cts.map +1 -0
  278. package/dist/pregel/read.d.ts +48 -46
  279. package/dist/pregel/read.d.ts.map +1 -0
  280. package/dist/pregel/read.js +147 -274
  281. package/dist/pregel/read.js.map +1 -1
  282. package/dist/pregel/remote.cjs +339 -458
  283. package/dist/pregel/remote.cjs.map +1 -0
  284. package/dist/pregel/remote.d.cts +121 -0
  285. package/dist/pregel/remote.d.cts.map +1 -0
  286. package/dist/pregel/remote.d.ts +79 -69
  287. package/dist/pregel/remote.d.ts.map +1 -0
  288. package/dist/pregel/remote.js +337 -453
  289. package/dist/pregel/remote.js.map +1 -1
  290. package/dist/pregel/retry.cjs +87 -138
  291. package/dist/pregel/retry.cjs.map +1 -0
  292. package/dist/pregel/retry.js +83 -130
  293. package/dist/pregel/retry.js.map +1 -1
  294. package/dist/pregel/runnable_types.d.cts +25 -0
  295. package/dist/pregel/runnable_types.d.cts.map +1 -0
  296. package/dist/pregel/runnable_types.d.ts +22 -16
  297. package/dist/pregel/runnable_types.d.ts.map +1 -0
  298. package/dist/pregel/runner.cjs +222 -315
  299. package/dist/pregel/runner.cjs.map +1 -0
  300. package/dist/pregel/runner.js +219 -308
  301. package/dist/pregel/runner.js.map +1 -1
  302. package/dist/pregel/stream.cjs +89 -130
  303. package/dist/pregel/stream.cjs.map +1 -0
  304. package/dist/pregel/stream.js +87 -125
  305. package/dist/pregel/stream.js.map +1 -1
  306. package/dist/pregel/types.cjs +25 -62
  307. package/dist/pregel/types.cjs.map +1 -0
  308. package/dist/pregel/types.d.cts +437 -0
  309. package/dist/pregel/types.d.cts.map +1 -0
  310. package/dist/pregel/types.d.ts +377 -431
  311. package/dist/pregel/types.d.ts.map +1 -0
  312. package/dist/pregel/types.js +23 -57
  313. package/dist/pregel/types.js.map +1 -1
  314. package/dist/pregel/utils/config.cjs +100 -147
  315. package/dist/pregel/utils/config.cjs.map +1 -0
  316. package/dist/pregel/utils/config.d.cts +36 -0
  317. package/dist/pregel/utils/config.d.cts.map +1 -0
  318. package/dist/pregel/utils/config.d.ts +12 -9
  319. package/dist/pregel/utils/config.d.ts.map +1 -0
  320. package/dist/pregel/utils/config.js +98 -143
  321. package/dist/pregel/utils/config.js.map +1 -1
  322. package/dist/pregel/utils/index.cjs +87 -125
  323. package/dist/pregel/utils/index.cjs.map +1 -0
  324. package/dist/pregel/utils/index.d.cts +51 -0
  325. package/dist/pregel/utils/index.d.cts.map +1 -0
  326. package/dist/pregel/utils/index.d.ts +45 -61
  327. package/dist/pregel/utils/index.d.ts.map +1 -0
  328. package/dist/pregel/utils/index.js +86 -120
  329. package/dist/pregel/utils/index.js.map +1 -1
  330. package/dist/pregel/utils/subgraph.cjs +15 -26
  331. package/dist/pregel/utils/subgraph.cjs.map +1 -0
  332. package/dist/pregel/utils/subgraph.js +12 -21
  333. package/dist/pregel/utils/subgraph.js.map +1 -1
  334. package/dist/pregel/validate.cjs +42 -92
  335. package/dist/pregel/validate.cjs.map +1 -0
  336. package/dist/pregel/validate.js +39 -84
  337. package/dist/pregel/validate.js.map +1 -1
  338. package/dist/pregel/write.cjs +87 -137
  339. package/dist/pregel/write.cjs.map +1 -0
  340. package/dist/pregel/write.d.cts +35 -0
  341. package/dist/pregel/write.d.cts.map +1 -0
  342. package/dist/pregel/write.d.ts +27 -23
  343. package/dist/pregel/write.d.ts.map +1 -0
  344. package/dist/pregel/write.js +83 -131
  345. package/dist/pregel/write.js.map +1 -1
  346. package/dist/remote.cjs +3 -6
  347. package/dist/remote.d.cts +2 -0
  348. package/dist/remote.d.ts +2 -1
  349. package/dist/remote.js +3 -2
  350. package/dist/setup/async_local_storage.cjs +10 -7
  351. package/dist/setup/async_local_storage.cjs.map +1 -0
  352. package/dist/setup/async_local_storage.js +7 -2
  353. package/dist/setup/async_local_storage.js.map +1 -1
  354. package/dist/ui/index.cjs +4 -0
  355. package/dist/ui/index.d.cts +5 -0
  356. package/dist/ui/index.d.ts +5 -0
  357. package/dist/ui/index.js +3 -0
  358. package/dist/ui/stream.cjs +145 -0
  359. package/dist/ui/stream.cjs.map +1 -0
  360. package/dist/ui/stream.d.cts +25 -0
  361. package/dist/ui/stream.d.cts.map +1 -0
  362. package/dist/ui/stream.d.ts +25 -0
  363. package/dist/ui/stream.d.ts.map +1 -0
  364. package/dist/ui/stream.js +143 -0
  365. package/dist/ui/stream.js.map +1 -0
  366. package/dist/ui/types.infer.d.cts +53 -0
  367. package/dist/ui/types.infer.d.cts.map +1 -0
  368. package/dist/ui/types.infer.d.ts +53 -0
  369. package/dist/ui/types.infer.d.ts.map +1 -0
  370. package/dist/ui/types.message.d.cts +95 -0
  371. package/dist/ui/types.message.d.cts.map +1 -0
  372. package/dist/ui/types.message.d.ts +95 -0
  373. package/dist/ui/types.message.d.ts.map +1 -0
  374. package/dist/ui/types.schema.d.cts +228 -0
  375. package/dist/ui/types.schema.d.cts.map +1 -0
  376. package/dist/ui/types.schema.d.ts +228 -0
  377. package/dist/ui/types.schema.d.ts.map +1 -0
  378. package/dist/utils.cjs +77 -147
  379. package/dist/utils.cjs.map +1 -0
  380. package/dist/utils.d.cts +32 -0
  381. package/dist/utils.d.cts.map +1 -0
  382. package/dist/utils.d.ts +29 -25
  383. package/dist/utils.d.ts.map +1 -0
  384. package/dist/utils.js +73 -140
  385. package/dist/utils.js.map +1 -1
  386. package/dist/web.cjs +97 -55
  387. package/dist/web.d.cts +23 -0
  388. package/dist/web.d.ts +23 -14
  389. package/dist/web.js +15 -8
  390. package/package.json +83 -86
  391. package/dist/channels/any_value.cjs +0 -65
  392. package/dist/channels/any_value.js +0 -61
  393. package/dist/channels/any_value.js.map +0 -1
  394. package/dist/channels/dynamic_barrier_value.cjs +0 -212
  395. package/dist/channels/dynamic_barrier_value.js +0 -207
  396. package/dist/channels/dynamic_barrier_value.js.map +0 -1
  397. package/dist/channels/index.d.ts +0 -7
  398. package/dist/channels/index.js.map +0 -1
  399. package/dist/func/types.cjs +0 -15
  400. package/dist/func/types.js +0 -12
  401. package/dist/func/types.js.map +0 -1
  402. package/dist/graph/index.d.ts +0 -4
  403. package/dist/graph/index.js.map +0 -1
  404. package/dist/graph/message.test.cjs +0 -196
  405. package/dist/graph/message.test.d.ts +0 -1
  406. package/dist/graph/message.test.js +0 -194
  407. package/dist/graph/message.test.js.map +0 -1
  408. package/dist/graph/zod/index.js.map +0 -1
  409. package/dist/graph/zod/plugin.d.ts +0 -28
  410. package/dist/hash.d.ts +0 -2
  411. package/dist/prebuilt/index.js.map +0 -1
  412. package/dist/prebuilt/interrupt.cjs +0 -3
  413. package/dist/prebuilt/interrupt.js +0 -2
  414. package/dist/prebuilt/interrupt.js.map +0 -1
  415. package/dist/pregel/call.d.ts +0 -16
  416. package/dist/pregel/debug.d.ts +0 -41
  417. package/dist/pregel/debug.test.cjs +0 -258
  418. package/dist/pregel/debug.test.d.ts +0 -1
  419. package/dist/pregel/debug.test.js +0 -256
  420. package/dist/pregel/debug.test.js.map +0 -1
  421. package/dist/pregel/io.d.ts +0 -30
  422. package/dist/pregel/io.mapCommand.test.cjs +0 -150
  423. package/dist/pregel/io.mapCommand.test.d.ts +0 -1
  424. package/dist/pregel/io.mapCommand.test.js +0 -148
  425. package/dist/pregel/io.mapCommand.test.js.map +0 -1
  426. package/dist/pregel/loop.d.ts +0 -147
  427. package/dist/pregel/messages.d.ts +0 -30
  428. package/dist/pregel/messages.test.cjs +0 -369
  429. package/dist/pregel/messages.test.d.ts +0 -1
  430. package/dist/pregel/messages.test.js +0 -367
  431. package/dist/pregel/messages.test.js.map +0 -1
  432. package/dist/pregel/read.test.cjs +0 -194
  433. package/dist/pregel/read.test.d.ts +0 -1
  434. package/dist/pregel/read.test.js +0 -192
  435. package/dist/pregel/read.test.js.map +0 -1
  436. package/dist/pregel/retry.d.ts +0 -17
  437. package/dist/pregel/runnable_types.cjs +0 -3
  438. package/dist/pregel/runnable_types.js +0 -2
  439. package/dist/pregel/runnable_types.js.map +0 -1
  440. package/dist/pregel/runner.d.ts +0 -79
  441. package/dist/pregel/runner.test.cjs +0 -66
  442. package/dist/pregel/runner.test.d.ts +0 -1
  443. package/dist/pregel/runner.test.js +0 -64
  444. package/dist/pregel/runner.test.js.map +0 -1
  445. package/dist/pregel/stream.d.ts +0 -40
  446. package/dist/pregel/utils/config.test.cjs +0 -214
  447. package/dist/pregel/utils/config.test.d.ts +0 -1
  448. package/dist/pregel/utils/config.test.js +0 -212
  449. package/dist/pregel/utils/config.test.js.map +0 -1
  450. package/dist/pregel/utils/subgraph.d.ts +0 -4
  451. package/dist/pregel/utils/subgraph.test.cjs +0 -83
  452. package/dist/pregel/utils/subgraph.test.d.ts +0 -1
  453. package/dist/pregel/utils/subgraph.test.js +0 -81
  454. package/dist/pregel/utils/subgraph.test.js.map +0 -1
  455. package/dist/pregel/validate.d.ts +0 -16
  456. package/dist/pregel/validate.test.cjs +0 -220
  457. package/dist/pregel/validate.test.d.ts +0 -1
  458. package/dist/pregel/validate.test.js +0 -218
  459. package/dist/pregel/validate.test.js.map +0 -1
  460. package/dist/pregel/write.test.cjs +0 -181
  461. package/dist/pregel/write.test.d.ts +0 -1
  462. package/dist/pregel/write.test.js +0 -179
  463. package/dist/pregel/write.test.js.map +0 -1
  464. package/dist/remote.js.map +0 -1
  465. package/dist/setup/async_local_storage.d.ts +0 -1
  466. package/dist/web.js.map +0 -1
  467. package/index.cjs +0 -1
  468. package/index.d.cts +0 -1
  469. package/index.d.ts +0 -1
  470. package/index.js +0 -1
  471. package/prebuilt.cjs +0 -1
  472. package/prebuilt.d.cts +0 -1
  473. package/prebuilt.d.ts +0 -1
  474. package/prebuilt.js +0 -1
  475. package/pregel.cjs +0 -1
  476. package/pregel.d.cts +0 -1
  477. package/pregel.d.ts +0 -1
  478. package/pregel.js +0 -1
  479. package/remote.cjs +0 -1
  480. package/remote.d.cts +0 -1
  481. package/remote.d.ts +0 -1
  482. package/remote.js +0 -1
  483. package/web.cjs +0 -1
  484. package/web.d.cts +0 -1
  485. package/web.d.ts +0 -1
  486. package/web.js +0 -1
  487. package/zod/schema.cjs +0 -1
  488. package/zod/schema.d.cts +0 -1
  489. package/zod/schema.d.ts +0 -1
  490. package/zod/schema.js +0 -1
  491. package/zod.cjs +0 -1
  492. package/zod.d.cts +0 -1
  493. package/zod.d.ts +0 -1
  494. package/zod.js +0 -1
@@ -1,500 +1,344 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createReactAgentAnnotation = void 0;
4
- exports._shouldBindTools = _shouldBindTools;
5
- exports._bindTools = _bindTools;
6
- exports._getModel = _getModel;
7
- exports.createReactAgent = createReactAgent;
8
- const messages_1 = require("@langchain/core/messages");
9
- const runnables_1 = require("@langchain/core/runnables");
10
- const index_js_1 = require("../graph/index.cjs");
11
- const tool_node_js_1 = require("./tool_node.cjs");
12
- const annotation_js_1 = require("../graph/annotation.cjs");
13
- const message_js_1 = require("../graph/message.cjs");
14
- const constants_js_1 = require("../constants.cjs");
15
- const agentName_js_1 = require("./agentName.cjs");
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_annotation = require('../graph/annotation.cjs');
3
+ const require_constants = require('../constants.cjs');
4
+ const require_state = require('../graph/state.cjs');
5
+ const require_message = require('../graph/message.cjs');
6
+ require('../graph/index.cjs');
7
+ const require_tool_node = require('./tool_node.cjs');
8
+ const require_agentName = require('./agentName.cjs');
9
+ const __langchain_core_runnables = require_rolldown_runtime.__toESM(require("@langchain/core/runnables"));
10
+ const __langchain_core_messages = require_rolldown_runtime.__toESM(require("@langchain/core/messages"));
11
+
12
+ //#region src/prebuilt/react_agent_executor.ts
16
13
  function _convertMessageModifierToPrompt(messageModifier) {
17
- // Handle string or SystemMessage
18
- if (typeof messageModifier === "string" ||
19
- ((0, messages_1.isBaseMessage)(messageModifier) && messageModifier._getType() === "system")) {
20
- return messageModifier;
21
- }
22
- // Handle callable function
23
- if (typeof messageModifier === "function") {
24
- return async (state) => messageModifier(state.messages);
25
- }
26
- // Handle Runnable
27
- if (runnables_1.Runnable.isRunnable(messageModifier)) {
28
- return runnables_1.RunnableLambda.from((state) => state.messages).pipe(messageModifier);
29
- }
30
- throw new Error(`Unexpected type for messageModifier: ${typeof messageModifier}`);
14
+ if (typeof messageModifier === "string" || (0, __langchain_core_messages.isBaseMessage)(messageModifier) && messageModifier._getType() === "system") return messageModifier;
15
+ if (typeof messageModifier === "function") return async (state) => messageModifier(state.messages);
16
+ if (__langchain_core_runnables.Runnable.isRunnable(messageModifier)) return __langchain_core_runnables.RunnableLambda.from((state) => state.messages).pipe(messageModifier);
17
+ throw new Error(`Unexpected type for messageModifier: ${typeof messageModifier}`);
31
18
  }
32
19
  const PROMPT_RUNNABLE_NAME = "prompt";
33
20
  function _getPromptRunnable(prompt) {
34
- let promptRunnable;
35
- if (prompt == null) {
36
- promptRunnable = runnables_1.RunnableLambda.from((state) => state.messages).withConfig({ runName: PROMPT_RUNNABLE_NAME });
37
- }
38
- else if (typeof prompt === "string") {
39
- const systemMessage = new messages_1.SystemMessage(prompt);
40
- promptRunnable = runnables_1.RunnableLambda.from((state) => {
41
- return [systemMessage, ...(state.messages ?? [])];
42
- }).withConfig({ runName: PROMPT_RUNNABLE_NAME });
43
- }
44
- else if ((0, messages_1.isBaseMessage)(prompt) && prompt._getType() === "system") {
45
- promptRunnable = runnables_1.RunnableLambda.from((state) => [prompt, ...state.messages]).withConfig({ runName: PROMPT_RUNNABLE_NAME });
46
- }
47
- else if (typeof prompt === "function") {
48
- promptRunnable = runnables_1.RunnableLambda.from(prompt).withConfig({
49
- runName: PROMPT_RUNNABLE_NAME,
50
- });
51
- }
52
- else if (runnables_1.Runnable.isRunnable(prompt)) {
53
- promptRunnable = prompt;
54
- }
55
- else {
56
- throw new Error(`Got unexpected type for 'prompt': ${typeof prompt}`);
57
- }
58
- return promptRunnable;
21
+ let promptRunnable;
22
+ if (prompt == null) promptRunnable = __langchain_core_runnables.RunnableLambda.from((state) => state.messages).withConfig({ runName: PROMPT_RUNNABLE_NAME });
23
+ else if (typeof prompt === "string") {
24
+ const systemMessage = new __langchain_core_messages.SystemMessage(prompt);
25
+ promptRunnable = __langchain_core_runnables.RunnableLambda.from((state) => {
26
+ return [systemMessage, ...state.messages ?? []];
27
+ }).withConfig({ runName: PROMPT_RUNNABLE_NAME });
28
+ } else if ((0, __langchain_core_messages.isBaseMessage)(prompt) && prompt._getType() === "system") promptRunnable = __langchain_core_runnables.RunnableLambda.from((state) => [prompt, ...state.messages]).withConfig({ runName: PROMPT_RUNNABLE_NAME });
29
+ else if (typeof prompt === "function") promptRunnable = __langchain_core_runnables.RunnableLambda.from(prompt).withConfig({ runName: PROMPT_RUNNABLE_NAME });
30
+ else if (__langchain_core_runnables.Runnable.isRunnable(prompt)) promptRunnable = prompt;
31
+ else throw new Error(`Got unexpected type for 'prompt': ${typeof prompt}`);
32
+ return promptRunnable;
59
33
  }
60
34
  function isClientTool(tool) {
61
- return runnables_1.Runnable.isRunnable(tool);
35
+ return __langchain_core_runnables.Runnable.isRunnable(tool);
62
36
  }
63
37
  function _getPrompt(prompt, stateModifier, messageModifier) {
64
- // Check if multiple modifiers exist
65
- const definedCount = [prompt, stateModifier, messageModifier].filter((x) => x != null).length;
66
- if (definedCount > 1) {
67
- throw new Error("Expected only one of prompt, stateModifier, or messageModifier, got multiple values");
68
- }
69
- let finalPrompt = prompt;
70
- if (stateModifier != null) {
71
- finalPrompt = stateModifier;
72
- }
73
- else if (messageModifier != null) {
74
- finalPrompt = _convertMessageModifierToPrompt(messageModifier);
75
- }
76
- return _getPromptRunnable(finalPrompt);
38
+ const definedCount = [
39
+ prompt,
40
+ stateModifier,
41
+ messageModifier
42
+ ].filter((x) => x != null).length;
43
+ if (definedCount > 1) throw new Error("Expected only one of prompt, stateModifier, or messageModifier, got multiple values");
44
+ let finalPrompt = prompt;
45
+ if (stateModifier != null) finalPrompt = stateModifier;
46
+ else if (messageModifier != null) finalPrompt = _convertMessageModifierToPrompt(messageModifier);
47
+ return _getPromptRunnable(finalPrompt);
77
48
  }
78
49
  function _isBaseChatModel(model) {
79
- return ("invoke" in model &&
80
- typeof model.invoke === "function" &&
81
- "_modelType" in model);
50
+ return "invoke" in model && typeof model.invoke === "function" && "_modelType" in model;
82
51
  }
83
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
52
  function _isConfigurableModel(model) {
85
- return ("_queuedMethodOperations" in model &&
86
- "_model" in model &&
87
- typeof model._model === "function");
53
+ return "_queuedMethodOperations" in model && "_model" in model && typeof model._model === "function";
88
54
  }
89
55
  function _isChatModelWithBindTools(llm) {
90
- if (!_isBaseChatModel(llm))
91
- return false;
92
- return "bindTools" in llm && typeof llm.bindTools === "function";
56
+ if (!_isBaseChatModel(llm)) return false;
57
+ return "bindTools" in llm && typeof llm.bindTools === "function";
93
58
  }
94
59
  async function _shouldBindTools(llm, tools) {
95
- // If model is a RunnableSequence, find a RunnableBinding or BaseChatModel in its steps
96
- let model = llm;
97
- if (runnables_1.RunnableSequence.isRunnableSequence(model)) {
98
- model =
99
- model.steps.find((step) => runnables_1.RunnableBinding.isRunnableBinding(step) ||
100
- _isBaseChatModel(step) ||
101
- _isConfigurableModel(step)) || model;
102
- }
103
- if (_isConfigurableModel(model)) {
104
- model = await model._model();
105
- }
106
- // If not a RunnableBinding, we should bind tools
107
- if (!runnables_1.RunnableBinding.isRunnableBinding(model)) {
108
- return true;
109
- }
110
- let boundTools = (() => {
111
- // check if model.kwargs contain the tools key
112
- if (model.kwargs != null &&
113
- typeof model.kwargs === "object" &&
114
- "tools" in model.kwargs &&
115
- Array.isArray(model.kwargs.tools)) {
116
- return (model.kwargs.tools ?? null);
117
- }
118
- // Some models can bind the tools via `withConfig()` instead of `bind()`
119
- if (model.config != null &&
120
- typeof model.config === "object" &&
121
- "tools" in model.config &&
122
- Array.isArray(model.config.tools)) {
123
- return (model.config.tools ?? null);
124
- }
125
- return null;
126
- })();
127
- // google-style
128
- if (boundTools != null &&
129
- boundTools.length === 1 &&
130
- "functionDeclarations" in boundTools[0]) {
131
- boundTools = boundTools[0].functionDeclarations;
132
- }
133
- // If no tools in kwargs, we should bind tools
134
- if (boundTools == null)
135
- return true;
136
- // Check if tools count matches
137
- if (tools.length !== boundTools.length) {
138
- throw new Error("Number of tools in the model.bindTools() and tools passed to createReactAgent must match");
139
- }
140
- const toolNames = new Set(tools.flatMap((tool) => (isClientTool(tool) ? tool.name : [])));
141
- const boundToolNames = new Set();
142
- for (const boundTool of boundTools) {
143
- let boundToolName;
144
- // OpenAI-style tool
145
- if ("type" in boundTool && boundTool.type === "function") {
146
- boundToolName = boundTool.function.name;
147
- }
148
- // Anthropic or Google-style tool
149
- else if ("name" in boundTool) {
150
- boundToolName = boundTool.name;
151
- }
152
- // Bedrock-style tool
153
- else if ("toolSpec" in boundTool && "name" in boundTool.toolSpec) {
154
- boundToolName = boundTool.toolSpec.name;
155
- }
156
- // unknown tool type so we'll ignore it
157
- else {
158
- continue;
159
- }
160
- if (boundToolName) {
161
- boundToolNames.add(boundToolName);
162
- }
163
- }
164
- const missingTools = [...toolNames].filter((x) => !boundToolNames.has(x));
165
- if (missingTools.length > 0) {
166
- throw new Error(`Missing tools '${missingTools}' in the model.bindTools().` +
167
- `Tools in the model.bindTools() must match the tools passed to createReactAgent.`);
168
- }
169
- return false;
60
+ let model = llm;
61
+ if (__langchain_core_runnables.RunnableSequence.isRunnableSequence(model)) model = model.steps.find((step) => __langchain_core_runnables.RunnableBinding.isRunnableBinding(step) || _isBaseChatModel(step) || _isConfigurableModel(step)) || model;
62
+ if (_isConfigurableModel(model)) model = await model._model();
63
+ if (!__langchain_core_runnables.RunnableBinding.isRunnableBinding(model)) return true;
64
+ let boundTools = (() => {
65
+ if (model.kwargs != null && typeof model.kwargs === "object" && "tools" in model.kwargs && Array.isArray(model.kwargs.tools)) return model.kwargs.tools ?? null;
66
+ if (model.config != null && typeof model.config === "object" && "tools" in model.config && Array.isArray(model.config.tools)) return model.config.tools ?? null;
67
+ return null;
68
+ })();
69
+ if (boundTools != null && boundTools.length === 1 && "functionDeclarations" in boundTools[0]) boundTools = boundTools[0].functionDeclarations;
70
+ if (boundTools == null) return true;
71
+ if (tools.length !== boundTools.length) throw new Error("Number of tools in the model.bindTools() and tools passed to createReactAgent must match");
72
+ const toolNames = new Set(tools.flatMap((tool) => isClientTool(tool) ? tool.name : []));
73
+ const boundToolNames = /* @__PURE__ */ new Set();
74
+ for (const boundTool of boundTools) {
75
+ let boundToolName;
76
+ if ("type" in boundTool && boundTool.type === "function") boundToolName = boundTool.function.name;
77
+ else if ("name" in boundTool) boundToolName = boundTool.name;
78
+ else if ("toolSpec" in boundTool && "name" in boundTool.toolSpec) boundToolName = boundTool.toolSpec.name;
79
+ else continue;
80
+ if (boundToolName) boundToolNames.add(boundToolName);
81
+ }
82
+ const missingTools = [...toolNames].filter((x) => !boundToolNames.has(x));
83
+ 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.`);
84
+ return false;
170
85
  }
171
86
  const _simpleBindTools = (llm, toolClasses) => {
172
- if (_isChatModelWithBindTools(llm)) {
173
- return llm.bindTools(toolClasses);
174
- }
175
- if (runnables_1.RunnableBinding.isRunnableBinding(llm) &&
176
- _isChatModelWithBindTools(llm.bound)) {
177
- const newBound = llm.bound.bindTools(toolClasses);
178
- if (runnables_1.RunnableBinding.isRunnableBinding(newBound)) {
179
- return new runnables_1.RunnableBinding({
180
- bound: newBound.bound,
181
- config: { ...llm.config, ...newBound.config },
182
- kwargs: { ...llm.kwargs, ...newBound.kwargs },
183
- configFactories: newBound.configFactories ?? llm.configFactories,
184
- });
185
- }
186
- return new runnables_1.RunnableBinding({
187
- bound: newBound,
188
- config: llm.config,
189
- kwargs: llm.kwargs,
190
- configFactories: llm.configFactories,
191
- });
192
- }
193
- return null;
87
+ if (_isChatModelWithBindTools(llm)) return llm.bindTools(toolClasses);
88
+ if (__langchain_core_runnables.RunnableBinding.isRunnableBinding(llm) && _isChatModelWithBindTools(llm.bound)) {
89
+ const newBound = llm.bound.bindTools(toolClasses);
90
+ if (__langchain_core_runnables.RunnableBinding.isRunnableBinding(newBound)) return new __langchain_core_runnables.RunnableBinding({
91
+ bound: newBound.bound,
92
+ config: {
93
+ ...llm.config,
94
+ ...newBound.config
95
+ },
96
+ kwargs: {
97
+ ...llm.kwargs,
98
+ ...newBound.kwargs
99
+ },
100
+ configFactories: newBound.configFactories ?? llm.configFactories
101
+ });
102
+ return new __langchain_core_runnables.RunnableBinding({
103
+ bound: newBound,
104
+ config: llm.config,
105
+ kwargs: llm.kwargs,
106
+ configFactories: llm.configFactories
107
+ });
108
+ }
109
+ return null;
194
110
  };
195
111
  async function _bindTools(llm, toolClasses) {
196
- const model = _simpleBindTools(llm, toolClasses);
197
- if (model)
198
- return model;
199
- if (_isConfigurableModel(llm)) {
200
- const model = _simpleBindTools(await llm._model(), toolClasses);
201
- if (model)
202
- return model;
203
- }
204
- if (runnables_1.RunnableSequence.isRunnableSequence(llm)) {
205
- const modelStep = llm.steps.findIndex((step) => runnables_1.RunnableBinding.isRunnableBinding(step) ||
206
- _isBaseChatModel(step) ||
207
- _isConfigurableModel(step));
208
- if (modelStep >= 0) {
209
- const model = _simpleBindTools(llm.steps[modelStep], toolClasses);
210
- if (model) {
211
- const nextSteps = llm.steps.slice();
212
- nextSteps.splice(modelStep, 1, model);
213
- return runnables_1.RunnableSequence.from(nextSteps);
214
- }
215
- }
216
- }
217
- throw new Error(`llm ${llm} must define bindTools method.`);
112
+ const model = _simpleBindTools(llm, toolClasses);
113
+ if (model) return model;
114
+ if (_isConfigurableModel(llm)) {
115
+ const model$1 = _simpleBindTools(await llm._model(), toolClasses);
116
+ if (model$1) return model$1;
117
+ }
118
+ if (__langchain_core_runnables.RunnableSequence.isRunnableSequence(llm)) {
119
+ const modelStep = llm.steps.findIndex((step) => __langchain_core_runnables.RunnableBinding.isRunnableBinding(step) || _isBaseChatModel(step) || _isConfigurableModel(step));
120
+ if (modelStep >= 0) {
121
+ const model$1 = _simpleBindTools(llm.steps[modelStep], toolClasses);
122
+ if (model$1) {
123
+ const nextSteps = llm.steps.slice();
124
+ nextSteps.splice(modelStep, 1, model$1);
125
+ return __langchain_core_runnables.RunnableSequence.from(nextSteps);
126
+ }
127
+ }
128
+ }
129
+ throw new Error(`llm ${llm} must define bindTools method.`);
218
130
  }
219
131
  async function _getModel(llm) {
220
- // If model is a RunnableSequence, find a RunnableBinding or BaseChatModel in its steps
221
- let model = llm;
222
- if (runnables_1.RunnableSequence.isRunnableSequence(model)) {
223
- model =
224
- model.steps.find((step) => runnables_1.RunnableBinding.isRunnableBinding(step) ||
225
- _isBaseChatModel(step) ||
226
- _isConfigurableModel(step)) || model;
227
- }
228
- if (_isConfigurableModel(model)) {
229
- model = await model._model();
230
- }
231
- // Get the underlying model from a RunnableBinding
232
- if (runnables_1.RunnableBinding.isRunnableBinding(model)) {
233
- model = model.bound;
234
- }
235
- if (!_isBaseChatModel(model)) {
236
- 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}`);
237
- }
238
- return model;
132
+ let model = llm;
133
+ if (__langchain_core_runnables.RunnableSequence.isRunnableSequence(model)) model = model.steps.find((step) => __langchain_core_runnables.RunnableBinding.isRunnableBinding(step) || _isBaseChatModel(step) || _isConfigurableModel(step)) || model;
134
+ if (_isConfigurableModel(model)) model = await model._model();
135
+ if (__langchain_core_runnables.RunnableBinding.isRunnableBinding(model)) model = model.bound;
136
+ 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}`);
137
+ return model;
239
138
  }
240
- const createReactAgentAnnotation = () => annotation_js_1.Annotation.Root({
241
- messages: (0, annotation_js_1.Annotation)({
242
- reducer: message_js_1.messagesStateReducer,
243
- default: () => [],
244
- }),
245
- structuredResponse: (annotation_js_1.Annotation),
246
- });
247
- exports.createReactAgentAnnotation = createReactAgentAnnotation;
248
- const PreHookAnnotation = annotation_js_1.Annotation.Root({
249
- llmInputMessages: (0, annotation_js_1.Annotation)({
250
- reducer: (_, update) => (0, message_js_1.messagesStateReducer)([], update),
251
- default: () => [],
252
- }),
139
+ const createReactAgentAnnotation = () => require_annotation.Annotation.Root({
140
+ messages: require_annotation.Annotation({
141
+ reducer: require_message.messagesStateReducer,
142
+ default: () => []
143
+ }),
144
+ structuredResponse: require_annotation.Annotation
253
145
  });
146
+ const PreHookAnnotation = require_annotation.Annotation.Root({ llmInputMessages: require_annotation.Annotation({
147
+ reducer: (_, update) => require_message.messagesStateReducer([], update),
148
+ default: () => []
149
+ }) });
254
150
  /**
255
- * Creates a StateGraph agent that relies on a chat model utilizing tool calling.
256
- *
257
- * @example
258
- * ```ts
259
- * import { ChatOpenAI } from "@langchain/openai";
260
- * import { tool } from "@langchain/core/tools";
261
- * import { z } from "zod";
262
- * import { createReactAgent } from "@langchain/langgraph/prebuilt";
263
- *
264
- * const model = new ChatOpenAI({
265
- * model: "gpt-4o",
266
- * });
267
- *
268
- * const getWeather = tool((input) => {
269
- * if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
270
- * return "It's 60 degrees and foggy.";
271
- * } else {
272
- * return "It's 90 degrees and sunny.";
273
- * }
274
- * }, {
275
- * name: "get_weather",
276
- * description: "Call to get the current weather.",
277
- * schema: z.object({
278
- * location: z.string().describe("Location to get the weather for."),
279
- * })
280
- * })
281
- *
282
- * const agent = createReactAgent({ llm: model, tools: [getWeather] });
283
- *
284
- * const inputs = {
285
- * messages: [{ role: "user", content: "what is the weather in SF?" }],
286
- * };
287
- *
288
- * const stream = await agent.stream(inputs, { streamMode: "values" });
289
- *
290
- * for await (const { messages } of stream) {
291
- * console.log(messages);
292
- * }
293
- * // Returns the messages in the state at each step of execution
294
- * ```
295
- */
151
+ * @deprecated `createReactAgent` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.
152
+ * Update your import to `import { createReactAgent } from "langchain";`
153
+ *
154
+ * Creates a StateGraph agent that relies on a chat model utilizing tool calling.
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * import { ChatOpenAI } from "@langchain/openai";
159
+ * import { tool } from "@langchain/core/tools";
160
+ * import { z } from "zod";
161
+ * import { createReactAgent } from "@langchain/langgraph/prebuilt";
162
+ *
163
+ * const model = new ChatOpenAI({
164
+ * model: "gpt-4o",
165
+ * });
166
+ *
167
+ * const getWeather = tool((input) => {
168
+ * if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
169
+ * return "It's 60 degrees and foggy.";
170
+ * } else {
171
+ * return "It's 90 degrees and sunny.";
172
+ * }
173
+ * }, {
174
+ * name: "get_weather",
175
+ * description: "Call to get the current weather.",
176
+ * schema: z.object({
177
+ * location: z.string().describe("Location to get the weather for."),
178
+ * })
179
+ * })
180
+ *
181
+ * const agent = createReactAgent({ llm: model, tools: [getWeather] });
182
+ *
183
+ * const inputs = {
184
+ * messages: [{ role: "user", content: "what is the weather in SF?" }],
185
+ * };
186
+ *
187
+ * const stream = await agent.stream(inputs, { streamMode: "values" });
188
+ *
189
+ * for await (const { messages } of stream) {
190
+ * console.log(messages);
191
+ * }
192
+ * // Returns the messages in the state at each step of execution
193
+ * ```
194
+ */
296
195
  function createReactAgent(params) {
297
- const { llm, tools, messageModifier, stateModifier, prompt, stateSchema, contextSchema, checkpointSaver, checkpointer, interruptBefore, interruptAfter, store, responseFormat, preModelHook, postModelHook, name, description, version = "v1", includeAgentName, } = params;
298
- let toolClasses;
299
- let toolNode;
300
- if (!Array.isArray(tools)) {
301
- toolClasses = tools.tools;
302
- toolNode = tools;
303
- }
304
- else {
305
- toolClasses = tools;
306
- toolNode = new tool_node_js_1.ToolNode(toolClasses.filter(isClientTool));
307
- }
308
- let cachedStaticModel = null;
309
- const _getStaticModel = async (llm) => {
310
- if (cachedStaticModel)
311
- return cachedStaticModel;
312
- let modelWithTools;
313
- if (await _shouldBindTools(llm, toolClasses)) {
314
- modelWithTools = await _bindTools(llm, toolClasses);
315
- }
316
- else {
317
- modelWithTools = llm;
318
- }
319
- const promptRunnable = _getPrompt(prompt, stateModifier, messageModifier);
320
- const modelRunnable = includeAgentName === "inline"
321
- ? (0, agentName_js_1.withAgentName)(modelWithTools, includeAgentName)
322
- : modelWithTools;
323
- cachedStaticModel = promptRunnable.pipe(modelRunnable);
324
- return cachedStaticModel;
325
- };
326
- const _getDynamicModel = async (llm, state, config) => {
327
- const model = await llm(state, config);
328
- return _getPrompt(prompt, stateModifier, messageModifier).pipe(includeAgentName === "inline"
329
- ? (0, agentName_js_1.withAgentName)(model, includeAgentName)
330
- : model);
331
- };
332
- // If any of the tools are configured to return_directly after running,
333
- // our graph needs to check if these were called
334
- const shouldReturnDirect = new Set(toolClasses
335
- .filter(isClientTool)
336
- .filter((tool) => "returnDirect" in tool && tool.returnDirect)
337
- .map((tool) => tool.name));
338
- function getModelInputState(state) {
339
- const { messages, llmInputMessages, ...rest } = state;
340
- if (llmInputMessages != null && llmInputMessages.length > 0) {
341
- return { messages: llmInputMessages, ...rest };
342
- }
343
- return { messages, ...rest };
344
- }
345
- const generateStructuredResponse = async (state, config) => {
346
- if (responseFormat == null) {
347
- throw new Error("Attempted to generate structured output with no passed response schema. Please contact us for help.");
348
- }
349
- const messages = [...state.messages];
350
- let modelWithStructuredOutput;
351
- const model = typeof llm === "function"
352
- ? await llm(state, config)
353
- : await _getModel(llm);
354
- if (!_isBaseChatModel(model)) {
355
- throw new Error(`Expected \`llm\` to be a ChatModel with .withStructuredOutput() method, got ${model.constructor.name}`);
356
- }
357
- if (typeof responseFormat === "object" && "schema" in responseFormat) {
358
- const { prompt, schema, ...options } = responseFormat;
359
- modelWithStructuredOutput = model.withStructuredOutput(schema, options);
360
- if (prompt != null) {
361
- messages.unshift(new messages_1.SystemMessage({ content: prompt }));
362
- }
363
- }
364
- else {
365
- modelWithStructuredOutput = model.withStructuredOutput(responseFormat);
366
- }
367
- const response = await modelWithStructuredOutput.invoke(messages, config);
368
- return { structuredResponse: response };
369
- };
370
- const callModel = async (state, config) => {
371
- // NOTE: we're dynamically creating the model runnable here
372
- // to ensure that we can validate ConfigurableModel properly
373
- const modelRunnable = typeof llm === "function"
374
- ? await _getDynamicModel(llm, state, config)
375
- : await _getStaticModel(llm);
376
- // TODO: Auto-promote streaming.
377
- const response = (await modelRunnable.invoke(getModelInputState(state), config));
378
- // add agent name to the AIMessage
379
- // TODO: figure out if we can avoid mutating the message directly
380
- response.name = name;
381
- response.lc_kwargs.name = name;
382
- return { messages: [response] };
383
- };
384
- const schema = stateSchema ?? (0, exports.createReactAgentAnnotation)();
385
- const workflow = new index_js_1.StateGraph(schema, contextSchema).addNode("tools", toolNode);
386
- if (!("messages" in workflow._schemaDefinition)) {
387
- throw new Error("Missing required `messages` key in state schema.");
388
- }
389
- const allNodeWorkflows = workflow;
390
- const conditionalMap = (map) => {
391
- return Object.fromEntries(Object.entries(map).filter(([_, v]) => v != null));
392
- };
393
- let entrypoint = "agent";
394
- let inputSchema;
395
- if (preModelHook != null) {
396
- allNodeWorkflows
397
- .addNode("pre_model_hook", preModelHook)
398
- .addEdge("pre_model_hook", "agent");
399
- entrypoint = "pre_model_hook";
400
- inputSchema = annotation_js_1.Annotation.Root({
401
- ...workflow._schemaDefinition,
402
- ...PreHookAnnotation.spec,
403
- });
404
- }
405
- else {
406
- entrypoint = "agent";
407
- }
408
- allNodeWorkflows
409
- .addNode("agent", callModel, { input: inputSchema })
410
- .addEdge(constants_js_1.START, entrypoint);
411
- if (postModelHook != null) {
412
- allNodeWorkflows
413
- .addNode("post_model_hook", postModelHook)
414
- .addEdge("agent", "post_model_hook")
415
- .addConditionalEdges("post_model_hook", (state) => {
416
- const { messages } = state;
417
- const toolMessageIds = new Set(messages.filter(messages_1.isToolMessage).map((msg) => msg.tool_call_id));
418
- let lastAiMessage;
419
- for (let i = messages.length - 1; i >= 0; i -= 1) {
420
- const message = messages[i];
421
- if ((0, messages_1.isAIMessage)(message)) {
422
- lastAiMessage = message;
423
- break;
424
- }
425
- }
426
- const pendingToolCalls = lastAiMessage?.tool_calls?.filter((i) => i.id == null || !toolMessageIds.has(i.id)) ?? [];
427
- const lastMessage = messages.at(-1);
428
- if (pendingToolCalls.length > 0) {
429
- if (version === "v2") {
430
- return pendingToolCalls.map((toolCall) => new constants_js_1.Send("tools", { ...state, lg_tool_call: toolCall }));
431
- }
432
- return "tools";
433
- }
434
- if (lastMessage && (0, messages_1.isToolMessage)(lastMessage))
435
- return entrypoint;
436
- if (responseFormat != null)
437
- return "generate_structured_response";
438
- return constants_js_1.END;
439
- }, conditionalMap({
440
- tools: "tools",
441
- [entrypoint]: entrypoint,
442
- generate_structured_response: responseFormat != null ? "generate_structured_response" : null,
443
- [constants_js_1.END]: responseFormat != null ? null : constants_js_1.END,
444
- }));
445
- }
446
- if (responseFormat !== undefined) {
447
- workflow
448
- .addNode("generate_structured_response", generateStructuredResponse)
449
- .addEdge("generate_structured_response", constants_js_1.END);
450
- }
451
- if (postModelHook == null) {
452
- allNodeWorkflows.addConditionalEdges("agent", (state) => {
453
- const { messages } = state;
454
- const lastMessage = messages[messages.length - 1];
455
- // if there's no function call, we finish
456
- if (!(0, messages_1.isAIMessage)(lastMessage) || !lastMessage.tool_calls?.length) {
457
- if (responseFormat != null)
458
- return "generate_structured_response";
459
- return constants_js_1.END;
460
- }
461
- // there are function calls, we continue
462
- if (version === "v2") {
463
- return lastMessage.tool_calls.map((toolCall) => new constants_js_1.Send("tools", { ...state, lg_tool_call: toolCall }));
464
- }
465
- return "tools";
466
- }, conditionalMap({
467
- tools: "tools",
468
- generate_structured_response: responseFormat != null ? "generate_structured_response" : null,
469
- [constants_js_1.END]: responseFormat != null ? null : constants_js_1.END,
470
- }));
471
- }
472
- if (shouldReturnDirect.size > 0) {
473
- allNodeWorkflows.addConditionalEdges("tools", (state) => {
474
- // Check the last consecutive tool calls
475
- for (let i = state.messages.length - 1; i >= 0; i -= 1) {
476
- const message = state.messages[i];
477
- if (!(0, messages_1.isToolMessage)(message))
478
- break;
479
- // Check if this tool is configured to return directly
480
- if (message.name !== undefined &&
481
- shouldReturnDirect.has(message.name)) {
482
- return constants_js_1.END;
483
- }
484
- }
485
- return entrypoint;
486
- }, conditionalMap({ [entrypoint]: entrypoint, [constants_js_1.END]: constants_js_1.END }));
487
- }
488
- else {
489
- allNodeWorkflows.addEdge("tools", entrypoint);
490
- }
491
- return allNodeWorkflows.compile({
492
- checkpointer: checkpointer ?? checkpointSaver,
493
- interruptBefore,
494
- interruptAfter,
495
- store,
496
- name,
497
- description,
498
- });
196
+ const { llm, tools, messageModifier, stateModifier, prompt, stateSchema, contextSchema, checkpointSaver, checkpointer, interruptBefore, interruptAfter, store, responseFormat, preModelHook, postModelHook, name, description, version = "v1", includeAgentName } = params;
197
+ let toolClasses;
198
+ let toolNode;
199
+ if (!Array.isArray(tools)) {
200
+ toolClasses = tools.tools;
201
+ toolNode = tools;
202
+ } else {
203
+ toolClasses = tools;
204
+ toolNode = new require_tool_node.ToolNode(toolClasses.filter(isClientTool));
205
+ }
206
+ let cachedStaticModel = null;
207
+ const _getStaticModel = async (llm$1) => {
208
+ if (cachedStaticModel) return cachedStaticModel;
209
+ let modelWithTools;
210
+ if (await _shouldBindTools(llm$1, toolClasses)) modelWithTools = await _bindTools(llm$1, toolClasses);
211
+ else modelWithTools = llm$1;
212
+ const promptRunnable = _getPrompt(prompt, stateModifier, messageModifier);
213
+ const modelRunnable = includeAgentName === "inline" ? require_agentName.withAgentName(modelWithTools, includeAgentName) : modelWithTools;
214
+ cachedStaticModel = promptRunnable.pipe(modelRunnable);
215
+ return cachedStaticModel;
216
+ };
217
+ const _getDynamicModel = async (llm$1, state, config) => {
218
+ const model = await llm$1(state, config);
219
+ return _getPrompt(prompt, stateModifier, messageModifier).pipe(includeAgentName === "inline" ? require_agentName.withAgentName(model, includeAgentName) : model);
220
+ };
221
+ const shouldReturnDirect = new Set(toolClasses.filter(isClientTool).filter((tool) => "returnDirect" in tool && tool.returnDirect).map((tool) => tool.name));
222
+ function getModelInputState(state) {
223
+ const { messages, llmInputMessages,...rest } = state;
224
+ if (llmInputMessages != null && llmInputMessages.length > 0) return {
225
+ messages: llmInputMessages,
226
+ ...rest
227
+ };
228
+ return {
229
+ messages,
230
+ ...rest
231
+ };
232
+ }
233
+ const generateStructuredResponse = async (state, config) => {
234
+ if (responseFormat == null) throw new Error("Attempted to generate structured output with no passed response schema. Please contact us for help.");
235
+ const messages = [...state.messages];
236
+ let modelWithStructuredOutput;
237
+ const model = typeof llm === "function" ? await llm(state, config) : await _getModel(llm);
238
+ if (!_isBaseChatModel(model)) throw new Error(`Expected \`llm\` to be a ChatModel with .withStructuredOutput() method, got ${model.constructor.name}`);
239
+ if (typeof responseFormat === "object" && "schema" in responseFormat) {
240
+ const { prompt: prompt$1, schema: schema$1,...options } = responseFormat;
241
+ modelWithStructuredOutput = model.withStructuredOutput(schema$1, options);
242
+ if (prompt$1 != null) messages.unshift(new __langchain_core_messages.SystemMessage({ content: prompt$1 }));
243
+ } else modelWithStructuredOutput = model.withStructuredOutput(responseFormat);
244
+ const response = await modelWithStructuredOutput.invoke(messages, config);
245
+ return { structuredResponse: response };
246
+ };
247
+ const callModel = async (state, config) => {
248
+ const modelRunnable = typeof llm === "function" ? await _getDynamicModel(llm, state, config) : await _getStaticModel(llm);
249
+ const response = await modelRunnable.invoke(getModelInputState(state), config);
250
+ response.name = name;
251
+ response.lc_kwargs.name = name;
252
+ return { messages: [response] };
253
+ };
254
+ const schema = stateSchema ?? createReactAgentAnnotation();
255
+ const workflow = new require_state.StateGraph(schema, contextSchema).addNode("tools", toolNode);
256
+ if (!("messages" in workflow._schemaDefinition)) throw new Error("Missing required `messages` key in state schema.");
257
+ const allNodeWorkflows = workflow;
258
+ const conditionalMap = (map) => {
259
+ return Object.fromEntries(Object.entries(map).filter(([_, v]) => v != null));
260
+ };
261
+ let entrypoint = "agent";
262
+ let inputSchema;
263
+ if (preModelHook != null) {
264
+ allNodeWorkflows.addNode("pre_model_hook", preModelHook).addEdge("pre_model_hook", "agent");
265
+ entrypoint = "pre_model_hook";
266
+ inputSchema = require_annotation.Annotation.Root({
267
+ ...workflow._schemaDefinition,
268
+ ...PreHookAnnotation.spec
269
+ });
270
+ } else entrypoint = "agent";
271
+ allNodeWorkflows.addNode("agent", callModel, { input: inputSchema }).addEdge(require_constants.START, entrypoint);
272
+ if (postModelHook != null) allNodeWorkflows.addNode("post_model_hook", postModelHook).addEdge("agent", "post_model_hook").addConditionalEdges("post_model_hook", (state) => {
273
+ const { messages } = state;
274
+ const toolMessageIds = new Set(messages.filter(__langchain_core_messages.isToolMessage).map((msg) => msg.tool_call_id));
275
+ let lastAiMessage;
276
+ for (let i = messages.length - 1; i >= 0; i -= 1) {
277
+ const message = messages[i];
278
+ if ((0, __langchain_core_messages.isAIMessage)(message)) {
279
+ lastAiMessage = message;
280
+ break;
281
+ }
282
+ }
283
+ const pendingToolCalls = lastAiMessage?.tool_calls?.filter((i) => i.id == null || !toolMessageIds.has(i.id)) ?? [];
284
+ const lastMessage = messages.at(-1);
285
+ if (pendingToolCalls.length > 0) {
286
+ if (version === "v2") return pendingToolCalls.map((toolCall) => new require_constants.Send("tools", {
287
+ ...state,
288
+ lg_tool_call: toolCall
289
+ }));
290
+ return "tools";
291
+ }
292
+ if (lastMessage && (0, __langchain_core_messages.isToolMessage)(lastMessage)) return entrypoint;
293
+ if (responseFormat != null) return "generate_structured_response";
294
+ return require_constants.END;
295
+ }, conditionalMap({
296
+ tools: "tools",
297
+ [entrypoint]: entrypoint,
298
+ generate_structured_response: responseFormat != null ? "generate_structured_response" : null,
299
+ [require_constants.END]: responseFormat != null ? null : require_constants.END
300
+ }));
301
+ if (responseFormat !== void 0) workflow.addNode("generate_structured_response", generateStructuredResponse).addEdge("generate_structured_response", require_constants.END);
302
+ if (postModelHook == null) allNodeWorkflows.addConditionalEdges("agent", (state) => {
303
+ const { messages } = state;
304
+ const lastMessage = messages[messages.length - 1];
305
+ if (!(0, __langchain_core_messages.isAIMessage)(lastMessage) || !lastMessage.tool_calls?.length) {
306
+ if (responseFormat != null) return "generate_structured_response";
307
+ return require_constants.END;
308
+ }
309
+ if (version === "v2") return lastMessage.tool_calls.map((toolCall) => new require_constants.Send("tools", {
310
+ ...state,
311
+ lg_tool_call: toolCall
312
+ }));
313
+ return "tools";
314
+ }, conditionalMap({
315
+ tools: "tools",
316
+ generate_structured_response: responseFormat != null ? "generate_structured_response" : null,
317
+ [require_constants.END]: responseFormat != null ? null : require_constants.END
318
+ }));
319
+ if (shouldReturnDirect.size > 0) allNodeWorkflows.addConditionalEdges("tools", (state) => {
320
+ for (let i = state.messages.length - 1; i >= 0; i -= 1) {
321
+ const message = state.messages[i];
322
+ if (!(0, __langchain_core_messages.isToolMessage)(message)) break;
323
+ if (message.name !== void 0 && shouldReturnDirect.has(message.name)) return require_constants.END;
324
+ }
325
+ return entrypoint;
326
+ }, conditionalMap({
327
+ [entrypoint]: entrypoint,
328
+ [require_constants.END]: require_constants.END
329
+ }));
330
+ else allNodeWorkflows.addEdge("tools", entrypoint);
331
+ return allNodeWorkflows.compile({
332
+ checkpointer: checkpointer ?? checkpointSaver,
333
+ interruptBefore,
334
+ interruptAfter,
335
+ store,
336
+ name,
337
+ description
338
+ });
499
339
  }
500
- //# sourceMappingURL=react_agent_executor.js.map
340
+
341
+ //#endregion
342
+ exports.createReactAgent = createReactAgent;
343
+ exports.createReactAgentAnnotation = createReactAgentAnnotation;
344
+ //# sourceMappingURL=react_agent_executor.cjs.map