@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,6 +1,8 @@
1
- import { LanguageModelLike } from "@langchain/core/language_models/base";
2
1
  import { AIMessage, BaseMessage, BaseMessageLike } from "@langchain/core/messages";
3
- export type AgentNameMode = "inline";
2
+ import { LanguageModelLike } from "@langchain/core/language_models/base";
3
+
4
+ //#region src/prebuilt/agentName.d.ts
5
+ type AgentNameMode = "inline";
4
6
  /**
5
7
  * Attach formatted agent names to the messages passed to and from a language model.
6
8
  *
@@ -10,34 +12,21 @@ export type AgentNameMode = "inline";
10
12
  * If you're using an agent built with createReactAgent, name is automatically set.
11
13
  * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.
12
14
  *
15
+ * @deprecated migrated to `langchain` package.
16
+ *
13
17
  * @param message - Message to add agent name formatting to
14
18
  * @returns Message with agent name formatting
15
19
  *
16
20
  * @internal
17
21
  */
18
- export declare function _addInlineAgentName<T extends BaseMessageLike>(message: T): T | AIMessage;
19
- /**
20
- * Remove explicit name and content XML tags from the AI message content.
21
- *
22
- * Examples:
23
- *
24
- * @example
25
- * ```typescript
26
- * removeInlineAgentName(new AIMessage({ content: "<name>assistant</name><content>Hello</content>", name: "assistant" }))
27
- * // AIMessage with content: "Hello"
28
- *
29
- * removeInlineAgentName(new AIMessage({ content: [{type: "text", text: "<name>assistant</name><content>Hello</content>"}], name: "assistant" }))
30
- * // AIMessage with content: [{type: "text", text: "Hello"}]
31
- * ```
32
- *
33
- * @internal
34
- */
35
- export declare function _removeInlineAgentName<T extends BaseMessage>(message: T): T;
22
+
36
23
  /**
37
24
  * Attach formatted agent names to the messages passed to and from a language model.
38
25
  *
39
26
  * This is useful for making a message history with multiple agents more coherent.
40
27
  *
28
+ * * @deprecated migrated to `langchain` package.
29
+ *
41
30
  * NOTE: agent name is consumed from the message.name field.
42
31
  * If you're using an agent built with createReactAgent, name is automatically set.
43
32
  * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.
@@ -47,4 +36,7 @@ export declare function _removeInlineAgentName<T extends BaseMessage>(message: T
47
36
  * - "inline": Add the agent name directly into the content field of the AI message using XML-style tags.
48
37
  * Example: "How can I help you" -> "<name>agent_name</name><content>How can I help you?</content>".
49
38
  */
50
- export declare function withAgentName(model: LanguageModelLike, agentNameMode: AgentNameMode): LanguageModelLike;
39
+ declare function withAgentName(model: LanguageModelLike, agentNameMode: AgentNameMode): LanguageModelLike;
40
+ //#endregion
41
+ export { AgentNameMode, withAgentName };
42
+ //# sourceMappingURL=agentName.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentName.d.ts","names":["LanguageModelLike","AIMessage","BaseMessage","BaseMessageLike","AgentNameMode","_addInlineAgentName","T","_removeInlineAgentName","withAgentName"],"sources":["../../src/prebuilt/agentName.d.ts"],"sourcesContent":["import { LanguageModelLike } from \"@langchain/core/language_models/base\";\nimport { AIMessage, BaseMessage, BaseMessageLike } from \"@langchain/core/messages\";\nexport type AgentNameMode = \"inline\";\n/**\n * Attach formatted agent names to the messages passed to and from a language model.\n *\n * This is useful for making a message history with multiple agents more coherent.\n *\n * NOTE: agent name is consumed from the message.name field.\n * If you're using an agent built with createReactAgent, name is automatically set.\n * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.\n *\n * @deprecated migrated to `langchain` package.\n *\n * @param message - Message to add agent name formatting to\n * @returns Message with agent name formatting\n *\n * @internal\n */\nexport declare function _addInlineAgentName<T extends BaseMessageLike>(message: T): T | AIMessage;\n/**\n * Remove explicit name and content XML tags from the AI message content.\n *\n * @deprecated migrated to `langchain` package.\n *\n * Examples:\n *\n * @example\n * ```typescript\n * removeInlineAgentName(new AIMessage({ content: \"<name>assistant</name><content>Hello</content>\", name: \"assistant\" }))\n * // AIMessage with content: \"Hello\"\n *\n * removeInlineAgentName(new AIMessage({ content: [{type: \"text\", text: \"<name>assistant</name><content>Hello</content>\"}], name: \"assistant\" }))\n * // AIMessage with content: [{type: \"text\", text: \"Hello\"}]\n * ```\n *\n * @internal\n */\nexport declare function _removeInlineAgentName<T extends BaseMessage>(message: T): T;\n/**\n * Attach formatted agent names to the messages passed to and from a language model.\n *\n * This is useful for making a message history with multiple agents more coherent.\n *\n * * @deprecated migrated to `langchain` package.\n *\n * NOTE: agent name is consumed from the message.name field.\n * If you're using an agent built with createReactAgent, name is automatically set.\n * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.\n *\n * @param model - Language model to add agent name formatting to\n * @param agentNameMode - How to expose the agent name to the LLM\n * - \"inline\": Add the agent name directly into the content field of the AI message using XML-style tags.\n * Example: \"How can I help you\" -> \"<name>agent_name</name><content>How can I help you?</content>\".\n */\nexport declare function withAgentName(model: LanguageModelLike, agentNameMode: AgentNameMode): LanguageModelLike;\n"],"mappings":";;;;KAEYI,aAAAA;;AAAZ;AAqDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAwBI,aAAAA,QAAqBR,kCAAkCI,gBAAgBJ"}
@@ -1,178 +1,149 @@
1
- import { AIMessage, isAIMessage, isAIMessageChunk, isBaseMessage, isBaseMessageChunk, } from "@langchain/core/messages";
2
1
  import { RunnableLambda, RunnableSequence } from "@langchain/core/runnables";
2
+ import { AIMessage, isAIMessage, isAIMessageChunk, isBaseMessage, isBaseMessageChunk } from "@langchain/core/messages";
3
+
4
+ //#region src/prebuilt/agentName.ts
3
5
  const NAME_PATTERN = /<name>(.*?)<\/name>/s;
4
6
  const CONTENT_PATTERN = /<content>(.*?)<\/content>/s;
5
7
  /**
6
- * Attach formatted agent names to the messages passed to and from a language model.
7
- *
8
- * This is useful for making a message history with multiple agents more coherent.
9
- *
10
- * NOTE: agent name is consumed from the message.name field.
11
- * If you're using an agent built with createReactAgent, name is automatically set.
12
- * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.
13
- *
14
- * @param message - Message to add agent name formatting to
15
- * @returns Message with agent name formatting
16
- *
17
- * @internal
18
- */
19
- export function _addInlineAgentName(message) {
20
- const isAI = isBaseMessage(message) &&
21
- (isAIMessage(message) ||
22
- (isBaseMessageChunk(message) && isAIMessageChunk(message)));
23
- if (!isAI || !message.name) {
24
- return message;
25
- }
26
- const { name } = message;
27
- if (typeof message.content === "string") {
28
- return new AIMessage({
29
- ...(Object.keys(message.lc_kwargs ?? {}).length > 0
30
- ? message.lc_kwargs
31
- : message),
32
- content: `<name>${name}</name><content>${message.content}</content>`,
33
- name: undefined,
34
- });
35
- }
36
- const updatedContent = [];
37
- let textBlockCount = 0;
38
- for (const contentBlock of message.content) {
39
- if (typeof contentBlock === "string") {
40
- textBlockCount += 1;
41
- updatedContent.push(`<name>${name}</name><content>${contentBlock}</content>`);
42
- }
43
- else if (typeof contentBlock === "object" &&
44
- "type" in contentBlock &&
45
- contentBlock.type === "text") {
46
- textBlockCount += 1;
47
- updatedContent.push({
48
- ...contentBlock,
49
- text: `<name>${name}</name><content>${contentBlock.text}</content>`,
50
- });
51
- }
52
- else {
53
- updatedContent.push(contentBlock);
54
- }
55
- }
56
- if (!textBlockCount) {
57
- updatedContent.unshift({
58
- type: "text",
59
- text: `<name>${name}</name><content></content>`,
60
- });
61
- }
62
- return new AIMessage({
63
- ...message.lc_kwargs,
64
- content: updatedContent,
65
- name: undefined,
66
- });
8
+ * Attach formatted agent names to the messages passed to and from a language model.
9
+ *
10
+ * This is useful for making a message history with multiple agents more coherent.
11
+ *
12
+ * NOTE: agent name is consumed from the message.name field.
13
+ * If you're using an agent built with createReactAgent, name is automatically set.
14
+ * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.
15
+ *
16
+ * @deprecated migrated to `langchain` package.
17
+ *
18
+ * @param message - Message to add agent name formatting to
19
+ * @returns Message with agent name formatting
20
+ *
21
+ * @internal
22
+ */
23
+ function _addInlineAgentName(message) {
24
+ const isAI = isBaseMessage(message) && (isAIMessage(message) || isBaseMessageChunk(message) && isAIMessageChunk(message));
25
+ if (!isAI || !message.name) return message;
26
+ const { name } = message;
27
+ if (typeof message.content === "string") return new AIMessage({
28
+ ...Object.keys(message.lc_kwargs ?? {}).length > 0 ? message.lc_kwargs : message,
29
+ content: `<name>${name}</name><content>${message.content}</content>`,
30
+ name: void 0
31
+ });
32
+ const updatedContent = [];
33
+ let textBlockCount = 0;
34
+ for (const contentBlock of message.content) if (typeof contentBlock === "string") {
35
+ textBlockCount += 1;
36
+ updatedContent.push(`<name>${name}</name><content>${contentBlock}</content>`);
37
+ } else if (typeof contentBlock === "object" && "type" in contentBlock && contentBlock.type === "text") {
38
+ textBlockCount += 1;
39
+ updatedContent.push({
40
+ ...contentBlock,
41
+ text: `<name>${name}</name><content>${contentBlock.text}</content>`
42
+ });
43
+ } else updatedContent.push(contentBlock);
44
+ if (!textBlockCount) updatedContent.unshift({
45
+ type: "text",
46
+ text: `<name>${name}</name><content></content>`
47
+ });
48
+ return new AIMessage({
49
+ ...message.lc_kwargs,
50
+ content: updatedContent,
51
+ name: void 0
52
+ });
67
53
  }
68
54
  /**
69
- * Remove explicit name and content XML tags from the AI message content.
70
- *
71
- * Examples:
72
- *
73
- * @example
74
- * ```typescript
75
- * removeInlineAgentName(new AIMessage({ content: "<name>assistant</name><content>Hello</content>", name: "assistant" }))
76
- * // AIMessage with content: "Hello"
77
- *
78
- * removeInlineAgentName(new AIMessage({ content: [{type: "text", text: "<name>assistant</name><content>Hello</content>"}], name: "assistant" }))
79
- * // AIMessage with content: [{type: "text", text: "Hello"}]
80
- * ```
81
- *
82
- * @internal
83
- */
84
- export function _removeInlineAgentName(message) {
85
- if (!isAIMessage(message) || !message.content) {
86
- return message;
87
- }
88
- let updatedContent = [];
89
- let updatedName;
90
- if (Array.isArray(message.content)) {
91
- updatedContent = message.content
92
- .filter((block) => {
93
- if (block.type === "text") {
94
- const nameMatch = block.text.match(NAME_PATTERN);
95
- const contentMatch = block.text.match(CONTENT_PATTERN);
96
- // don't include empty content blocks that were added because there was no text block to modify
97
- if (nameMatch && (!contentMatch || contentMatch[1] === "")) {
98
- // capture name from text block
99
- // eslint-disable-next-line prefer-destructuring
100
- updatedName = nameMatch[1];
101
- return false;
102
- }
103
- return true;
104
- }
105
- return true;
106
- })
107
- .map((block) => {
108
- if (block.type === "text") {
109
- const nameMatch = block.text.match(NAME_PATTERN);
110
- const contentMatch = block.text.match(CONTENT_PATTERN);
111
- if (!nameMatch || !contentMatch) {
112
- return block;
113
- }
114
- // capture name from text block
115
- // eslint-disable-next-line prefer-destructuring
116
- updatedName = nameMatch[1];
117
- return {
118
- ...block,
119
- text: contentMatch[1],
120
- };
121
- }
122
- return block;
123
- });
124
- }
125
- else {
126
- const content = message.content;
127
- const nameMatch = content.match(NAME_PATTERN);
128
- const contentMatch = content.match(CONTENT_PATTERN);
129
- if (!nameMatch || !contentMatch) {
130
- return message;
131
- }
132
- // eslint-disable-next-line prefer-destructuring
133
- updatedName = nameMatch[1];
134
- // eslint-disable-next-line prefer-destructuring
135
- updatedContent = contentMatch[1];
136
- }
137
- return new AIMessage({
138
- ...(Object.keys(message.lc_kwargs ?? {}).length > 0
139
- ? message.lc_kwargs
140
- : message),
141
- content: updatedContent,
142
- name: updatedName,
143
- });
55
+ * Remove explicit name and content XML tags from the AI message content.
56
+ *
57
+ * @deprecated migrated to `langchain` package.
58
+ *
59
+ * Examples:
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * removeInlineAgentName(new AIMessage({ content: "<name>assistant</name><content>Hello</content>", name: "assistant" }))
64
+ * // AIMessage with content: "Hello"
65
+ *
66
+ * removeInlineAgentName(new AIMessage({ content: [{type: "text", text: "<name>assistant</name><content>Hello</content>"}], name: "assistant" }))
67
+ * // AIMessage with content: [{type: "text", text: "Hello"}]
68
+ * ```
69
+ *
70
+ * @internal
71
+ */
72
+ function _removeInlineAgentName(message) {
73
+ if (!isAIMessage(message) || !message.content) return message;
74
+ let updatedContent = [];
75
+ let updatedName;
76
+ if (Array.isArray(message.content)) updatedContent = message.content.filter((block) => {
77
+ if (block.type === "text" && typeof block.text === "string") {
78
+ const nameMatch = block.text.match(NAME_PATTERN);
79
+ const contentMatch = block.text.match(CONTENT_PATTERN);
80
+ if (nameMatch && (!contentMatch || contentMatch[1] === "")) {
81
+ updatedName = nameMatch[1];
82
+ return false;
83
+ }
84
+ return true;
85
+ }
86
+ return true;
87
+ }).map((block) => {
88
+ if (block.type === "text" && typeof block.text === "string") {
89
+ const nameMatch = block.text.match(NAME_PATTERN);
90
+ const contentMatch = block.text.match(CONTENT_PATTERN);
91
+ if (!nameMatch || !contentMatch) return block;
92
+ updatedName = nameMatch[1];
93
+ return {
94
+ ...block,
95
+ text: contentMatch[1]
96
+ };
97
+ }
98
+ return block;
99
+ });
100
+ else {
101
+ const content = message.content;
102
+ const nameMatch = content.match(NAME_PATTERN);
103
+ const contentMatch = content.match(CONTENT_PATTERN);
104
+ if (!nameMatch || !contentMatch) return message;
105
+ updatedName = nameMatch[1];
106
+ updatedContent = contentMatch[1];
107
+ }
108
+ return new AIMessage({
109
+ ...Object.keys(message.lc_kwargs ?? {}).length > 0 ? message.lc_kwargs : message,
110
+ content: updatedContent,
111
+ name: updatedName
112
+ });
144
113
  }
145
114
  /**
146
- * Attach formatted agent names to the messages passed to and from a language model.
147
- *
148
- * This is useful for making a message history with multiple agents more coherent.
149
- *
150
- * NOTE: agent name is consumed from the message.name field.
151
- * If you're using an agent built with createReactAgent, name is automatically set.
152
- * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.
153
- *
154
- * @param model - Language model to add agent name formatting to
155
- * @param agentNameMode - How to expose the agent name to the LLM
156
- * - "inline": Add the agent name directly into the content field of the AI message using XML-style tags.
157
- * Example: "How can I help you" -> "<name>agent_name</name><content>How can I help you?</content>".
158
- */
159
- export function withAgentName(model, agentNameMode) {
160
- let processInputMessage;
161
- let processOutputMessage;
162
- if (agentNameMode === "inline") {
163
- processInputMessage = _addInlineAgentName;
164
- processOutputMessage = _removeInlineAgentName;
165
- }
166
- else {
167
- throw new Error(`Invalid agent name mode: ${agentNameMode}. Needs to be one of: "inline"`);
168
- }
169
- function processInputMessages(messages) {
170
- return messages.map(processInputMessage);
171
- }
172
- return RunnableSequence.from([
173
- RunnableLambda.from(processInputMessages),
174
- model,
175
- RunnableLambda.from(processOutputMessage),
176
- ]);
115
+ * Attach formatted agent names to the messages passed to and from a language model.
116
+ *
117
+ * This is useful for making a message history with multiple agents more coherent.
118
+ *
119
+ * * @deprecated migrated to `langchain` package.
120
+ *
121
+ * NOTE: agent name is consumed from the message.name field.
122
+ * If you're using an agent built with createReactAgent, name is automatically set.
123
+ * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.
124
+ *
125
+ * @param model - Language model to add agent name formatting to
126
+ * @param agentNameMode - How to expose the agent name to the LLM
127
+ * - "inline": Add the agent name directly into the content field of the AI message using XML-style tags.
128
+ * Example: "How can I help you" -> "<name>agent_name</name><content>How can I help you?</content>".
129
+ */
130
+ function withAgentName(model, agentNameMode) {
131
+ let processInputMessage;
132
+ let processOutputMessage;
133
+ if (agentNameMode === "inline") {
134
+ processInputMessage = _addInlineAgentName;
135
+ processOutputMessage = _removeInlineAgentName;
136
+ } else throw new Error(`Invalid agent name mode: ${agentNameMode}. Needs to be one of: "inline"`);
137
+ function processInputMessages(messages) {
138
+ return messages.map(processInputMessage);
139
+ }
140
+ return RunnableSequence.from([
141
+ RunnableLambda.from(processInputMessages),
142
+ model,
143
+ RunnableLambda.from(processOutputMessage)
144
+ ]);
177
145
  }
146
+
147
+ //#endregion
148
+ export { withAgentName };
178
149
  //# sourceMappingURL=agentName.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"agentName.js","sourceRoot":"","sources":["../../src/prebuilt/agentName.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EAGT,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,kBAAkB,GAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,gB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AC;QAC3B,gDAAgD;QAChD,cAAc,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,IAAI,SAAS,CAAC;QACnB,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC;YACjD,CAAC,CAAC,OAAO,CAAC,SAAS;YACnB,CAAC,CAAC,OAAO,CAAC;QACZ,OAAO,EAAE,cAAc;QACvB,IAAI,EAAE,WAAW;KAClB,CAAM,CAAC;AACV,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAC3B,KAAwB,EACxB,aAA4B;IAE5B,IAAI,mBAAkE,CAAC;IACvE,IAAI,oBAA2D,CAAC;IAEhE,IAAI,aAAa,KAAK,QAAQ,EAAE,CAAC;QAC/B,mBAAmB,GAAG,mBAAmB,CAAC;QAC1C,oBAAoB,GAAG,sBAAsB,CAAC;IAChD,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CACb,4BAA4B,aAAa,gCAAgC,CAC1E,CAAC;IACJ,CAAC;IAED,SAAS,oBAAoB,CAC3B,QAA2B;QAE3B,OAAO,QAAQ,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,gBAAgB,CAAC,IAAI,CAAC;QAC3B,cAAc,CAAC,IAAI,CAAC,oBAAoB,CAAC;QACzC,KAAK;QACL,cAAc,CAAC,IAAI,CAAC,oBAAoB,CAAC;KAC1C,CAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"agentName.js","names":["updatedContent: MessageContent","updatedName: string | undefined","processInputMessage: (message: BaseMessageLike) => BaseMessageLike","processOutputMessage: (message: BaseMessage) => BaseMessage"],"sources":["../../src/prebuilt/agentName.ts"],"sourcesContent":["import { LanguageModelLike } from \"@langchain/core/language_models/base\";\nimport {\n AIMessage,\n BaseMessage,\n BaseMessageLike,\n isAIMessage,\n isAIMessageChunk,\n isBaseMessage,\n isBaseMessageChunk,\n MessageContent,\n} from \"@langchain/core/messages\";\nimport { RunnableLambda, RunnableSequence } from \"@langchain/core/runnables\";\n\nconst NAME_PATTERN = /<name>(.*?)<\\/name>/s;\nconst CONTENT_PATTERN = /<content>(.*?)<\\/content>/s;\n\nexport type AgentNameMode = \"inline\";\n\n/**\n * Attach formatted agent names to the messages passed to and from a language model.\n *\n * This is useful for making a message history with multiple agents more coherent.\n *\n * NOTE: agent name is consumed from the message.name field.\n * If you're using an agent built with createReactAgent, name is automatically set.\n * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.\n *\n * @deprecated migrated to `langchain` package.\n *\n * @param message - Message to add agent name formatting to\n * @returns Message with agent name formatting\n *\n * @internal\n */\nexport function _addInlineAgentName<T extends BaseMessageLike>(\n message: T\n): T | AIMessage {\n const isAI =\n isBaseMessage(message) &&\n (isAIMessage(message) ||\n (isBaseMessageChunk(message) && isAIMessageChunk(message)));\n\n if (!isAI || !message.name) {\n return message;\n }\n\n const { name } = message;\n\n if (typeof message.content === \"string\") {\n return new AIMessage({\n ...(Object.keys(message.lc_kwargs ?? {}).length > 0\n ? message.lc_kwargs\n : message),\n content: `<name>${name}</name><content>${message.content}</content>`,\n name: undefined,\n });\n }\n\n const updatedContent = [];\n let textBlockCount = 0;\n\n for (const contentBlock of message.content) {\n if (typeof contentBlock === \"string\") {\n textBlockCount += 1;\n updatedContent.push(\n `<name>${name}</name><content>${contentBlock}</content>`\n );\n } else if (\n typeof contentBlock === \"object\" &&\n \"type\" in contentBlock &&\n contentBlock.type === \"text\"\n ) {\n textBlockCount += 1;\n updatedContent.push({\n ...contentBlock,\n text: `<name>${name}</name><content>${contentBlock.text}</content>`,\n });\n } else {\n updatedContent.push(contentBlock);\n }\n }\n\n if (!textBlockCount) {\n updatedContent.unshift({\n type: \"text\",\n text: `<name>${name}</name><content></content>`,\n });\n }\n return new AIMessage({\n ...message.lc_kwargs,\n content: updatedContent as MessageContent,\n name: undefined,\n });\n}\n\n/**\n * Remove explicit name and content XML tags from the AI message content.\n *\n * @deprecated migrated to `langchain` package.\n *\n * Examples:\n *\n * @example\n * ```typescript\n * removeInlineAgentName(new AIMessage({ content: \"<name>assistant</name><content>Hello</content>\", name: \"assistant\" }))\n * // AIMessage with content: \"Hello\"\n *\n * removeInlineAgentName(new AIMessage({ content: [{type: \"text\", text: \"<name>assistant</name><content>Hello</content>\"}], name: \"assistant\" }))\n * // AIMessage with content: [{type: \"text\", text: \"Hello\"}]\n * ```\n *\n * @internal\n */\nexport function _removeInlineAgentName<T extends BaseMessage>(message: T): T {\n if (!isAIMessage(message) || !message.content) {\n return message;\n }\n\n let updatedContent: MessageContent = [];\n let updatedName: string | undefined;\n\n if (Array.isArray(message.content)) {\n updatedContent = message.content\n .filter((block) => {\n if (block.type === \"text\" && typeof block.text === \"string\") {\n const nameMatch = block.text.match(NAME_PATTERN);\n const contentMatch = block.text.match(CONTENT_PATTERN);\n // don't include empty content blocks that were added because there was no text block to modify\n if (nameMatch && (!contentMatch || contentMatch[1] === \"\")) {\n // capture name from text block\n // eslint-disable-next-line prefer-destructuring\n updatedName = nameMatch[1];\n return false;\n }\n return true;\n }\n return true;\n })\n .map((block) => {\n if (block.type === \"text\" && typeof block.text === \"string\") {\n const nameMatch = block.text.match(NAME_PATTERN);\n const contentMatch = block.text.match(CONTENT_PATTERN);\n\n if (!nameMatch || !contentMatch) {\n return block;\n }\n\n // capture name from text block\n // eslint-disable-next-line prefer-destructuring\n updatedName = nameMatch[1];\n\n return {\n ...block,\n text: contentMatch[1],\n };\n }\n return block;\n });\n } else {\n const content = message.content as string;\n const nameMatch = content.match(NAME_PATTERN);\n const contentMatch = content.match(CONTENT_PATTERN);\n\n if (!nameMatch || !contentMatch) {\n return message;\n }\n\n // eslint-disable-next-line prefer-destructuring\n updatedName = nameMatch[1];\n // eslint-disable-next-line prefer-destructuring\n updatedContent = contentMatch[1];\n }\n\n return new AIMessage({\n ...(Object.keys(message.lc_kwargs ?? {}).length > 0\n ? message.lc_kwargs\n : message),\n content: updatedContent,\n name: updatedName,\n }) as T;\n}\n\n/**\n * Attach formatted agent names to the messages passed to and from a language model.\n *\n * This is useful for making a message history with multiple agents more coherent.\n *\n * * @deprecated migrated to `langchain` package.\n *\n * NOTE: agent name is consumed from the message.name field.\n * If you're using an agent built with createReactAgent, name is automatically set.\n * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.\n *\n * @param model - Language model to add agent name formatting to\n * @param agentNameMode - How to expose the agent name to the LLM\n * - \"inline\": Add the agent name directly into the content field of the AI message using XML-style tags.\n * Example: \"How can I help you\" -> \"<name>agent_name</name><content>How can I help you?</content>\".\n */\nexport function withAgentName(\n model: LanguageModelLike,\n agentNameMode: AgentNameMode\n): LanguageModelLike {\n let processInputMessage: (message: BaseMessageLike) => BaseMessageLike;\n let processOutputMessage: (message: BaseMessage) => BaseMessage;\n\n if (agentNameMode === \"inline\") {\n processInputMessage = _addInlineAgentName;\n processOutputMessage = _removeInlineAgentName;\n } else {\n throw new Error(\n `Invalid agent name mode: ${agentNameMode}. Needs to be one of: \"inline\"`\n );\n }\n\n function processInputMessages(\n messages: BaseMessageLike[]\n ): BaseMessageLike[] {\n return messages.map(processInputMessage);\n }\n\n return RunnableSequence.from([\n RunnableLambda.from(processInputMessages),\n model,\n RunnableLambda.from(processOutputMessage),\n ]);\n}\n"],"mappings":";;;;AAaA,MAAM,eAAe;AACrB,MAAM,kBAAkB;;;;;;;;;;;;;;;;;AAoBxB,SAAgB,oBACd,SACe;CACf,MAAM,OACJ,cAAc,aACb,YAAY,YACV,mBAAmB,YAAY,iBAAiB;AAErD,KAAI,CAAC,QAAQ,CAAC,QAAQ,KACpB,QAAO;CAGT,MAAM,EAAE,SAAS;AAEjB,KAAI,OAAO,QAAQ,YAAY,SAC7B,QAAO,IAAI,UAAU;EACnB,GAAI,OAAO,KAAK,QAAQ,aAAa,IAAI,SAAS,IAC9C,QAAQ,YACR;EACJ,SAAS,SAAS,KAAK,k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EACL,MAAM,UAAU,QAAQ;EACxB,MAAM,YAAY,QAAQ,MAAM;EAChC,MAAM,eAAe,QAAQ,MAAM;AAEnC,MAAI,CAAC,aAAa,CAAC,aACjB,QAAO;AAIT,gBAAc,UAAU;AAExB,mBAAiB,aAAa;;AAGhC,QAAO,IAAI,UAAU;EACnB,GAAI,OAAO,KAAK,QAAQ,aAAa,IAAI,SAAS,IAC9C,QAAQ,YACR;EACJ,SAAS;EACT,MAAM;;;;;;;;;;;;;;;;;;;AAoBV,SAAgB,cACd,OACA,eACmB;CACnB,IAAIC;CACJ,IAAIC;AAEJ,KAAI,kBAAkB,UAAU;AAC9B,wBAAsB;AACtB,yBAAuB;OAEvB,OAAM,IAAI,MACR,4BAA4B,cAAc;CAI9C,SAAS,qBACP,UACmB;AACnB,SAAO,SAAS,IAAI;;AAGtB,QAAO,iBAAiB,KAAK;EAC3B,eAAe,KAAK;EACpB;EACA,eAAe,KAAK"}
@@ -1,82 +1,44 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAgentExecutor = createAgentExecutor;
4
- const tool_executor_js_1 = require("./tool_executor.cjs");
5
- const state_js_1 = require("../graph/state.cjs");
6
- const constants_js_1 = require("../constants.cjs");
1
+ const require_constants = require('../constants.cjs');
2
+ const require_state = require('../graph/state.cjs');
3
+ const require_tool_executor = require('./tool_executor.cjs');
4
+
5
+ //#region src/prebuilt/agent_executor.ts
7
6
  /** @ignore */
8
- function createAgentExecutor({ agentRunnable, tools, }) {
9
- let toolExecutor;
10
- if (!Array.isArray(tools)) {
11
- toolExecutor = tools;
12
- }
13
- else {
14
- toolExecutor = new tool_executor_js_1.ToolExecutor({
15
- tools,
16
- });
17
- }
18
- // Define logic that will be used to determine which conditional edge to go down
19
- const shouldContinue = (data) => {
20
- if (data.agentOutcome && "returnValues" in data.agentOutcome) {
21
- return "end";
22
- }
23
- return "continue";
24
- };
25
- const runAgent = async (data, config) => {
26
- const agentOutcome = await agentRunnable.invoke(data, config);
27
- return {
28
- agentOutcome,
29
- };
30
- };
31
- const executeTools = async (data, config) => {
32
- const agentAction = data.agentOutcome;
33
- if (!agentAction || "returnValues" in agentAction) {
34
- throw new Error("Agent has not been run yet");
35
- }
36
- const output = await toolExecutor.invoke(agentAction, config);
37
- return {
38
- steps: [{ action: agentAction, observation: output }],
39
- };
40
- };
41
- // Define a new graph
42
- const workflow = new state_js_1.StateGraph({
43
- channels: {
44
- input: null,
45
- agentOutcome: null,
46
- steps: {
47
- reducer: (x, y) => x.concat(y),
48
- default: () => [],
49
- },
50
- },
51
- })
52
- // Define the two nodes we will cycle between
53
- .addNode("agent", runAgent)
54
- .addNode("action", executeTools)
55
- // Set the entrypoint as `agent`
56
- // This means that this node is the first one called
57
- .addEdge(constants_js_1.START, "agent")
58
- // We now add a conditional edge
59
- .addConditionalEdges(
60
- // First, we define the start node. We use `agent`.
61
- // This means these are the edges taken after the `agent` node is called.
62
- "agent",
63
- // Next, we pass in the function that will determine which node is called next.
64
- shouldContinue,
65
- // Finally we pass in a mapping.
66
- // The keys are strings, and the values are other nodes.
67
- // END is a special node marking that the graph should finish.
68
- // What will happen is we will call `should_continue`, and then the output of that
69
- // will be matched against the keys in this mapping.
70
- // Based on which one it matches, that node will then be called.
71
- {
72
- // If `tools`, then we call the tool node.
73
- continue: "action",
74
- // Otherwise we finish.
75
- end: constants_js_1.END,
76
- })
77
- // We now add a normal edge from `tools` to `agent`.
78
- // This means that after `tools` is called, `agent` node is called next.
79
- .addEdge("action", "agent");
80
- return workflow.compile();
7
+ function createAgentExecutor({ agentRunnable, tools }) {
8
+ let toolExecutor;
9
+ if (!Array.isArray(tools)) toolExecutor = tools;
10
+ else toolExecutor = new require_tool_executor.ToolExecutor({ tools });
11
+ const shouldContinue = (data) => {
12
+ if (data.agentOutcome && "returnValues" in data.agentOutcome) return "end";
13
+ return "continue";
14
+ };
15
+ const runAgent = async (data, config) => {
16
+ const agentOutcome = await agentRunnable.invoke(data, config);
17
+ return { agentOutcome };
18
+ };
19
+ const executeTools = async (data, config) => {
20
+ const agentAction = data.agentOutcome;
21
+ if (!agentAction || "returnValues" in agentAction) throw new Error("Agent has not been run yet");
22
+ const output = await toolExecutor.invoke(agentAction, config);
23
+ return { steps: [{
24
+ action: agentAction,
25
+ observation: output
26
+ }] };
27
+ };
28
+ const workflow = new require_state.StateGraph({ channels: {
29
+ input: null,
30
+ agentOutcome: null,
31
+ steps: {
32
+ reducer: (x, y) => x.concat(y),
33
+ default: () => []
34
+ }
35
+ } }).addNode("agent", runAgent).addNode("action", executeTools).addEdge(require_constants.START, "agent").addConditionalEdges("agent", shouldContinue, {
36
+ continue: "action",
37
+ end: require_constants.END
38
+ }).addEdge("action", "agent");
39
+ return workflow.compile();
81
40
  }
82
- //# sourceMappingURL=agent_executor.js.map
41
+
42
+ //#endregion
43
+ exports.createAgentExecutor = createAgentExecutor;
44
+ //# sourceMappingURL=agent_executor.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent_executor.cjs","names":["toolExecutor: ToolExecutor","ToolExecutor","StateGraph","START","END"],"sources":["../../src/prebuilt/agent_executor.ts"],"sourcesContent":["import { AgentAction, AgentFinish } from \"@langchain/core/agents\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { Runnable, type RunnableConfig } from \"@langchain/core/runnables\";\nimport { Tool } from \"@langchain/core/tools\";\nimport { ToolExecutor } from \"./tool_executor.js\";\nimport { StateGraph } from \"../graph/state.js\";\nimport { END, START } from \"../constants.js\";\nimport type { BaseChannel } from \"../channels/base.js\";\n\ninterface Step {\n action: AgentAction | AgentFinish;\n observation: unknown;\n}\n\n/** @ignore */\nexport interface AgentExecutorState {\n agentOutcome?: AgentAction | AgentFinish;\n steps: Array<Step>;\n input: string;\n chatHistory?: BaseMessage[];\n}\n\n/** @ignore */\nexport function createAgentExecutor({\n agentRunnable,\n tools,\n}: {\n agentRunnable: Runnable;\n tools: Array<Tool> | ToolExecutor;\n}) {\n let toolExecutor: ToolExecutor;\n if (!Array.isArray(tools)) {\n toolExecutor = tools;\n } else {\n toolExecutor = new ToolExecutor({\n tools,\n });\n }\n\n // Define logic that will be used to determine which conditional edge to go down\n const shouldContinue = (data: AgentExecutorState) => {\n if (data.agentOutcome && \"returnValues\" in data.agentOutcome) {\n return \"end\";\n }\n return \"continue\";\n };\n\n const runAgent = async (\n data: AgentExecutorState,\n config?: RunnableConfig\n ) => {\n const agentOutcome = await agentRunnable.invoke(data, config);\n return {\n agentOutcome,\n };\n };\n\n const executeTools = async (\n data: AgentExecutorState,\n config?: RunnableConfig\n ): Promise<Partial<AgentExecutorState>> => {\n const agentAction = data.agentOutcome;\n if (!agentAction || \"returnValues\" in agentAction) {\n throw new Error(\"Agent has not been run yet\");\n }\n const output = await toolExecutor.invoke(agentAction, config);\n return {\n steps: [{ action: agentAction, observation: output }],\n };\n };\n\n // Define a new graph\n const workflow = new StateGraph<{\n [K in keyof AgentExecutorState]: BaseChannel<\n AgentExecutorState[K],\n AgentExecutorState[K]\n >;\n }>({\n channels: {\n input: null,\n agentOutcome: null,\n steps: {\n reducer: (x: Step[], y: Step[]) => x.concat(y),\n default: () => [] as Step[],\n },\n },\n })\n // Define the two nodes we will cycle between\n .addNode(\"agent\", runAgent)\n .addNode(\"action\", executeTools)\n // Set the entrypoint as `agent`\n // This means that this node is the first one called\n .addEdge(START, \"agent\")\n // We now add a conditional edge\n .addConditionalEdges(\n // First, we define the start node. We use `agent`.\n // This means these are the edges taken after the `agent` node is called.\n \"agent\",\n // Next, we pass in the function that will determine which node is called next.\n shouldContinue,\n // Finally we pass in a mapping.\n // The keys are strings, and the values are other nodes.\n // END is a special node marking that the graph should finish.\n // What will happen is we will call `should_continue`, and then the output of that\n // will be matched against the keys in this mapping.\n // Based on which one it matches, that node will then be called.\n {\n // If `tools`, then we call the tool node.\n continue: \"action\",\n // Otherwise we finish.\n end: END,\n }\n )\n // We now add a normal edge from `tools` to `agent`.\n // This means that after `tools` is called, `agent` node is called next.\n .addEdge(\"action\", \"agent\");\n\n return workflow.compile();\n}\n"],"mappings":";;;;;;AAuBA,SAAgB,oBAAoB,EAClC,eACA,SAIC;CACD,IAAIA;AACJ,KAAI,CAAC,MAAM,QAAQ,OACjB,gBAAe;KAEf,gBAAe,IAAIC,mCAAa,EAC9B;CAKJ,MAAM,kBAAkB,SAA6B;AACnD,MAAI,KAAK,gBAAgB,kBAAkB,KAAK,aAC9C,QAAO;AAET,SAAO;;CAGT,MAAM,WAAW,OACf,MACA,WACG;EACH,MAAM,eAAe,MAAM,cAAc,OAAO,MAAM;AACtD,SAAO,EACL;;CAIJ,MAAM,eAAe,OACnB,MACA,WACyC;EACzC,MAAM,cAAc,KAAK;AACzB,MAAI,CAAC,eAAe,kBAAkB,YACpC,OAAM,IAAI,MAAM;EAElB,MAAM,SAAS,MAAM,aAAa,OAAO,aAAa;AACtD,SAAO,EACL,OAAO,CAAC;GAAE,QAAQ;GAAa,aAAa;;;CAKhD,MAAM,WAAW,IAAIC,yBAKlB,EACD,UAAU;EACR,OAAO;EACP,cAAc;EACd,OAAO;GACL,UAAU,GAAW,MAAc,EAAE,OAAO;GAC5C,eAAe;;MAKlB,QAAQ,SAAS,UACjB,QAAQ,UAAU,cAGlB,QAAQC,yBAAO,SAEf,oBAGC,SAEA,gBAOA;EAEE,UAAU;EAEV,KAAKC;IAKR,QAAQ,UAAU;AAErB,QAAO,SAAS"}
@@ -0,0 +1,57 @@
1
+ import { BaseChannel } from "../channels/base.cjs";
2
+ import { StateDefinition } from "../graph/annotation.cjs";
3
+ import { CompiledStateGraph } from "../graph/state.cjs";
4
+ import { ToolExecutor } from "./tool_executor.cjs";
5
+ import { Runnable } from "@langchain/core/runnables";
6
+ import { BaseMessage } from "@langchain/core/messages";
7
+ import { AgentAction, AgentFinish } from "@langchain/core/agents";
8
+ import { Tool } from "@langchain/core/tools";
9
+
10
+ //#region src/prebuilt/agent_executor.d.ts
11
+ interface Step {
12
+ action: AgentAction | AgentFinish;
13
+ observation: unknown;
14
+ }
15
+ /** @ignore */
16
+ interface AgentExecutorState {
17
+ agentOutcome?: AgentAction | AgentFinish;
18
+ steps: Array<Step>;
19
+ input: string;
20
+ chatHistory?: BaseMessage[];
21
+ }
22
+ /** @ignore */
23
+ declare function createAgentExecutor({
24
+ agentRunnable,
25
+ tools
26
+ }: {
27
+ agentRunnable: Runnable;
28
+ tools: Array<Tool> | ToolExecutor;
29
+ }): CompiledStateGraph<{
30
+ agentOutcome?: AgentAction | AgentFinish | undefined;
31
+ steps: Step[];
32
+ input: string;
33
+ chatHistory?: BaseMessage[] | undefined;
34
+ }, {
35
+ agentOutcome?: AgentAction | AgentFinish | undefined;
36
+ steps?: Step[] | undefined;
37
+ input?: string | undefined;
38
+ chatHistory?: BaseMessage[] | undefined;
39
+ }, "__start__" | "action" | "agent", {
40
+ agentOutcome?: BaseChannel<AgentAction | AgentFinish | undefined, AgentAction | AgentFinish | undefined, unknown> | undefined;
41
+ steps: BaseChannel<Step[], Step[], unknown>;
42
+ input: BaseChannel<string, string, unknown>;
43
+ chatHistory?: BaseChannel<BaseMessage[] | undefined, BaseMessage[] | undefined, unknown> | undefined;
44
+ }, {
45
+ agentOutcome?: BaseChannel<AgentAction | AgentFinish | undefined, AgentAction | AgentFinish | undefined, unknown> | undefined;
46
+ steps: BaseChannel<Step[], Step[], unknown>;
47
+ input: BaseChannel<string, string, unknown>;
48
+ chatHistory?: BaseChannel<BaseMessage[] | undefined, BaseMessage[] | undefined, unknown> | undefined;
49
+ }, StateDefinition, {
50
+ action: Partial<AgentExecutorState>;
51
+ agent: {
52
+ agentOutcome: any;
53
+ };
54
+ }>;
55
+ //#endregion
56
+ export { AgentExecutorState, createAgentExecutor };
57
+ //# sourceMappingURL=agent_executor.d.cts.map