@langchain/langgraph 1.0.7 → 1.0.13

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 (304) hide show
  1. package/dist/channels/any_value.cjs.map +1 -1
  2. package/dist/channels/any_value.d.cts +0 -1
  3. package/dist/channels/any_value.d.cts.map +1 -1
  4. package/dist/channels/any_value.d.ts +0 -1
  5. package/dist/channels/any_value.d.ts.map +1 -1
  6. package/dist/channels/any_value.js.map +1 -1
  7. package/dist/channels/base.cjs +2 -3
  8. package/dist/channels/base.cjs.map +1 -1
  9. package/dist/channels/base.d.cts.map +1 -1
  10. package/dist/channels/base.d.ts.map +1 -1
  11. package/dist/channels/base.js.map +1 -1
  12. package/dist/channels/binop.cjs.map +1 -1
  13. package/dist/channels/binop.d.cts.map +1 -1
  14. package/dist/channels/binop.d.ts.map +1 -1
  15. package/dist/channels/binop.js.map +1 -1
  16. package/dist/channels/dynamic_barrier_value.cjs +0 -1
  17. package/dist/channels/dynamic_barrier_value.cjs.map +1 -1
  18. package/dist/channels/dynamic_barrier_value.d.cts +1 -3
  19. package/dist/channels/dynamic_barrier_value.d.cts.map +1 -1
  20. package/dist/channels/dynamic_barrier_value.d.ts +1 -3
  21. package/dist/channels/dynamic_barrier_value.d.ts.map +1 -1
  22. package/dist/channels/dynamic_barrier_value.js +0 -1
  23. package/dist/channels/dynamic_barrier_value.js.map +1 -1
  24. package/dist/channels/ephemeral_value.cjs.map +1 -1
  25. package/dist/channels/ephemeral_value.d.cts +0 -1
  26. package/dist/channels/ephemeral_value.d.cts.map +1 -1
  27. package/dist/channels/ephemeral_value.d.ts +0 -1
  28. package/dist/channels/ephemeral_value.d.ts.map +1 -1
  29. package/dist/channels/ephemeral_value.js.map +1 -1
  30. package/dist/channels/last_value.cjs.map +1 -1
  31. package/dist/channels/last_value.d.cts +0 -2
  32. package/dist/channels/last_value.d.cts.map +1 -1
  33. package/dist/channels/last_value.d.ts +0 -2
  34. package/dist/channels/last_value.d.ts.map +1 -1
  35. package/dist/channels/last_value.js.map +1 -1
  36. package/dist/channels/named_barrier_value.cjs +0 -2
  37. package/dist/channels/named_barrier_value.cjs.map +1 -1
  38. package/dist/channels/named_barrier_value.d.cts +2 -4
  39. package/dist/channels/named_barrier_value.d.cts.map +1 -1
  40. package/dist/channels/named_barrier_value.d.ts +2 -4
  41. package/dist/channels/named_barrier_value.d.ts.map +1 -1
  42. package/dist/channels/named_barrier_value.js +0 -2
  43. package/dist/channels/named_barrier_value.js.map +1 -1
  44. package/dist/channels/topic.cjs.map +1 -1
  45. package/dist/channels/topic.d.cts.map +1 -1
  46. package/dist/channels/topic.d.ts.map +1 -1
  47. package/dist/channels/topic.js.map +1 -1
  48. package/dist/constants.cjs.map +1 -1
  49. package/dist/constants.d.cts +2 -6
  50. package/dist/constants.d.cts.map +1 -1
  51. package/dist/constants.d.ts +2 -6
  52. package/dist/constants.d.ts.map +1 -1
  53. package/dist/constants.js.map +1 -1
  54. package/dist/errors.cjs.map +1 -1
  55. package/dist/errors.d.cts +0 -4
  56. package/dist/errors.d.cts.map +1 -1
  57. package/dist/errors.d.ts +0 -4
  58. package/dist/errors.d.ts.map +1 -1
  59. package/dist/errors.js.map +1 -1
  60. package/dist/func/index.cjs +2 -4
  61. package/dist/func/index.cjs.map +1 -1
  62. package/dist/func/index.d.cts +1 -6
  63. package/dist/func/index.d.cts.map +1 -1
  64. package/dist/func/index.d.ts +1 -6
  65. package/dist/func/index.d.ts.map +1 -1
  66. package/dist/func/index.js +1 -2
  67. package/dist/func/index.js.map +1 -1
  68. package/dist/func/types.d.cts +2 -4
  69. package/dist/func/types.d.cts.map +1 -1
  70. package/dist/func/types.d.ts +2 -4
  71. package/dist/func/types.d.ts.map +1 -1
  72. package/dist/graph/annotation.cjs.map +1 -1
  73. package/dist/graph/annotation.d.cts.map +1 -1
  74. package/dist/graph/annotation.d.ts.map +1 -1
  75. package/dist/graph/annotation.js.map +1 -1
  76. package/dist/graph/graph.cjs +15 -18
  77. package/dist/graph/graph.cjs.map +1 -1
  78. package/dist/graph/graph.d.cts +4 -28
  79. package/dist/graph/graph.d.cts.map +1 -1
  80. package/dist/graph/graph.d.ts +4 -28
  81. package/dist/graph/graph.d.ts.map +1 -1
  82. package/dist/graph/graph.js +4 -6
  83. package/dist/graph/graph.js.map +1 -1
  84. package/dist/graph/message.cjs +8 -10
  85. package/dist/graph/message.cjs.map +1 -1
  86. package/dist/graph/message.d.cts +2 -2
  87. package/dist/graph/message.d.cts.map +1 -1
  88. package/dist/graph/message.d.ts +2 -2
  89. package/dist/graph/message.d.ts.map +1 -1
  90. package/dist/graph/message.js +3 -4
  91. package/dist/graph/message.js.map +1 -1
  92. package/dist/graph/messages_annotation.cjs +1 -2
  93. package/dist/graph/messages_annotation.cjs.map +1 -1
  94. package/dist/graph/messages_annotation.d.cts +5 -5
  95. package/dist/graph/messages_annotation.d.cts.map +1 -1
  96. package/dist/graph/messages_annotation.d.ts +5 -5
  97. package/dist/graph/messages_annotation.d.ts.map +1 -1
  98. package/dist/graph/messages_annotation.js.map +1 -1
  99. package/dist/graph/state.cjs +23 -30
  100. package/dist/graph/state.cjs.map +1 -1
  101. package/dist/graph/state.d.cts +2 -9
  102. package/dist/graph/state.d.cts.map +1 -1
  103. package/dist/graph/state.d.ts +2 -9
  104. package/dist/graph/state.d.ts.map +1 -1
  105. package/dist/graph/state.js +6 -12
  106. package/dist/graph/state.js.map +1 -1
  107. package/dist/graph/zod/meta.cjs +8 -9
  108. package/dist/graph/zod/meta.cjs.map +1 -1
  109. package/dist/graph/zod/meta.d.cts +0 -1
  110. package/dist/graph/zod/meta.d.cts.map +1 -1
  111. package/dist/graph/zod/meta.d.ts +0 -1
  112. package/dist/graph/zod/meta.d.ts.map +1 -1
  113. package/dist/graph/zod/meta.js.map +1 -1
  114. package/dist/graph/zod/plugin.cjs +4 -6
  115. package/dist/graph/zod/plugin.cjs.map +1 -1
  116. package/dist/graph/zod/plugin.js +1 -2
  117. package/dist/graph/zod/plugin.js.map +1 -1
  118. package/dist/graph/zod/schema.cjs +2 -3
  119. package/dist/graph/zod/schema.cjs.map +1 -1
  120. package/dist/graph/zod/schema.d.cts.map +1 -1
  121. package/dist/graph/zod/schema.d.ts.map +1 -1
  122. package/dist/graph/zod/schema.js.map +1 -1
  123. package/dist/graph/zod/zod-registry.cjs +3 -4
  124. package/dist/graph/zod/zod-registry.cjs.map +1 -1
  125. package/dist/graph/zod/zod-registry.d.cts +0 -2
  126. package/dist/graph/zod/zod-registry.d.cts.map +1 -1
  127. package/dist/graph/zod/zod-registry.d.ts +0 -2
  128. package/dist/graph/zod/zod-registry.d.ts.map +1 -1
  129. package/dist/graph/zod/zod-registry.js.map +1 -1
  130. package/dist/hash.cjs +4 -10
  131. package/dist/hash.cjs.map +1 -1
  132. package/dist/hash.js +4 -10
  133. package/dist/hash.js.map +1 -1
  134. package/dist/index.cjs +8 -9
  135. package/dist/index.cjs.map +1 -1
  136. package/dist/index.js.map +1 -1
  137. package/dist/interrupt.cjs +4 -7
  138. package/dist/interrupt.cjs.map +1 -1
  139. package/dist/interrupt.d.cts +1 -4
  140. package/dist/interrupt.d.cts.map +1 -1
  141. package/dist/interrupt.d.ts +1 -4
  142. package/dist/interrupt.d.ts.map +1 -1
  143. package/dist/interrupt.js +2 -4
  144. package/dist/interrupt.js.map +1 -1
  145. package/dist/prebuilt/agentName.cjs +14 -19
  146. package/dist/prebuilt/agentName.cjs.map +1 -1
  147. package/dist/prebuilt/agentName.js +6 -10
  148. package/dist/prebuilt/agentName.js.map +1 -1
  149. package/dist/prebuilt/agent_executor.cjs +4 -7
  150. package/dist/prebuilt/agent_executor.cjs.map +1 -1
  151. package/dist/prebuilt/agent_executor.d.cts +5 -5
  152. package/dist/prebuilt/agent_executor.d.cts.map +1 -1
  153. package/dist/prebuilt/agent_executor.d.ts +5 -5
  154. package/dist/prebuilt/agent_executor.d.ts.map +1 -1
  155. package/dist/prebuilt/agent_executor.js +4 -7
  156. package/dist/prebuilt/agent_executor.js.map +1 -1
  157. package/dist/prebuilt/chat_agent_executor.cjs +11 -17
  158. package/dist/prebuilt/chat_agent_executor.cjs.map +1 -1
  159. package/dist/prebuilt/chat_agent_executor.d.cts.map +1 -1
  160. package/dist/prebuilt/chat_agent_executor.d.ts.map +1 -1
  161. package/dist/prebuilt/chat_agent_executor.js +7 -12
  162. package/dist/prebuilt/chat_agent_executor.js.map +1 -1
  163. package/dist/prebuilt/interrupt.d.cts +0 -1
  164. package/dist/prebuilt/interrupt.d.cts.map +1 -1
  165. package/dist/prebuilt/interrupt.d.ts +0 -1
  166. package/dist/prebuilt/interrupt.d.ts.map +1 -1
  167. package/dist/prebuilt/react_agent_executor.cjs +35 -40
  168. package/dist/prebuilt/react_agent_executor.cjs.map +1 -1
  169. package/dist/prebuilt/react_agent_executor.d.cts +8 -27
  170. package/dist/prebuilt/react_agent_executor.d.cts.map +1 -1
  171. package/dist/prebuilt/react_agent_executor.d.ts +8 -27
  172. package/dist/prebuilt/react_agent_executor.d.ts.map +1 -1
  173. package/dist/prebuilt/react_agent_executor.js +8 -12
  174. package/dist/prebuilt/react_agent_executor.js.map +1 -1
  175. package/dist/prebuilt/tool_executor.cjs +4 -9
  176. package/dist/prebuilt/tool_executor.cjs.map +1 -1
  177. package/dist/prebuilt/tool_executor.d.cts +0 -2
  178. package/dist/prebuilt/tool_executor.d.cts.map +1 -1
  179. package/dist/prebuilt/tool_executor.d.ts +0 -2
  180. package/dist/prebuilt/tool_executor.d.ts.map +1 -1
  181. package/dist/prebuilt/tool_executor.js +1 -5
  182. package/dist/prebuilt/tool_executor.js.map +1 -1
  183. package/dist/prebuilt/tool_node.cjs +7 -8
  184. package/dist/prebuilt/tool_node.cjs.map +1 -1
  185. package/dist/prebuilt/tool_node.d.cts +0 -2
  186. package/dist/prebuilt/tool_node.d.cts.map +1 -1
  187. package/dist/prebuilt/tool_node.d.ts +0 -2
  188. package/dist/prebuilt/tool_node.d.ts.map +1 -1
  189. package/dist/prebuilt/tool_node.js.map +1 -1
  190. package/dist/pregel/algo.cjs +33 -41
  191. package/dist/pregel/algo.cjs.map +1 -1
  192. package/dist/pregel/algo.d.cts.map +1 -1
  193. package/dist/pregel/algo.d.ts.map +1 -1
  194. package/dist/pregel/algo.js +22 -29
  195. package/dist/pregel/algo.js.map +1 -1
  196. package/dist/pregel/call.cjs +11 -14
  197. package/dist/pregel/call.cjs.map +1 -1
  198. package/dist/pregel/call.js +7 -9
  199. package/dist/pregel/call.js.map +1 -1
  200. package/dist/pregel/debug.cjs +6 -9
  201. package/dist/pregel/debug.cjs.map +1 -1
  202. package/dist/pregel/debug.js +6 -9
  203. package/dist/pregel/debug.js.map +1 -1
  204. package/dist/pregel/index.cjs +28 -35
  205. package/dist/pregel/index.cjs.map +1 -1
  206. package/dist/pregel/index.d.cts +6 -54
  207. package/dist/pregel/index.d.cts.map +1 -1
  208. package/dist/pregel/index.d.ts +6 -54
  209. package/dist/pregel/index.d.ts.map +1 -1
  210. package/dist/pregel/index.js +10 -16
  211. package/dist/pregel/index.js.map +1 -1
  212. package/dist/pregel/io.cjs.map +1 -1
  213. package/dist/pregel/io.js.map +1 -1
  214. package/dist/pregel/loop.cjs +9 -12
  215. package/dist/pregel/loop.cjs.map +1 -1
  216. package/dist/pregel/loop.js +2 -4
  217. package/dist/pregel/loop.js.map +1 -1
  218. package/dist/pregel/messages.cjs +13 -14
  219. package/dist/pregel/messages.cjs.map +1 -1
  220. package/dist/pregel/messages.js.map +1 -1
  221. package/dist/pregel/read.cjs +7 -8
  222. package/dist/pregel/read.cjs.map +1 -1
  223. package/dist/pregel/read.d.cts +0 -6
  224. package/dist/pregel/read.d.cts.map +1 -1
  225. package/dist/pregel/read.d.ts +0 -6
  226. package/dist/pregel/read.d.ts.map +1 -1
  227. package/dist/pregel/read.js +1 -1
  228. package/dist/pregel/read.js.map +1 -1
  229. package/dist/pregel/remote.cjs +24 -32
  230. package/dist/pregel/remote.cjs.map +1 -1
  231. package/dist/pregel/remote.d.cts +1 -6
  232. package/dist/pregel/remote.d.cts.map +1 -1
  233. package/dist/pregel/remote.d.ts +1 -6
  234. package/dist/pregel/remote.d.ts.map +1 -1
  235. package/dist/pregel/remote.js +12 -19
  236. package/dist/pregel/remote.js.map +1 -1
  237. package/dist/pregel/retry.cjs +1 -2
  238. package/dist/pregel/retry.cjs.map +1 -1
  239. package/dist/pregel/retry.js +1 -2
  240. package/dist/pregel/retry.js.map +1 -1
  241. package/dist/pregel/runnable_types.d.cts +2 -8
  242. package/dist/pregel/runnable_types.d.cts.map +1 -1
  243. package/dist/pregel/runnable_types.d.ts +2 -8
  244. package/dist/pregel/runnable_types.d.ts.map +1 -1
  245. package/dist/pregel/runner.cjs +1 -1
  246. package/dist/pregel/runner.cjs.map +1 -1
  247. package/dist/pregel/runner.js +1 -1
  248. package/dist/pregel/runner.js.map +1 -1
  249. package/dist/pregel/stream.cjs +4 -6
  250. package/dist/pregel/stream.cjs.map +1 -1
  251. package/dist/pregel/stream.js +1 -2
  252. package/dist/pregel/stream.js.map +1 -1
  253. package/dist/pregel/types.d.cts +5 -18
  254. package/dist/pregel/types.d.cts.map +1 -1
  255. package/dist/pregel/types.d.ts +5 -18
  256. package/dist/pregel/types.d.ts.map +1 -1
  257. package/dist/pregel/utils/config.cjs +6 -7
  258. package/dist/pregel/utils/config.cjs.map +1 -1
  259. package/dist/pregel/utils/config.d.cts.map +1 -1
  260. package/dist/pregel/utils/config.d.ts.map +1 -1
  261. package/dist/pregel/utils/config.js.map +1 -1
  262. package/dist/pregel/utils/index.cjs +1 -2
  263. package/dist/pregel/utils/index.cjs.map +1 -1
  264. package/dist/pregel/utils/index.d.cts +1 -1
  265. package/dist/pregel/utils/index.d.cts.map +1 -1
  266. package/dist/pregel/utils/index.d.ts +1 -1
  267. package/dist/pregel/utils/index.d.ts.map +1 -1
  268. package/dist/pregel/utils/index.js +1 -2
  269. package/dist/pregel/utils/index.js.map +1 -1
  270. package/dist/pregel/utils/subgraph.cjs +0 -1
  271. package/dist/pregel/utils/subgraph.cjs.map +1 -1
  272. package/dist/pregel/utils/subgraph.js +0 -1
  273. package/dist/pregel/utils/subgraph.js.map +1 -1
  274. package/dist/pregel/validate.cjs.map +1 -1
  275. package/dist/pregel/validate.js.map +1 -1
  276. package/dist/pregel/write.cjs +2 -3
  277. package/dist/pregel/write.cjs.map +1 -1
  278. package/dist/pregel/write.d.cts +1 -5
  279. package/dist/pregel/write.d.cts.map +1 -1
  280. package/dist/pregel/write.d.ts +1 -5
  281. package/dist/pregel/write.d.ts.map +1 -1
  282. package/dist/pregel/write.js.map +1 -1
  283. package/dist/setup/async_local_storage.cjs +3 -4
  284. package/dist/setup/async_local_storage.cjs.map +1 -1
  285. package/dist/setup/async_local_storage.js.map +1 -1
  286. package/dist/utils.cjs +9 -11
  287. package/dist/utils.cjs.map +1 -1
  288. package/dist/utils.d.cts +1 -8
  289. package/dist/utils.d.cts.map +1 -1
  290. package/dist/utils.d.ts +1 -8
  291. package/dist/utils.d.ts.map +1 -1
  292. package/dist/utils.js +1 -2
  293. package/dist/utils.js.map +1 -1
  294. package/dist/web.cjs +8 -9
  295. package/dist/writer.cjs +2 -3
  296. package/dist/writer.cjs.map +1 -1
  297. package/dist/writer.d.cts +1 -2
  298. package/dist/writer.d.cts.map +1 -1
  299. package/dist/writer.d.ts +1 -2
  300. package/dist/writer.d.ts.map +1 -1
  301. package/dist/writer.js.map +1 -1
  302. package/package.json +7 -7
  303. package/CHANGELOG.md +0 -286
  304. package/dist/_virtual/rolldown_runtime.cjs +0 -25
@@ -1 +1 @@
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 AIMessageFields,\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 const fields = (\n Object.keys(message.lc_kwargs ?? {}).length > 0\n ? message.lc_kwargs\n : message\n ) as AIMessageFields;\n\n return new AIMessage({\n ...fields,\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":";;;;AAcA,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,UAAU;EACvC,MAAM,SACJ,OAAO,KAAK,QAAQ,aAAa,IAAI,SAAS,IAC1C,QAAQ,YACR;AAGN,SAAO,IAAI,UA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;IACH,MAAM,aAAa;;;AAGvB,SAAO;;MAEN;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
+ {"version":3,"file":"agentName.js","names":[],"sources":["../../src/prebuilt/agentName.ts"],"sourcesContent":["import { LanguageModelLike } from \"@langchain/core/language_models/base\";\nimport {\n AIMessage,\n AIMessageFields,\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 const fields = (\n Object.keys(message.lc_kwargs ?? {}).length > 0\n ? message.lc_kwargs\n : message\n ) as AIMessageFields;\n\n return new AIMessage({\n ...fields,\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":";;;;AAcA,MAAM,eAAe;AACrB,MAAM,kBAAkB;;;;;;;;;;;;;;;;;AAoBxB,SAAgB,oBACd,SACe;AAMf,KAAI,EAJF,cAAc,QAAQ,KACrB,YAAY,QAAQ,IAClB,mBAAmB,QAAQ,IAAI,iBAAiB,QAAQ,MAEhD,CAAC,QAAQ,KACpB,QAAO;CAGT,MAAM,EAAE,SAAS;AAEjB,KAAI,OAAO,QAAQ,YAAY,SAO7B,QAAO,IAAI,UAAU;EACnB,GANA,OAAO,KAAK,QAAQ,aAAa,EAAE,CAAC,CAAC,SAAS,IAC1C,QAAQ,YACR;EAKJ,SAAS,SAAS,KAAK,kBAAkB,QAAQ,QAAQ;EACzD,MAAM;EACP,CAAC;CAGJ,MAAM,iBAAiB,EAAE;CACzB,IAAI,iBAAiB;AAErB,MAAK,MAAM,gBAAgB,QAAQ,QACjC,KAAI,OAAO,iBAAiB,UAAU;AACpC,oBAAkB;AAClB,iBAAe,KACb,SAAS,KAAK,kBAAkB,aAAa,YAC9C;YAED,OAAO,iBAAiB,YACxB,UAAU,gBACV,aAAa,SAAS,QACtB;AACA,oBAAkB;AAClB,iBAAe,KAAK;GAClB,GAAG;GACH,MAAM,SAAS,KAAK,kBAAkB,aAAa,KAAK;GACzD,CA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,CAAC,SAAS,IAC9C,QAAQ,YACR;EACJ,SAAS;EACT,MAAM;EACP,CAAC;;;;;;;;;;;;;;;;;;AAmBJ,SAAgB,cACd,OACA,eACmB;CACnB,IAAI;CACJ,IAAI;AAEJ,KAAI,kBAAkB,UAAU;AAC9B,wBAAsB;AACtB,yBAAuB;OAEvB,OAAM,IAAI,MACR,4BAA4B,cAAc,gCAC3C;CAGH,SAAS,qBACP,UACmB;AACnB,SAAO,SAAS,IAAI,oBAAoB;;AAG1C,QAAO,iBAAiB,KAAK;EAC3B,eAAe,KAAK,qBAAqB;EACzC;EACA,eAAe,KAAK,qBAAqB;EAC1C,CAAC"}
@@ -13,19 +13,17 @@ function createAgentExecutor({ agentRunnable, tools }) {
13
13
  return "continue";
14
14
  };
15
15
  const runAgent = async (data, config) => {
16
- const agentOutcome = await agentRunnable.invoke(data, config);
17
- return { agentOutcome };
16
+ return { agentOutcome: await agentRunnable.invoke(data, config) };
18
17
  };
19
18
  const executeTools = async (data, config) => {
20
19
  const agentAction = data.agentOutcome;
21
20
  if (!agentAction || "returnValues" in agentAction) throw new Error("Agent has not been run yet");
22
- const output = await toolExecutor.invoke(agentAction, config);
23
21
  return { steps: [{
24
22
  action: agentAction,
25
- observation: output
23
+ observation: await toolExecutor.invoke(agentAction, config)
26
24
  }] };
27
25
  };
28
- const workflow = new require_state.StateGraph({ channels: {
26
+ return new require_state.StateGraph({ channels: {
29
27
  input: null,
30
28
  agentOutcome: null,
31
29
  steps: {
@@ -35,8 +33,7 @@ function createAgentExecutor({ agentRunnable, tools }) {
35
33
  } }).addNode("agent", runAgent).addNode("action", executeTools).addEdge(require_constants.START, "agent").addConditionalEdges("agent", shouldContinue, {
36
34
  continue: "action",
37
35
  end: require_constants.END
38
- }).addEdge("action", "agent");
39
- return workflow.compile();
36
+ }).addEdge("action", "agent").compile();
40
37
  }
41
38
 
42
39
  //#endregion
@@ -1 +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"}
1
+ {"version":3,"file":"agent_executor.cjs","names":["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,IAAI;AACJ,KAAI,CAAC,MAAM,QAAQ,MAAM,CACvB,gBAAe;KAEf,gBAAe,IAAIA,mCAAa,EAC9B,OACD,CAAC;CAIJ,MAAM,kBAAkB,SAA6B;AACnD,MAAI,KAAK,gBAAgB,kBAAkB,KAAK,aAC9C,QAAO;AAET,SAAO;;CAGT,MAAM,WAAW,OACf,MACA,WACG;AAEH,SAAO,EACL,cAFmB,MAAM,cAAc,OAAO,MAAM,OAAO,EAG5D;;CAGH,MAAM,eAAe,OACnB,MACA,WACyC;EACzC,MAAM,cAAc,KAAK;AACzB,MAAI,CAAC,eAAe,kBAAkB,YACpC,OAAM,IAAI,MAAM,6BAA6B;AAG/C,SAAO,EACL,OAAO,CAAC;GAAE,QAAQ;GAAa,aAFlB,MAAM,aAAa,OAAO,aAAa,OAAO;GAEP,CAAC,EACtD;;AAiDH,QA7CiB,IAAIC,yBAKlB,EACD,UAAU;EACR,OAAO;EACP,cAAc;EACd,OAAO;GACL,UAAU,GAAW,MAAc,EAAE,OAAO,EAAE;GAC9C,eAAe,EAAE;GAClB;EACF,EACF,CAAC,CAEC,QAAQ,SAAS,SAAS,CAC1B,QAAQ,UAAU,aAAa,CAG/B,QAAQC,yBAAO,QAAQ,CAEvB,oBAGC,SAEA,gBAOA;EAEE,UAAU;EAEV,KAAKC;EACN,CACF,CAGA,QAAQ,UAAU,QAAQ,CAEb,SAAS"}
@@ -3,7 +3,7 @@ import { StateDefinition } from "../graph/annotation.cjs";
3
3
  import { CompiledStateGraph } from "../graph/state.cjs";
4
4
  import { ToolExecutor } from "./tool_executor.cjs";
5
5
  import { Runnable } from "@langchain/core/runnables";
6
- import * as _langchain_core_messages1 from "@langchain/core/messages";
6
+ import * as _langchain_core_messages0 from "@langchain/core/messages";
7
7
  import { BaseMessage } from "@langchain/core/messages";
8
8
  import { AgentAction, AgentFinish } from "@langchain/core/agents";
9
9
  import { Tool } from "@langchain/core/tools";
@@ -31,22 +31,22 @@ declare function createAgentExecutor({
31
31
  agentOutcome?: AgentAction | AgentFinish | undefined;
32
32
  steps: Step[];
33
33
  input: string;
34
- chatHistory?: BaseMessage<_langchain_core_messages1.MessageStructure, _langchain_core_messages1.MessageType>[] | undefined;
34
+ chatHistory?: BaseMessage<_langchain_core_messages0.MessageStructure<_langchain_core_messages0.MessageToolSet>, _langchain_core_messages0.MessageType>[] | undefined;
35
35
  }, {
36
36
  agentOutcome?: AgentAction | AgentFinish | undefined;
37
37
  steps?: Step[] | undefined;
38
38
  input?: string | undefined;
39
- chatHistory?: BaseMessage<_langchain_core_messages1.MessageStructure, _langchain_core_messages1.MessageType>[] | undefined;
39
+ chatHistory?: BaseMessage<_langchain_core_messages0.MessageStructure<_langchain_core_messages0.MessageToolSet>, _langchain_core_messages0.MessageType>[] | undefined;
40
40
  }, "__start__" | "action" | "agent", {
41
41
  agentOutcome?: BaseChannel<AgentAction | AgentFinish | undefined, AgentAction | AgentFinish | undefined, unknown> | undefined;
42
42
  steps: BaseChannel<Step[], Step[], unknown>;
43
43
  input: BaseChannel<string, string, unknown>;
44
- chatHistory?: BaseChannel<BaseMessage<_langchain_core_messages1.MessageStructure, _langchain_core_messages1.MessageType>[] | undefined, BaseMessage<_langchain_core_messages1.MessageStructure, _langchain_core_messages1.MessageType>[] | undefined, unknown> | undefined;
44
+ chatHistory?: BaseChannel<BaseMessage<_langchain_core_messages0.MessageStructure<_langchain_core_messages0.MessageToolSet>, _langchain_core_messages0.MessageType>[] | undefined, BaseMessage<_langchain_core_messages0.MessageStructure<_langchain_core_messages0.MessageToolSet>, _langchain_core_messages0.MessageType>[] | undefined, unknown> | undefined;
45
45
  }, {
46
46
  agentOutcome?: BaseChannel<AgentAction | AgentFinish | undefined, AgentAction | AgentFinish | undefined, unknown> | undefined;
47
47
  steps: BaseChannel<Step[], Step[], unknown>;
48
48
  input: BaseChannel<string, string, unknown>;
49
- chatHistory?: BaseChannel<BaseMessage<_langchain_core_messages1.MessageStructure, _langchain_core_messages1.MessageType>[] | undefined, BaseMessage<_langchain_core_messages1.MessageStructure, _langchain_core_messages1.MessageType>[] | undefined, unknown> | undefined;
49
+ chatHistory?: BaseChannel<BaseMessage<_langchain_core_messages0.MessageStructure<_langchain_core_messages0.MessageToolSet>, _langchain_core_messages0.MessageType>[] | undefined, BaseMessage<_langchain_core_messages0.MessageStructure<_langchain_core_messages0.MessageToolSet>, _langchain_core_messages0.MessageType>[] | undefined, unknown> | undefined;
50
50
  }, StateDefinition, {
51
51
  action: Partial<AgentExecutorState>;
52
52
  agent: {
@@ -1 +1 @@
1
- {"version":3,"file":"agent_executor.d.cts","names":["___web_js0","AgentAction","AgentFinish","BaseMessage","Runnable","Tool","ToolExecutor","BaseChannel","Step","AgentExecutorState","Array","createAgentExecutor","agentRunnable","tools","_langchain_core_messages1","MessageStructure","MessageType","StateDefinition","Partial","CompiledStateGraph"],"sources":["../../src/prebuilt/agent_executor.d.ts"],"sourcesContent":["import { AgentAction, AgentFinish } from \"@langchain/core/agents\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { Runnable } from \"@langchain/core/runnables\";\nimport { Tool } from \"@langchain/core/tools\";\nimport { ToolExecutor } from \"./tool_executor.js\";\nimport type { BaseChannel } from \"../channels/base.js\";\ninterface Step {\n action: AgentAction | AgentFinish;\n observation: unknown;\n}\n/** @ignore */\nexport interface AgentExecutorState {\n agentOutcome?: AgentAction | AgentFinish;\n steps: Array<Step>;\n input: string;\n chatHistory?: BaseMessage[];\n}\n/** @ignore */\nexport declare function createAgentExecutor({ agentRunnable, tools }: {\n agentRunnable: Runnable;\n tools: Array<Tool> | ToolExecutor;\n}): import(\"../web.js\").CompiledStateGraph<{\n agentOutcome?: AgentAction | AgentFinish | undefined;\n steps: Step[];\n input: string;\n chatHistory?: BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[] | undefined;\n}, {\n agentOutcome?: AgentAction | AgentFinish | undefined;\n steps?: Step[] | undefined;\n input?: string | undefined;\n chatHistory?: BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[] | undefined;\n}, \"__start__\" | \"action\" | \"agent\", {\n agentOutcome?: BaseChannel<AgentAction | AgentFinish | undefined, AgentAction | AgentFinish | undefined, unknown> | undefined;\n steps: BaseChannel<Step[], Step[], unknown>;\n input: BaseChannel<string, string, unknown>;\n chatHistory?: BaseChannel<BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[] | undefined, BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[] | undefined, unknown> | undefined;\n}, {\n agentOutcome?: BaseChannel<AgentAction | AgentFinish | undefined, AgentAction | AgentFinish | undefined, unknown> | undefined;\n steps: BaseChannel<Step[], Step[], unknown>;\n input: BaseChannel<string, string, unknown>;\n chatHistory?: BaseChannel<BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[] | undefined, BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[] | undefined, unknown> | undefined;\n}, import(\"../web.js\").StateDefinition, {\n action: Partial<AgentExecutorState>;\n agent: {\n agentOutcome: any;\n };\n}, unknown, unknown>;\nexport {};\n"],"mappings":";;;;;;;;;;;UAMUQ,IAAAA;UACEP,cAAcC;;;;AADhBM,UAKOC,kBAAAA,CALH;EAAA,YAAA,CAAA,EAMKR,WANL,GAMmBC,WANnB;OACFD,EAMDS,KANCT,CAMKO,IANLP,CAAAA;OAAcC,EAAAA,MAAAA;gBAQRC;AAJlB;;AACmBF,iBAMKU,mBAAAA,CANLV;EAAAA,aAAAA;EAAAA;CAAAA,EAAAA;eAAcC,EAOdE,QAPcF;OAChBM,EAONE,KAPMF,CAOAH,IAPAG,CAAAA,GAOQF,YAPRE;sBAANE,CAAAA;cAEOP,CAAAA,EAOCF,WAPDE,GAOeD,WAPfC,GAAAA,SAAAA;SAQPK;EALaG,KAAAA,EAAAA,MAAAA;EAAmB,WAAA,CAAA,EAOzBR,WAPyB,CAK5BW,yBAAAA,CAEkDC,gBAAAA,EAAgBD,yBAAAA,CAAqCE,WAAAA,CAP3E,EAAA,GAAA,SAAA;;cAAkBH,CAAAA,EAS1CZ,WAT0CY,GAS5BX,WAT4BW,GAAAA,SAAAA;OAC1CT,CAAAA,EASPI,IATOJ,EAAAA,GAAAA,SAAAA;OACFC,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;aAANK,CAAAA,EAUOP,WAVPO,CAQKI,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AA,CAAoKC,gBAAAA,EAAgBD,yBAAAA,CAAqCE,WAAAA,CAZtPR,EAAAA,GAAAA,SAAAA,EAAAA,OAAAA,CAAAA,GAAAA,SAAAA;oBAEqDO;QAAgBD,EAYrEI,OAZqEJ,CAY7DL,kBAZkGO,CAAAA;OAApGb,EAAAA;IAEaF,YAAAA,EAAAA,GAAAA;;UAAuCA,EAAAA,OAAAA,CAAAA"}
1
+ {"version":3,"file":"agent_executor.d.cts","names":["___web_js0","AgentAction","AgentFinish","BaseMessage","Runnable","Tool","ToolExecutor","BaseChannel","Step","AgentExecutorState","Array","createAgentExecutor","agentRunnable","tools","_langchain_core_messages0","MessageToolSet","MessageStructure","MessageType","StateDefinition","Partial","CompiledStateGraph"],"sources":["../../src/prebuilt/agent_executor.d.ts"],"sourcesContent":["import { AgentAction, AgentFinish } from \"@langchain/core/agents\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { Runnable } from \"@langchain/core/runnables\";\nimport { Tool } from \"@langchain/core/tools\";\nimport { ToolExecutor } from \"./tool_executor.js\";\nimport type { BaseChannel } from \"../channels/base.js\";\ninterface Step {\n action: AgentAction | AgentFinish;\n observation: unknown;\n}\n/** @ignore */\nexport interface AgentExecutorState {\n agentOutcome?: AgentAction | AgentFinish;\n steps: Array<Step>;\n input: string;\n chatHistory?: BaseMessage[];\n}\n/** @ignore */\nexport declare function createAgentExecutor({ agentRunnable, tools }: {\n agentRunnable: Runnable;\n tools: Array<Tool> | ToolExecutor;\n}): import(\"../web.js\").CompiledStateGraph<{\n agentOutcome?: AgentAction | AgentFinish | undefined;\n steps: Step[];\n input: string;\n chatHistory?: BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[] | undefined;\n}, {\n agentOutcome?: AgentAction | AgentFinish | undefined;\n steps?: Step[] | undefined;\n input?: string | undefined;\n chatHistory?: BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[] | undefined;\n}, \"__start__\" | \"action\" | \"agent\", {\n agentOutcome?: BaseChannel<AgentAction | AgentFinish | undefined, AgentAction | AgentFinish | undefined, unknown> | undefined;\n steps: BaseChannel<Step[], Step[], unknown>;\n input: BaseChannel<string, string, unknown>;\n chatHistory?: BaseChannel<BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[] | undefined, BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[] | undefined, unknown> | undefined;\n}, {\n agentOutcome?: BaseChannel<AgentAction | AgentFinish | undefined, AgentAction | AgentFinish | undefined, unknown> | undefined;\n steps: BaseChannel<Step[], Step[], unknown>;\n input: BaseChannel<string, string, unknown>;\n chatHistory?: BaseChannel<BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[] | undefined, BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[] | undefined, unknown> | undefined;\n}, import(\"../web.js\").StateDefinition, {\n action: Partial<AgentExecutorState>;\n agent: {\n agentOutcome: any;\n };\n}, unknown, unknown>;\nexport {};\n"],"mappings":";;;;;;;;;;;UAMUQ,IAAAA;UACEP,cAAcC;;;;AADhBM,UAKOC,kBAAAA,CALH;EAAA,YAAA,CAAA,EAMKR,WANL,GAMmBC,WANnB;OACFD,EAMDS,KANCT,CAMKO,IANLP,CAAAA;OAAcC,EAAAA,MAAAA;EAAW,WAAA,CAAA,EAQnBC,WARmB,EAAA;AAIrC;;AACmBF,iBAMKU,mBAAAA,CANLV;EAAAA,aAAAA;EAAAA;CAAAA,EAAAA;eAAcC,EAOdE,QAPcF;OAChBM,EAONE,KAPMF,CAOAH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D,yBAAAA,CAAlEE,gBAV3ID,CAU5ED,yBAAAA,CAA2QC,cAAAA,CAV/LA,EAU2JD,yBAAAA,CAAwFG,WAAAA,CAVnPF,EAAAA,GAAAA,SAAAA,EAAAA,OAAAA,CAAAA,GAAAA,SAAAA;;cAApCD,CAAAA,EAY9DP,WAZ8DO,CAYlDb,WAZ0IgB,GAY5Hf,WAZ4He,GAAAA,SAAAA,EAYnGhB,WAZmGgB,GAYrFf,WAZqFe,GAAAA,SAAAA,EAAAA,OAAAA,CAAAA,GAAAA,SAAAA;OAAvJd,EAaPI,WAbOJ,CAaKK,IAbLL,EAAAA,EAaaK,IAbbL,EAAAA,EAAAA,OAAAA,CAAAA;OAECF,EAYRM,WAZQN,CAAAA,MAAAA,EAAAA,MAAAA,EAAAA,OAAAA,CAAAA;aAAcC,CAAAA,EAafK,WAbeL,CAaHC,WAbGD,CAa8GY,yBAAAA,CAAlEE,gBAb5Cd,CAYXY,yBAAAA,CAC2GC,cAAAA,CAbhGb,EAa4DY,yBAAAA,CAAwFG,WAAAA,CAbpJf,EAAAA,GAAAA,SAAAA,EAagLC,WAbhLD,CAaiSY,yBAAAA,CAAlEE,gBAb/Nd,CAaQY,yBAAAA,CAA2QC,cAAAA,CAbnRb,EAa+OY,yBAAAA,CAAwFG,WAAAA,CAbvUf,EAAAA,GAAAA,SAAAA,EAAAA,OAAAA,CAAAA,GAAAA,SAAAA;GAaJF,eAAAA,EAZjBQ;QAAIM,EAcJK,OAdIL,CAcIL,kBAZiGM,CAAAA;OAAcD,EAAAA;IAAlDA,YAAAA,EAAAA,GAAAA;;UAElDb,EAAAA,OAAAA,CAAAA"}
@@ -3,7 +3,7 @@ import { StateDefinition } from "../graph/annotation.js";
3
3
  import { CompiledStateGraph } from "../graph/state.js";
4
4
  import { ToolExecutor } from "./tool_executor.js";
5
5
  import { Runnable } from "@langchain/core/runnables";
6
- import * as _langchain_core_messages1 from "@langchain/core/messages";
6
+ import * as _langchain_core_messages0 from "@langchain/core/messages";
7
7
  import { BaseMessage } from "@langchain/core/messages";
8
8
  import { AgentAction, AgentFinish } from "@langchain/core/agents";
9
9
  import { Tool } from "@langchain/core/tools";
@@ -31,22 +31,22 @@ declare function createAgentExecutor({
31
31
  agentOutcome?: AgentAction | AgentFinish | undefined;
32
32
  steps: Step[];
33
33
  input: string;
34
- chatHistory?: BaseMessage<_langchain_core_messages1.MessageStructure, _langchain_core_messages1.MessageType>[] | undefined;
34
+ chatHistory?: BaseMessage<_langchain_core_messages0.MessageStructure<_langchain_core_messages0.MessageToolSet>, _langchain_core_messages0.MessageType>[] | undefined;
35
35
  }, {
36
36
  agentOutcome?: AgentAction | AgentFinish | undefined;
37
37
  steps?: Step[] | undefined;
38
38
  input?: string | undefined;
39
- chatHistory?: BaseMessage<_langchain_core_messages1.MessageStructure, _langchain_core_messages1.MessageType>[] | undefined;
39
+ chatHistory?: BaseMessage<_langchain_core_messages0.MessageStructure<_langchain_core_messages0.MessageToolSet>, _langchain_core_messages0.MessageType>[] | undefined;
40
40
  }, "__start__" | "action" | "agent", {
41
41
  agentOutcome?: BaseChannel<AgentAction | AgentFinish | undefined, AgentAction | AgentFinish | undefined, unknown> | undefined;
42
42
  steps: BaseChannel<Step[], Step[], unknown>;
43
43
  input: BaseChannel<string, string, unknown>;
44
- chatHistory?: BaseChannel<BaseMessage<_langchain_core_messages1.MessageStructure, _langchain_core_messages1.MessageType>[] | undefined, BaseMessage<_langchain_core_messages1.MessageStructure, _langchain_core_messages1.MessageType>[] | undefined, unknown> | undefined;
44
+ chatHistory?: BaseChannel<BaseMessage<_langchain_core_messages0.MessageStructure<_langchain_core_messages0.MessageToolSet>, _langchain_core_messages0.MessageType>[] | undefined, BaseMessage<_langchain_core_messages0.MessageStructure<_langchain_core_messages0.MessageToolSet>, _langchain_core_messages0.MessageType>[] | undefined, unknown> | undefined;
45
45
  }, {
46
46
  agentOutcome?: BaseChannel<AgentAction | AgentFinish | undefined, AgentAction | AgentFinish | undefined, unknown> | undefined;
47
47
  steps: BaseChannel<Step[], Step[], unknown>;
48
48
  input: BaseChannel<string, string, unknown>;
49
- chatHistory?: BaseChannel<BaseMessage<_langchain_core_messages1.MessageStructure, _langchain_core_messages1.MessageType>[] | undefined, BaseMessage<_langchain_core_messages1.MessageStructure, _langchain_core_messages1.MessageType>[] | undefined, unknown> | undefined;
49
+ chatHistory?: BaseChannel<BaseMessage<_langchain_core_messages0.MessageStructure<_langchain_core_messages0.MessageToolSet>, _langchain_core_messages0.MessageType>[] | undefined, BaseMessage<_langchain_core_messages0.MessageStructure<_langchain_core_messages0.MessageToolSet>, _langchain_core_messages0.MessageType>[] | undefined, unknown> | undefined;
50
50
  }, StateDefinition, {
51
51
  action: Partial<AgentExecutorState>;
52
52
  agent: {
@@ -1 +1 @@
1
- {"version":3,"file":"agent_executor.d.ts","names":["___web_js0","AgentAction","AgentFinish","BaseMessage","Runnable","Tool","ToolExecutor","BaseChannel","Step","AgentExecutorState","Array","createAgentExecutor","agentRunnable","tools","_langchain_core_messages1","MessageStructure","MessageType","StateDefinition","Partial","CompiledStateGraph"],"sources":["../../src/prebuilt/agent_executor.d.ts"],"sourcesContent":["import { AgentAction, AgentFinish } from \"@langchain/core/agents\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { Runnable } from \"@langchain/core/runnables\";\nimport { Tool } from \"@langchain/core/tools\";\nimport { ToolExecutor } from \"./tool_executor.js\";\nimport type { BaseChannel } from \"../channels/base.js\";\ninterface Step {\n action: AgentAction | AgentFinish;\n observation: unknown;\n}\n/** @ignore */\nexport interface AgentExecutorState {\n agentOutcome?: AgentAction | AgentFinish;\n steps: Array<Step>;\n input: string;\n chatHistory?: BaseMessage[];\n}\n/** @ignore */\nexport declare function createAgentExecutor({ agentRunnable, tools }: {\n agentRunnable: Runnable;\n tools: Array<Tool> | ToolExecutor;\n}): import(\"../web.js\").CompiledStateGraph<{\n agentOutcome?: AgentAction | AgentFinish | undefined;\n steps: Step[];\n input: string;\n chatHistory?: BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[] | undefined;\n}, {\n agentOutcome?: AgentAction | AgentFinish | undefined;\n steps?: Step[] | undefined;\n input?: string | undefined;\n chatHistory?: BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[] | undefined;\n}, \"__start__\" | \"action\" | \"agent\", {\n agentOutcome?: BaseChannel<AgentAction | AgentFinish | undefined, AgentAction | AgentFinish | undefined, unknown> | undefined;\n steps: BaseChannel<Step[], Step[], unknown>;\n input: BaseChannel<string, string, unknown>;\n chatHistory?: BaseChannel<BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[] | undefined, BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[] | undefined, unknown> | undefined;\n}, {\n agentOutcome?: BaseChannel<AgentAction | AgentFinish | undefined, AgentAction | AgentFinish | undefined, unknown> | undefined;\n steps: BaseChannel<Step[], Step[], unknown>;\n input: BaseChannel<string, string, unknown>;\n chatHistory?: BaseChannel<BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[] | undefined, BaseMessage<import(\"@langchain/core/messages\").MessageStructure, import(\"@langchain/core/messages\").MessageType>[] | undefined, unknown> | undefined;\n}, import(\"../web.js\").StateDefinition, {\n action: Partial<AgentExecutorState>;\n agent: {\n agentOutcome: any;\n };\n}, unknown, unknown>;\nexport {};\n"],"mappings":";;;;;;;;;;;UAMUQ,IAAAA;UACEP,cAAcC;;;;AADhBM,UAKOC,kBAAAA,CALH;EAAA,YAAA,CAAA,EAMKR,WANL,GAMmBC,WANnB;OACFD,EAMDS,KANCT,CAMKO,IANLP,CAAAA;OAAcC,EAAAA,MAAAA;gBAQRC;AAJlB;;AACmBF,iBAMKU,mBAAAA,CANLV;EAAAA,aAAAA;EAAAA;CAAAA,EAAAA;eAAcC,EAOdE,QAPcF;OAChBM,EAONE,KAPMF,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J,CAYaF,WAZbE,GAY2BD,WAZ3BC,GAAAA,SAAAA,EAYoDF,WAZpDE,GAYkED,WAZlEC,GAAAA,SAAAA,EAAAA,OAAAA,CAAAA,GAAAA,SAAAA;OAECF,EAWRM,WAXQN,CAWIO,IAXJP,EAAAA,EAWYO,IAXZP,EAAAA,EAAAA,OAAAA,CAAAA;OAAcC,EAYtBK,WAZsBL,CAAAA,MAAAA,EAAAA,MAAAA,EAAAA,OAAAA,CAAAA;aACrBM,CAAAA,EAYMD,WAZNC,CAYkBL,WAZlBK,CAWUM,yBAAAA,CACuDC,gBAAAA,EAAgBD,yBAAAA,CAAqCE,WAAAA,CAZtHR,EAAAA,GAAAA,SAAAA,EAYkJL,WAZlJK,CAY6BM,yBAAAA,CAAoKC,gBAAAA,EAAgBD,yBAAAA,CAAqCE,WAAAA,CAZtPR,EAAAA,GAAAA,SAAAA,EAAAA,OAAAA,CAAAA,GAAAA,SAAAA;oBAEqDO;QAAgBD,EAYrEI,OAZqEJ,CAY7DL,kBAZkGO,CAAAA;OAApGb,EAAAA;IAEaF,YAAAA,EAAAA,GAAAA;;UAAuCA,EAAAA,OAAAA,CAAAA"}
1
+ {"version":3,"file":"agent_executor.d.ts","names":["___web_js0","AgentAction","AgentFinish","BaseMessage","Runnable","Tool","ToolExecutor","BaseChannel","Step","AgentExecutorState","Array","createAgentExecutor","agentRunnable","tools","_langchain_core_messages0","MessageToolSet","MessageStructure","MessageType","StateDefinition","Partial","CompiledStateGraph"],"sources":["../../src/prebuilt/agent_executor.d.ts"],"sourcesContent":["import { AgentAction, AgentFinish } from \"@langchain/core/agents\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { Runnable } from \"@langchain/core/runnables\";\nimport { Tool } from \"@langchain/core/tools\";\nimport { ToolExecutor } from \"./tool_executor.js\";\nimport type { BaseChannel } from \"../channels/base.js\";\ninterface Step {\n action: AgentAction | AgentFinish;\n observation: unknown;\n}\n/** @ignore */\nexport interface AgentExecutorState {\n agentOutcome?: AgentAction | AgentFinish;\n steps: Array<Step>;\n input: string;\n chatHistory?: BaseMessage[];\n}\n/** @ignore */\nexport declare function createAgentExecutor({ agentRunnable, tools }: {\n agentRunnable: Runnable;\n tools: Array<Tool> | ToolExecutor;\n}): import(\"../web.js\").CompiledStateGraph<{\n agentOutcome?: AgentAction | AgentFinish | undefined;\n steps: Step[];\n input: string;\n chatHistory?: BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[] | undefined;\n}, {\n agentOutcome?: AgentAction | AgentFinish | undefined;\n steps?: Step[] | undefined;\n input?: string | undefined;\n chatHistory?: BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[] | undefined;\n}, \"__start__\" | \"action\" | \"agent\", {\n agentOutcome?: BaseChannel<AgentAction | AgentFinish | undefined, AgentAction | AgentFinish | undefined, unknown> | undefined;\n steps: BaseChannel<Step[], Step[], unknown>;\n input: BaseChannel<string, string, unknown>;\n chatHistory?: BaseChannel<BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[] | undefined, BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[] | undefined, unknown> | undefined;\n}, {\n agentOutcome?: BaseChannel<AgentAction | AgentFinish | undefined, AgentAction | AgentFinish | undefined, unknown> | undefined;\n steps: BaseChannel<Step[], Step[], unknown>;\n input: BaseChannel<string, string, unknown>;\n chatHistory?: BaseChannel<BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[] | undefined, BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[] | undefined, unknown> | undefined;\n}, import(\"../web.js\").StateDefinition, {\n action: Partial<AgentExecutorState>;\n agent: {\n agentOutcome: any;\n };\n}, unknown, unknown>;\nexport {};\n"],"mappings":";;;;;;;;;;;UAMUQ,IAAAA;UACEP,cAAcC;;;;AADhBM,UAKOC,kBAAAA,CALH;EAAA,YAAA,CAAA,EAMKR,WANL,GAMmBC,WANnB;OACFD,EAMDS,KANCT,CAMKO,IANLP,CAAAA;OAAcC,EAAAA,MAAAA;EAAW,WAAA,CAAA,EAQnBC,WARmB,EAAA;AAIrC;;AACmBF,iBAMKU,mBAAAA,CANLV;EAAAA,aAAAA;EAAAA;CAAAA,EAAAA;eAAcC,EAOdE,QAPcF;OAChBM,EAONE,KAPMF,CAOAH,IAPAG,CAAAA,GAOQF,YAPRE;IA6BER,kBA7BRU,CAAAA;cAEOP,CAAAA,EAOCF,WAPDE,GAOeD,WAPfC,GAAAA,SAAAA;EAAW,KAAA,EAQlBK,IARkB,EAAA;EAGLG,KAAAA,EAAAA,MAAAA;EAAmB,WAAA,CAAA,EAOzBR,WAPyB,CAOwFW,yBAAAA,CAAlEE,gBAPtB,CAK5BF,yBAAAA,CAEsGC,cAAAA,CAP1E,EAOsCD,yBAAAA,CAAwFG,WAAAA,CAP9H,EAAA,GAAA,SAAA;;cAAkBJ,CAAAA,EAS1CZ,WAT0CY,GAS5BX,WAT4BW,GAAAA,SAAAA;OAC1CT,CAAAA,EASPI,IATOJ,EAAAA,GAAAA,SAAAA;OACFC,CAAAA,EAAAA,MAAAA,GAAAA,SAAAA;aAANK,CAAAA,EAUOP,WAVPO,CAUwHI,yBAAAA,CAAlEE,gBAVtDN,CAQKI,yBAAAA,CAEqGC,cAAAA,CAV1GL,EAUsEI,yBAAAA,CAAwFG,WAAAA,CAV9JP,EAAAA,GAAAA,SAAAA;cAAcJ,GAAAA,QAAAA,GAAAA,OAAAA,EAAAA;cAENL,CAAAA,EAUAM,WAVAN,CAUYA,WAVZA,GAU0BC,WAV1BD,G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Rb,EAa+OY,yBAAAA,CAAwFG,WAAAA,CAbvUf,EAAAA,GAAAA,SAAAA,EAAAA,OAAAA,CAAAA,GAAAA,SAAAA;GAaJF,eAAAA,EAZjBQ;QAAIM,EAcJK,OAdIL,CAcIL,kBAZiGM,CAAAA;OAAcD,EAAAA;IAAlDA,YAAAA,EAAAA,GAAAA;;UAElDb,EAAAA,OAAAA,CAAAA"}
@@ -13,19 +13,17 @@ function createAgentExecutor({ agentRunnable, tools }) {
13
13
  return "continue";
14
14
  };
15
15
  const runAgent = async (data, config) => {
16
- const agentOutcome = await agentRunnable.invoke(data, config);
17
- return { agentOutcome };
16
+ return { agentOutcome: await agentRunnable.invoke(data, config) };
18
17
  };
19
18
  const executeTools = async (data, config) => {
20
19
  const agentAction = data.agentOutcome;
21
20
  if (!agentAction || "returnValues" in agentAction) throw new Error("Agent has not been run yet");
22
- const output = await toolExecutor.invoke(agentAction, config);
23
21
  return { steps: [{
24
22
  action: agentAction,
25
- observation: output
23
+ observation: await toolExecutor.invoke(agentAction, config)
26
24
  }] };
27
25
  };
28
- const workflow = new StateGraph({ channels: {
26
+ return new StateGraph({ channels: {
29
27
  input: null,
30
28
  agentOutcome: null,
31
29
  steps: {
@@ -35,8 +33,7 @@ function createAgentExecutor({ agentRunnable, tools }) {
35
33
  } }).addNode("agent", runAgent).addNode("action", executeTools).addEdge(START, "agent").addConditionalEdges("agent", shouldContinue, {
36
34
  continue: "action",
37
35
  end: END
38
- }).addEdge("action", "agent");
39
- return workflow.compile();
36
+ }).addEdge("action", "agent").compile();
40
37
  }
41
38
 
42
39
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"agent_executor.js","names":["toolExecutor: ToolExecutor"],"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,IAAI,aAAa,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,IAAI,WAKlB,EACD,UAAU;EACR,OAAO;EACP,cAAc;EACd,OAAO;GACL,UAAU,GAAW,MAAc,EAAE,OAAO;GAC5C,eAAe;;MAKlB,QAAQ,SAAS,UACjB,QAAQ,UAAU,cAGlB,QAAQ,OAAO,SAEf,oBAGC,SAEA,gBAOA;EAEE,UAAU;EAEV,KAAK;IAKR,QAAQ,UAAU;AAErB,QAAO,SAAS"}
1
+ {"version":3,"file":"agent_executor.js","names":[],"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,IAAI;AACJ,KAAI,CAAC,MAAM,QAAQ,MAAM,CACvB,gBAAe;KAEf,gBAAe,IAAI,aAAa,EAC9B,OACD,CAAC;CAIJ,MAAM,kBAAkB,SAA6B;AACnD,MAAI,KAAK,gBAAgB,kBAAkB,KAAK,aAC9C,QAAO;AAET,SAAO;;CAGT,MAAM,WAAW,OACf,MACA,WACG;AAEH,SAAO,EACL,cAFmB,MAAM,cAAc,OAAO,MAAM,OAAO,EAG5D;;CAGH,MAAM,eAAe,OACnB,MACA,WACyC;EACzC,MAAM,cAAc,KAAK;AACzB,MAAI,CAAC,eAAe,kBAAkB,YACpC,OAAM,IAAI,MAAM,6BAA6B;AAG/C,SAAO,EACL,OAAO,CAAC;GAAE,QAAQ;GAAa,aAFlB,MAAM,aAAa,OAAO,aAAa,OAAO;GAEP,CAAC,EACtD;;AAiDH,QA7CiB,IAAI,WAKlB,EACD,UAAU;EACR,OAAO;EACP,cAAc;EACd,OAAO;GACL,UAAU,GAAW,MAAc,EAAE,OAAO,EAAE;GAC9C,eAAe,EAAE;GAClB;EACF,EACF,CAAC,CAEC,QAAQ,SAAS,SAAS,CAC1B,QAAQ,UAAU,aAAa,CAG/B,QAAQ,OAAO,QAAQ,CAEvB,oBAGC,SAEA,gBAOA;EAEE,UAAU;EAEV,KAAK;EACN,CACF,CAGA,QAAQ,UAAU,QAAQ,CAEb,SAAS"}
@@ -1,10 +1,9 @@
1
- const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
1
  const require_constants = require('../constants.cjs');
3
2
  const require_state = require('../graph/state.cjs');
4
3
  const require_tool_executor = require('./tool_executor.cjs');
5
- const __langchain_core_runnables = require_rolldown_runtime.__toESM(require("@langchain/core/runnables"));
6
- const __langchain_core_messages = require_rolldown_runtime.__toESM(require("@langchain/core/messages"));
7
- const __langchain_core_utils_function_calling = require_rolldown_runtime.__toESM(require("@langchain/core/utils/function_calling"));
4
+ let _langchain_core_runnables = require("@langchain/core/runnables");
5
+ let _langchain_core_messages = require("@langchain/core/messages");
6
+ let _langchain_core_utils_function_calling = require("@langchain/core/utils/function_calling");
8
7
 
9
8
  //#region src/prebuilt/chat_agent_executor.ts
10
9
  /** @deprecated Use {@link createReactAgent} instead with tool calling. */
@@ -19,7 +18,7 @@ function createFunctionCallingExecutor({ model, tools }) {
19
18
  toolClasses = tools;
20
19
  }
21
20
  if (!("bind" in model) || typeof model.bind !== "function") throw new Error("Model must be bindable");
22
- const toolsAsOpenAIFunctions = toolClasses.map((tool) => (0, __langchain_core_utils_function_calling.convertToOpenAIFunction)(tool));
21
+ const toolsAsOpenAIFunctions = toolClasses.map((tool) => (0, _langchain_core_utils_function_calling.convertToOpenAIFunction)(tool));
23
22
  const newModel = model.bind({ functions: toolsAsOpenAIFunctions });
24
23
  const shouldContinue = (state) => {
25
24
  const { messages } = state;
@@ -29,8 +28,7 @@ function createFunctionCallingExecutor({ model, tools }) {
29
28
  };
30
29
  const callModel = async (state, config) => {
31
30
  const { messages } = state;
32
- const response = await newModel.invoke(messages, config);
33
- return { messages: [response] };
31
+ return { messages: [await newModel.invoke(messages, config)] };
34
32
  };
35
33
  const _getAction = (state) => {
36
34
  const { messages } = state;
@@ -45,22 +43,18 @@ function createFunctionCallingExecutor({ model, tools }) {
45
43
  };
46
44
  const callTool = async (state, config) => {
47
45
  const action = _getAction(state);
48
- const response = await toolExecutor.invoke(action, config);
49
- const functionMessage = new __langchain_core_messages.FunctionMessage({
50
- content: response,
46
+ return { messages: [new _langchain_core_messages.FunctionMessage({
47
+ content: await toolExecutor.invoke(action, config),
51
48
  name: action.tool
52
- });
53
- return { messages: [functionMessage] };
49
+ })] };
54
50
  };
55
- const schema = { messages: {
51
+ return new require_state.StateGraph({ channels: { messages: {
56
52
  value: (x, y) => x.concat(y),
57
53
  default: () => []
58
- } };
59
- const workflow = new require_state.StateGraph({ channels: schema }).addNode("agent", new __langchain_core_runnables.RunnableLambda({ func: callModel })).addNode("action", new __langchain_core_runnables.RunnableLambda({ func: callTool })).addEdge(require_constants.START, "agent").addConditionalEdges("agent", shouldContinue, {
54
+ } } }).addNode("agent", new _langchain_core_runnables.RunnableLambda({ func: callModel })).addNode("action", new _langchain_core_runnables.RunnableLambda({ func: callTool })).addEdge(require_constants.START, "agent").addConditionalEdges("agent", shouldContinue, {
60
55
  continue: "action",
61
56
  end: require_constants.END
62
- }).addEdge("action", "agent");
63
- return workflow.compile();
57
+ }).addEdge("action", "agent").compile();
64
58
  }
65
59
 
66
60
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"chat_agent_executor.cjs","names":["toolExecutor: ToolExecutor","toolClasses: Array<StructuredToolInterface | RunnableToolLike>","ToolExecutor","FunctionMessage","schema: StateGraphArgs<FunctionCallingExecutorState>[\"channels\"]","StateGraph","RunnableLambda","START","END"],"sources":["../../src/prebuilt/chat_agent_executor.ts"],"sourcesContent":["import { StructuredToolInterface } from \"@langchain/core/tools\";\nimport { convertToOpenAIFunction } from \"@langchain/core/utils/function_calling\";\nimport { AgentAction } from \"@langchain/core/agents\";\nimport { FunctionMessage, BaseMessage } from \"@langchain/core/messages\";\nimport {\n type RunnableConfig,\n RunnableLambda,\n RunnableToolLike,\n} from \"@langchain/core/runnables\";\nimport { ToolExecutor } from \"./tool_executor.js\";\nimport {\n CompiledStateGraph,\n StateGraph,\n StateGraphArgs,\n} from \"../graph/state.js\";\nimport { END, START } from \"../constants.js\";\n\n/** @deprecated Use {@link createReactAgent} instead with tool calling. */\nexport type FunctionCallingExecutorState = { messages: Array<BaseMessage> };\n\n/** @deprecated Use {@link createReactAgent} instead with tool calling. */\nexport function createFunctionCallingExecutor<Model extends object>({\n model,\n tools,\n}: {\n model: Model;\n tools: Array<StructuredToolInterface | RunnableToolLike> | ToolExecutor;\n}): CompiledStateGraph<\n FunctionCallingExecutorState,\n Partial<FunctionCallingExecutorState>,\n typeof START | \"agent\" | \"action\"\n> {\n let toolExecutor: ToolExecutor;\n let toolClasses: Array<StructuredToolInterface | RunnableToolLike>;\n if (!Array.isArray(tools)) {\n toolExecutor = tools;\n toolClasses = tools.tools;\n } else {\n toolExecutor = new ToolExecutor({\n tools,\n });\n toolClasses = tools;\n }\n\n if (!(\"bind\" in model) || typeof model.bind !== \"function\") {\n throw new Error(\"Model must be bindable\");\n }\n const toolsAsOpenAIFunctions = toolClasses.map((tool) =>\n convertToOpenAIFunction(tool)\n );\n const newModel = model.bind({\n functions: toolsAsOpenAIFunctions,\n });\n\n // Define the function that determines whether to continue or not\n const shouldContinue = (state: FunctionCallingExecutorState) => {\n const { messages } = state;\n const lastMessage = messages[messages.length - 1];\n // If there is no function call, then we finish\n if (\n !(\"function_call\" in lastMessage.additional_kwargs) ||\n !lastMessage.additional_kwargs.function_call\n ) {\n return \"end\";\n }\n // Otherwise if there is, we continue\n return \"continue\";\n };\n\n // Define the function that calls the model\n const callModel = async (\n state: FunctionCallingExecutorState,\n config?: RunnableConfig\n ) => {\n const { messages } = state;\n const response = await newModel.invoke(messages, config);\n // We return a list, because this will get added to the existing list\n return {\n messages: [response],\n };\n };\n\n // Define the function to execute tools\n const _getAction = (state: FunctionCallingExecutorState): AgentAction => {\n const { messages } = state;\n // Based on the continue condition\n // we know the last message involves a function call\n const lastMessage = messages[messages.length - 1];\n if (!lastMessage) {\n throw new Error(\"No messages found.\");\n }\n if (!lastMessage.additional_kwargs.function_call) {\n throw new Error(\"No function call found in message.\");\n }\n // We construct an AgentAction from the function_call\n return {\n tool: lastMessage.additional_kwargs.function_call.name,\n toolInput: JSON.stringify(\n lastMessage.additional_kwargs.function_call.arguments\n ),\n log: \"\",\n };\n };\n\n const callTool = async (\n state: FunctionCallingExecutorState,\n config?: RunnableConfig\n ) => {\n const action = _getAction(state);\n // We call the tool_executor and get back a response\n const response = await toolExecutor.invoke(action, config);\n // We use the response to create a FunctionMessage\n const functionMessage = new FunctionMessage({\n content: response,\n name: action.tool,\n });\n // We return a list, because this will get added to the existing list\n return { messages: [functionMessage] };\n };\n\n // We create the AgentState that we will pass around\n // This simply involves a list of messages\n // We want steps to return messages to append to the list\n // So we annotate the messages attribute with operator.add\n const schema: StateGraphArgs<FunctionCallingExecutorState>[\"channels\"] = {\n messages: {\n value: (x: BaseMessage[], y: BaseMessage[]) => x.concat(y),\n default: () => [],\n },\n };\n\n // Define a new graph\n const workflow = new StateGraph<FunctionCallingExecutorState>({\n channels: schema,\n })\n // Define the two nodes we will cycle between\n .addNode(\"agent\", new RunnableLambda({ func: callModel }))\n .addNode(\"action\", new RunnableLambda({ func: callTool }))\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 // Finally, we compile it!\n // This compiles it into a LangChain Runnable,\n // meaning you can use it as you would any other runnable\n return workflow.compile();\n}\n"],"mappings":";;;;;;;;;;AAqBA,SAAgB,8BAAoD,EAClE,OACA,SAQA;CACA,IAAIA;CACJ,IAAIC;AACJ,KAAI,CAAC,MAAM,QAAQ,QAAQ;AACzB,iBAAe;AACf,gBAAc,MAAM;QACf;AACL,iBAAe,IAAIC,mCAAa,EAC9B;AAEF,gBAAc;;AAGhB,KAAI,EAAE,UAAU,UAAU,OAAO,MAAM,SAAS,WAC9C,OAAM,IAAI,MAAM;CAElB,MAAM,yBAAyB,YAAY,KAAK,8EACtB;CAE1B,MAAM,WAAW,MAAM,KAAK,EAC1B,WAAW;CAIb,MAAM,kBAAkB,UAAwC;EAC9D,MAAM,EAAE,aAAa;EACrB,MAAM,cAAc,SAAS,SAAS,SAAS;AAE/C,MACE,EAAE,mBAAmB,YAAY,sBACjC,CAAC,YAAY,kBAAkB,cAE/B,QAAO;AAGT,SAAO;;CAIT,MAAM,YAAY,OAChB,OACA,WACG;EACH,MAAM,EAAE,aAAa;EACrB,MAAM,WAAW,MAAM,SAAS,OAAO,UAAU;AAEjD,SAAO,EACL,UAAU,CAAC;;CAKf,MAAM,cAAc,UAAqD;EACvE,MAAM,EAAE,aAAa;EAGrB,MAAM,cAAc,SAAS,SAAS,SAAS;AAC/C,MAAI,CAAC,YACH,OAAM,IAAI,MAAM;AAElB,MAAI,CAAC,YAAY,kBAAkB,cACjC,OAAM,IAAI,MAAM;AAGlB,SAAO;GACL,MAAM,YAAY,kBAAkB,cAAc;GAClD,WAAW,KAAK,UACd,YAAY,kBAAkB,cAAc;GAE9C,KAAK;;;CAIT,MAAM,WAAW,OACf,OACA,WACG;EACH,MAAM,SAAS,WAAW;EAE1B,MAAM,WAAW,MAAM,aAAa,OAAO,QAAQ;EAEnD,MAAM,kBAAkB,IAAIC,0CAAgB;GAC1C,SAAS;GACT,MAAM,OAAO;;AAGf,SAAO,EAAE,UAAU,CAAC;;CAOtB,MAAMC,SAAmE,EACvE,UAAU;EACR,QAAQ,GAAkB,MAAqB,EAAE,OAAO;EACxD,eAAe;;CAKnB,MAAM,WAAW,IAAIC,yBAAyC,EAC5D,UAAU,UAGT,QAAQ,SAAS,IAAIC,0CAAe,EAAE,MAAM,cAC5C,QAAQ,UAAU,IAAIA,0CAAe,EAAE,MAAM,aAG7C,QAAQC,yBAAO,SAEf,oBAGC,SAEA,gBAOA;EAEE,UAAU;EAEV,KAAKC;IAKR,QAAQ,UAAU;AAKrB,QAAO,SAAS"}
1
+ {"version":3,"file":"chat_agent_executor.cjs","names":["ToolExecutor","FunctionMessage","StateGraph","RunnableLambda","START","END"],"sources":["../../src/prebuilt/chat_agent_executor.ts"],"sourcesContent":["import { StructuredToolInterface } from \"@langchain/core/tools\";\nimport { convertToOpenAIFunction } from \"@langchain/core/utils/function_calling\";\nimport { AgentAction } from \"@langchain/core/agents\";\nimport { FunctionMessage, BaseMessage } from \"@langchain/core/messages\";\nimport {\n type RunnableConfig,\n RunnableLambda,\n RunnableToolLike,\n} from \"@langchain/core/runnables\";\nimport { ToolExecutor } from \"./tool_executor.js\";\nimport {\n CompiledStateGraph,\n StateGraph,\n StateGraphArgs,\n} from \"../graph/state.js\";\nimport { END, START } from \"../constants.js\";\n\n/** @deprecated Use {@link createReactAgent} instead with tool calling. */\nexport type FunctionCallingExecutorState = { messages: Array<BaseMessage> };\n\n/** @deprecated Use {@link createReactAgent} instead with tool calling. */\nexport function createFunctionCallingExecutor<Model extends object>({\n model,\n tools,\n}: {\n model: Model;\n tools: Array<StructuredToolInterface | RunnableToolLike> | ToolExecutor;\n}): CompiledStateGraph<\n FunctionCallingExecutorState,\n Partial<FunctionCallingExecutorState>,\n typeof START | \"agent\" | \"action\"\n> {\n let toolExecutor: ToolExecutor;\n let toolClasses: Array<StructuredToolInterface | RunnableToolLike>;\n if (!Array.isArray(tools)) {\n toolExecutor = tools;\n toolClasses = tools.tools;\n } else {\n toolExecutor = new ToolExecutor({\n tools,\n });\n toolClasses = tools;\n }\n\n if (!(\"bind\" in model) || typeof model.bind !== \"function\") {\n throw new Error(\"Model must be bindable\");\n }\n const toolsAsOpenAIFunctions = toolClasses.map((tool) =>\n convertToOpenAIFunction(tool)\n );\n const newModel = model.bind({\n functions: toolsAsOpenAIFunctions,\n });\n\n // Define the function that determines whether to continue or not\n const shouldContinue = (state: FunctionCallingExecutorState) => {\n const { messages } = state;\n const lastMessage = messages[messages.length - 1];\n // If there is no function call, then we finish\n if (\n !(\"function_call\" in lastMessage.additional_kwargs) ||\n !lastMessage.additional_kwargs.function_call\n ) {\n return \"end\";\n }\n // Otherwise if there is, we continue\n return \"continue\";\n };\n\n // Define the function that calls the model\n const callModel = async (\n state: FunctionCallingExecutorState,\n config?: RunnableConfig\n ) => {\n const { messages } = state;\n const response = await newModel.invoke(messages, config);\n // We return a list, because this will get added to the existing list\n return {\n messages: [response],\n };\n };\n\n // Define the function to execute tools\n const _getAction = (state: FunctionCallingExecutorState): AgentAction => {\n const { messages } = state;\n // Based on the continue condition\n // we know the last message involves a function call\n const lastMessage = messages[messages.length - 1];\n if (!lastMessage) {\n throw new Error(\"No messages found.\");\n }\n if (!lastMessage.additional_kwargs.function_call) {\n throw new Error(\"No function call found in message.\");\n }\n // We construct an AgentAction from the function_call\n return {\n tool: lastMessage.additional_kwargs.function_call.name,\n toolInput: JSON.stringify(\n lastMessage.additional_kwargs.function_call.arguments\n ),\n log: \"\",\n };\n };\n\n const callTool = async (\n state: FunctionCallingExecutorState,\n config?: RunnableConfig\n ) => {\n const action = _getAction(state);\n // We call the tool_executor and get back a response\n const response = await toolExecutor.invoke(action, config);\n // We use the response to create a FunctionMessage\n const functionMessage = new FunctionMessage({\n content: response,\n name: action.tool,\n });\n // We return a list, because this will get added to the existing list\n return { messages: [functionMessage] };\n };\n\n // We create the AgentState that we will pass around\n // This simply involves a list of messages\n // We want steps to return messages to append to the list\n // So we annotate the messages attribute with operator.add\n const schema: StateGraphArgs<FunctionCallingExecutorState>[\"channels\"] = {\n messages: {\n value: (x: BaseMessage[], y: BaseMessage[]) => x.concat(y),\n default: () => [],\n },\n };\n\n // Define a new graph\n const workflow = new StateGraph<FunctionCallingExecutorState>({\n channels: schema,\n })\n // Define the two nodes we will cycle between\n .addNode(\"agent\", new RunnableLambda({ func: callModel }))\n .addNode(\"action\", new RunnableLambda({ func: callTool }))\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 // Finally, we compile it!\n // This compiles it into a LangChain Runnable,\n // meaning you can use it as you would any other runnable\n return workflow.compile();\n}\n"],"mappings":";;;;;;;;;AAqBA,SAAgB,8BAAoD,EAClE,OACA,SAQA;CACA,IAAI;CACJ,IAAI;AACJ,KAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,iBAAe;AACf,gBAAc,MAAM;QACf;AACL,iBAAe,IAAIA,mCAAa,EAC9B,OACD,CAAC;AACF,gBAAc;;AAGhB,KAAI,EAAE,UAAU,UAAU,OA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U,CAAC,CAAC,CAGzD,QAAQC,yBAAO,QAAQ,CAEvB,oBAGC,SAEA,gBAOA;EAEE,UAAU;EAEV,KAAKC;EACN,CACF,CAGA,QAAQ,UAAU,QAAQ,CAKb,SAAS"}
@@ -1 +1 @@
1
- {"version":3,"file":"chat_agent_executor.d.cts","names":["StructuredToolInterface","BaseMessage","RunnableToolLike","ToolExecutor","CompiledStateGraph","START","FunctionCallingExecutorState","Array","createFunctionCallingExecutor","model","tools","Model","Partial"],"sources":["../../src/prebuilt/chat_agent_executor.d.ts"],"sourcesContent":["import { StructuredToolInterface } from \"@langchain/core/tools\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { RunnableToolLike } from \"@langchain/core/runnables\";\nimport { ToolExecutor } from \"./tool_executor.js\";\nimport { CompiledStateGraph } from \"../graph/state.js\";\nimport { START } from \"../constants.js\";\n/** @deprecated Use {@link createReactAgent} instead with tool calling. */\nexport type FunctionCallingExecutorState = {\n messages: Array<BaseMessage>;\n};\n/** @deprecated Use {@link createReactAgent} instead with tool calling. */\nexport declare function createFunctionCallingExecutor<Model extends object>({ model, tools }: {\n model: Model;\n tools: Array<StructuredToolInterface | RunnableToolLike> | ToolExecutor;\n}): CompiledStateGraph<FunctionCallingExecutorState, Partial<FunctionCallingExecutorState>, typeof START | \"agent\" | \"action\">;\n"],"mappings":";;;;;;;;;KAOYM,4BAAAA;EAAAA,QAAAA,EACEC,KADFD,CACQL,WADRK,CAAAA;CAA4B;;AAC1BC,iBAGUC,6BAHVD,CAAAA,cAAAA,MAAAA,CAAAA,CAAAA;EAAAA,KAAAA;EAAAA;CAAAA,EAAAA;SAIHI;EADaH,KAAAA,EAEbD,KAFaC,CAEPR,uBAFoC,GAEVE,gBAFU,CAAA,GAEUC,YAFV;CAAA,CAAA,EAGjDC,kBAHiD,CAG9BE,4BAH8B,EAGAM,OAHA,CAGQN,4BAHR,CAAA,EAAA,OAG8CD,KAH9C,GAAA,OAAA,GAAA,QAAA,CAAA"}
1
+ {"version":3,"file":"chat_agent_executor.d.cts","names":["StructuredToolInterface","BaseMessage","RunnableToolLike","ToolExecutor","CompiledStateGraph","START","FunctionCallingExecutorState","Array","createFunctionCallingExecutor","model","tools","Model","Partial"],"sources":["../../src/prebuilt/chat_agent_executor.d.ts"],"sourcesContent":["import { StructuredToolInterface } from \"@langchain/core/tools\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { RunnableToolLike } from \"@langchain/core/runnables\";\nimport { ToolExecutor } from \"./tool_executor.js\";\nimport { CompiledStateGraph } from \"../graph/state.js\";\nimport { START } from \"../constants.js\";\n/** @deprecated Use {@link createReactAgent} instead with tool calling. */\nexport type FunctionCallingExecutorState = {\n messages: Array<BaseMessage>;\n};\n/** @deprecated Use {@link createReactAgent} instead with tool calling. */\nexport declare function createFunctionCallingExecutor<Model extends object>({ model, tools }: {\n model: Model;\n tools: Array<StructuredToolInterface | RunnableToolLike> | ToolExecutor;\n}): CompiledStateGraph<FunctionCallingExecutorState, Partial<FunctionCallingExecutorState>, typeof START | \"agent\" | \"action\">;\n"],"mappings":";;;;;;;;;KAOYM,4BAAAA;EAAAA,QAAAA,EACEC,KADFD,CACQL,WADRK,CAAAA;CAA4B;;AAC1BC,iBAGUC,6BAHVD,CAAAA,cAAAA,MAAAA,CAAAA,CAAAA;EAAAA,KAAAA;EAAAA;CAAAA,EAAAA;EAAK,KAAA,EAIRI,KAJQ;EAGKH,KAAAA,EAEbD,KAFaC,CAEPR,uBAFoC,GAEVE,gBAFU,CAAA,GAEUC,YAFV;CAAA,CAAA,EAGjDC,kBAHiD,CAG9BE,4BAH8B,EAGAM,OAHA,CAGQN,4BAHR,CAAA,EAAA,OAG8CD,KAH9C,GAAA,OAAA,GAAA,QAAA,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"chat_agent_executor.d.ts","names":["StructuredToolInterface","BaseMessage","RunnableToolLike","ToolExecutor","CompiledStateGraph","START","FunctionCallingExecutorState","Array","createFunctionCallingExecutor","model","tools","Model","Partial"],"sources":["../../src/prebuilt/chat_agent_executor.d.ts"],"sourcesContent":["import { StructuredToolInterface } from \"@langchain/core/tools\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { RunnableToolLike } from \"@langchain/core/runnables\";\nimport { ToolExecutor } from \"./tool_executor.js\";\nimport { CompiledStateGraph } from \"../graph/state.js\";\nimport { START } from \"../constants.js\";\n/** @deprecated Use {@link createReactAgent} instead with tool calling. */\nexport type FunctionCallingExecutorState = {\n messages: Array<BaseMessage>;\n};\n/** @deprecated Use {@link createReactAgent} instead with tool calling. */\nexport declare function createFunctionCallingExecutor<Model extends object>({ model, tools }: {\n model: Model;\n tools: Array<StructuredToolInterface | RunnableToolLike> | ToolExecutor;\n}): CompiledStateGraph<FunctionCallingExecutorState, Partial<FunctionCallingExecutorState>, typeof START | \"agent\" | \"action\">;\n"],"mappings":";;;;;;;;;KAOYM,4BAAAA;EAAAA,QAAAA,EACEC,KADFD,CACQL,WADRK,CAAAA;CAA4B;;AAC1BC,iBAGUC,6BAHVD,CAAAA,cAAAA,MAAAA,CAAAA,CAAAA;EAAAA,KAAAA;EAAAA;CAAAA,EAAAA;SAIHI;EADaH,KAAAA,EAEbD,KAFaC,CAEPR,uBAFoC,GAEVE,gBAFU,CAAA,GAEUC,YAFV;CAAA,CAAA,EAGjDC,kBAHiD,CAG9BE,4BAH8B,EAGAM,OAHA,CAGQN,4BAHR,CAAA,EAAA,OAG8CD,KAH9C,GAAA,OAAA,GAAA,QAAA,CAAA"}
1
+ {"version":3,"file":"chat_agent_executor.d.ts","names":["StructuredToolInterface","BaseMessage","RunnableToolLike","ToolExecutor","CompiledStateGraph","START","FunctionCallingExecutorState","Array","createFunctionCallingExecutor","model","tools","Model","Partial"],"sources":["../../src/prebuilt/chat_agent_executor.d.ts"],"sourcesContent":["import { StructuredToolInterface } from \"@langchain/core/tools\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { RunnableToolLike } from \"@langchain/core/runnables\";\nimport { ToolExecutor } from \"./tool_executor.js\";\nimport { CompiledStateGraph } from \"../graph/state.js\";\nimport { START } from \"../constants.js\";\n/** @deprecated Use {@link createReactAgent} instead with tool calling. */\nexport type FunctionCallingExecutorState = {\n messages: Array<BaseMessage>;\n};\n/** @deprecated Use {@link createReactAgent} instead with tool calling. */\nexport declare function createFunctionCallingExecutor<Model extends object>({ model, tools }: {\n model: Model;\n tools: Array<StructuredToolInterface | RunnableToolLike> | ToolExecutor;\n}): CompiledStateGraph<FunctionCallingExecutorState, Partial<FunctionCallingExecutorState>, typeof START | \"agent\" | \"action\">;\n"],"mappings":";;;;;;;;;KAOYM,4BAAAA;EAAAA,QAAAA,EACEC,KADFD,CACQL,WADRK,CAAAA;CAA4B;;AAC1BC,iBAGUC,6BAHVD,CAAAA,cAAAA,MAAAA,CAAAA,CAAAA;EAAAA,KAAAA;EAAAA;CAAAA,EAAAA;EAAK,KAAA,EAIRI,KAJQ;EAGKH,KAAAA,EAEbD,KAFaC,CAEPR,uBAFoC,GAEVE,gBAFU,CAAA,GAEUC,YAFV;CAAA,CAAA,EAGjDC,kBAHiD,CAG9BE,4BAH8B,EAGAM,OAHA,CAGQN,4BAHR,CAAA,EAAA,OAG8CD,KAH9C,GAAA,OAAA,GAAA,QAAA,CAAA"}
@@ -28,8 +28,7 @@ function createFunctionCallingExecutor({ model, tools }) {
28
28
  };
29
29
  const callModel = async (state, config) => {
30
30
  const { messages } = state;
31
- const response = await newModel.invoke(messages, config);
32
- return { messages: [response] };
31
+ return { messages: [await newModel.invoke(messages, config)] };
33
32
  };
34
33
  const _getAction = (state) => {
35
34
  const { messages } = state;
@@ -44,22 +43,18 @@ function createFunctionCallingExecutor({ model, tools }) {
44
43
  };
45
44
  const callTool = async (state, config) => {
46
45
  const action = _getAction(state);
47
- const response = await toolExecutor.invoke(action, config);
48
- const functionMessage = new FunctionMessage({
49
- content: response,
46
+ return { messages: [new FunctionMessage({
47
+ content: await toolExecutor.invoke(action, config),
50
48
  name: action.tool
51
- });
52
- return { messages: [functionMessage] };
49
+ })] };
53
50
  };
54
- const schema = { messages: {
51
+ return new StateGraph({ channels: { messages: {
55
52
  value: (x, y) => x.concat(y),
56
53
  default: () => []
57
- } };
58
- const workflow = new StateGraph({ channels: schema }).addNode("agent", new RunnableLambda({ func: callModel })).addNode("action", new RunnableLambda({ func: callTool })).addEdge(START, "agent").addConditionalEdges("agent", shouldContinue, {
54
+ } } }).addNode("agent", new RunnableLambda({ func: callModel })).addNode("action", new RunnableLambda({ func: callTool })).addEdge(START, "agent").addConditionalEdges("agent", shouldContinue, {
59
55
  continue: "action",
60
56
  end: END
61
- }).addEdge("action", "agent");
62
- return workflow.compile();
57
+ }).addEdge("action", "agent").compile();
63
58
  }
64
59
 
65
60
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"chat_agent_executor.js","names":["toolExecutor: ToolExecutor","toolClasses: Array<StructuredToolInterface | RunnableToolLike>","schema: StateGraphArgs<FunctionCallingExecutorState>[\"channels\"]"],"sources":["../../src/prebuilt/chat_agent_executor.ts"],"sourcesContent":["import { StructuredToolInterface } from \"@langchain/core/tools\";\nimport { convertToOpenAIFunction } from \"@langchain/core/utils/function_calling\";\nimport { AgentAction } from \"@langchain/core/agents\";\nimport { FunctionMessage, BaseMessage } from \"@langchain/core/messages\";\nimport {\n type RunnableConfig,\n RunnableLambda,\n RunnableToolLike,\n} from \"@langchain/core/runnables\";\nimport { ToolExecutor } from \"./tool_executor.js\";\nimport {\n CompiledStateGraph,\n StateGraph,\n StateGraphArgs,\n} from \"../graph/state.js\";\nimport { END, START } from \"../constants.js\";\n\n/** @deprecated Use {@link createReactAgent} instead with tool calling. */\nexport type FunctionCallingExecutorState = { messages: Array<BaseMessage> };\n\n/** @deprecated Use {@link createReactAgent} instead with tool calling. */\nexport function createFunctionCallingExecutor<Model extends object>({\n model,\n tools,\n}: {\n model: Model;\n tools: Array<StructuredToolInterface | RunnableToolLike> | ToolExecutor;\n}): CompiledStateGraph<\n FunctionCallingExecutorState,\n Partial<FunctionCallingExecutorState>,\n typeof START | \"agent\" | \"action\"\n> {\n let toolExecutor: ToolExecutor;\n let toolClasses: Array<StructuredToolInterface | RunnableToolLike>;\n if (!Array.isArray(tools)) {\n toolExecutor = tools;\n toolClasses = tools.tools;\n } else {\n toolExecutor = new ToolExecutor({\n tools,\n });\n toolClasses = tools;\n }\n\n if (!(\"bind\" in model) || typeof model.bind !== \"function\") {\n throw new Error(\"Model must be bindable\");\n }\n const toolsAsOpenAIFunctions = toolClasses.map((tool) =>\n convertToOpenAIFunction(tool)\n );\n const newModel = model.bind({\n functions: toolsAsOpenAIFunctions,\n });\n\n // Define the function that determines whether to continue or not\n const shouldContinue = (state: FunctionCallingExecutorState) => {\n const { messages } = state;\n const lastMessage = messages[messages.length - 1];\n // If there is no function call, then we finish\n if (\n !(\"function_call\" in lastMessage.additional_kwargs) ||\n !lastMessage.additional_kwargs.function_call\n ) {\n return \"end\";\n }\n // Otherwise if there is, we continue\n return \"continue\";\n };\n\n // Define the function that calls the model\n const callModel = async (\n state: FunctionCallingExecutorState,\n config?: RunnableConfig\n ) => {\n const { messages } = state;\n const response = await newModel.invoke(messages, config);\n // We return a list, because this will get added to the existing list\n return {\n messages: [response],\n };\n };\n\n // Define the function to execute tools\n const _getAction = (state: FunctionCallingExecutorState): AgentAction => {\n const { messages } = state;\n // Based on the continue condition\n // we know the last message involves a function call\n const lastMessage = messages[messages.length - 1];\n if (!lastMessage) {\n throw new Error(\"No messages found.\");\n }\n if (!lastMessage.additional_kwargs.function_call) {\n throw new Error(\"No function call found in message.\");\n }\n // We construct an AgentAction from the function_call\n return {\n tool: lastMessage.additional_kwargs.function_call.name,\n toolInput: JSON.stringify(\n lastMessage.additional_kwargs.function_call.arguments\n ),\n log: \"\",\n };\n };\n\n const callTool = async (\n state: FunctionCallingExecutorState,\n config?: RunnableConfig\n ) => {\n const action = _getAction(state);\n // We call the tool_executor and get back a response\n const response = await toolExecutor.invoke(action, config);\n // We use the response to create a FunctionMessage\n const functionMessage = new FunctionMessage({\n content: response,\n name: action.tool,\n });\n // We return a list, because this will get added to the existing list\n return { messages: [functionMessage] };\n };\n\n // We create the AgentState that we will pass around\n // This simply involves a list of messages\n // We want steps to return messages to append to the list\n // So we annotate the messages attribute with operator.add\n const schema: StateGraphArgs<FunctionCallingExecutorState>[\"channels\"] = {\n messages: {\n value: (x: BaseMessage[], y: BaseMessage[]) => x.concat(y),\n default: () => [],\n },\n };\n\n // Define a new graph\n const workflow = new StateGraph<FunctionCallingExecutorState>({\n channels: schema,\n })\n // Define the two nodes we will cycle between\n .addNode(\"agent\", new RunnableLambda({ func: callModel }))\n .addNode(\"action\", new RunnableLambda({ func: callTool }))\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 // Finally, we compile it!\n // This compiles it into a LangChain Runnable,\n // meaning you can use it as you would any other runnable\n return workflow.compile();\n}\n"],"mappings":";;;;;;;;;AAqBA,SAAgB,8BAAoD,EAClE,OACA,SAQA;CACA,IAAIA;CACJ,IAAIC;AACJ,KAAI,CAAC,MAAM,QAAQ,QAAQ;AACzB,iBAAe;AACf,gBAAc,MAAM;QACf;AACL,iBAAe,IAAI,aAAa,EAC9B;AAEF,gBAAc;;AAGhB,KAAI,EAAE,UAAU,UAAU,OAAO,MAAM,SAAS,WAC9C,OAAM,IAAI,MAAM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":"chat_agent_executor.js","names":[],"sources":["../../src/prebuilt/chat_agent_executor.ts"],"sourcesContent":["import { StructuredToolInterface } from \"@langchain/core/tools\";\nimport { convertToOpenAIFunction } from \"@langchain/core/utils/function_calling\";\nimport { AgentAction } from \"@langchain/core/agents\";\nimport { FunctionMessage, BaseMessage } from \"@langchain/core/messages\";\nimport {\n type RunnableConfig,\n RunnableLambda,\n RunnableToolLike,\n} from \"@langchain/core/runnables\";\nimport { ToolExecutor } from \"./tool_executor.js\";\nimport {\n CompiledStateGraph,\n StateGraph,\n StateGraphArgs,\n} from \"../graph/state.js\";\nimport { END, START } from \"../constants.js\";\n\n/** @deprecated Use {@link createReactAgent} instead with tool calling. */\nexport type FunctionCallingExecutorState = { messages: Array<BaseMessage> };\n\n/** @deprecated Use {@link createReactAgent} instead with tool calling. */\nexport function createFunctionCallingExecutor<Model extends object>({\n model,\n tools,\n}: {\n model: Model;\n tools: Array<StructuredToolInterface | RunnableToolLike> | ToolExecutor;\n}): CompiledStateGraph<\n FunctionCallingExecutorState,\n Partial<FunctionCallingExecutorState>,\n typeof START | \"agent\" | \"action\"\n> {\n let toolExecutor: ToolExecutor;\n let toolClasses: Array<StructuredToolInterface | RunnableToolLike>;\n if (!Array.isArray(tools)) {\n toolExecutor = tools;\n toolClasses = tools.tools;\n } else {\n toolExecutor = new ToolExecutor({\n tools,\n });\n toolClasses = tools;\n }\n\n if (!(\"bind\" in model) || typeof model.bind !== \"function\") {\n throw new Error(\"Model must be bindable\");\n }\n const toolsAsOpenAIFunctions = toolClasses.map((tool) =>\n convertToOpenAIFunction(tool)\n );\n const newModel = model.bind({\n functions: toolsAsOpenAIFunctions,\n });\n\n // Define the function that determines whether to continue or not\n const shouldContinue = (state: FunctionCallingExecutorState) => {\n const { messages } = state;\n const lastMessage = messages[messages.length - 1];\n // If there is no function call, then we finish\n if (\n !(\"function_call\" in lastMessage.additional_kwargs) ||\n !lastMessage.additional_kwargs.function_call\n ) {\n return \"end\";\n }\n // Otherwise if there is, we continue\n return \"continue\";\n };\n\n // Define the function that calls the model\n const callModel = async (\n state: FunctionCallingExecutorState,\n config?: RunnableConfig\n ) => {\n const { messages } = state;\n const response = await newModel.invoke(messages, config);\n // We return a list, because this will get added to the existing list\n return {\n messages: [response],\n };\n };\n\n // Define the function to execute tools\n const _getAction = (state: FunctionCallingExecutorState): AgentAction => {\n const { messages } = state;\n // Based on the continue condition\n // we know the last message involves a function call\n const lastMessage = messages[messages.length - 1];\n if (!lastMessage) {\n throw new Error(\"No messages found.\");\n }\n if (!lastMessage.additional_kwargs.function_call) {\n throw new Error(\"No function call found in message.\");\n }\n // We construct an AgentAction from the function_call\n return {\n tool: lastMessage.additional_kwargs.function_call.name,\n toolInput: JSON.stringify(\n lastMessage.additional_kwargs.function_call.arguments\n ),\n log: \"\",\n };\n };\n\n const callTool = async (\n state: FunctionCallingExecutorState,\n config?: RunnableConfig\n ) => {\n const action = _getAction(state);\n // We call the tool_executor and get back a response\n const response = await toolExecutor.invoke(action, config);\n // We use the response to create a FunctionMessage\n const functionMessage = new FunctionMessage({\n content: response,\n name: action.tool,\n });\n // We return a list, because this will get added to the existing list\n return { messages: [functionMessage] };\n };\n\n // We create the AgentState that we will pass around\n // This simply involves a list of messages\n // We want steps to return messages to append to the list\n // So we annotate the messages attribute with operator.add\n const schema: StateGraphArgs<FunctionCallingExecutorState>[\"channels\"] = {\n messages: {\n value: (x: BaseMessage[], y: BaseMessage[]) => x.concat(y),\n default: () => [],\n },\n };\n\n // Define a new graph\n const workflow = new StateGraph<FunctionCallingExecutorState>({\n channels: schema,\n })\n // Define the two nodes we will cycle between\n .addNode(\"agent\", new RunnableLambda({ func: callModel }))\n .addNode(\"action\", new RunnableLambda({ func: callTool }))\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 // Finally, we compile it!\n // This compiles it into a LangChain Runnable,\n // meaning you can use it as you would any other runnable\n return workflow.compile();\n}\n"],"mappings":";;;;;;;;;AAqBA,SAAgB,8BAAoD,EAClE,OACA,SAQA;CACA,IAAI;CACJ,IAAI;AACJ,KAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,iBAAe;AACf,gBAAc,MAAM;QACf;AACL,iBAAe,IAAI,aAAa,EAC9B,OACD,CAAC;AACF,gBAAc;;AAGhB,KAAI,EAAE,UAAU,UAAU,OAAO,MAAM,SAAS,WAC9C,OAAM,IAAI,MAAM,yBAAyB;CAE3C,MAAM,yBAAyB,YAAY,KAAK,SAC9C,wBAAwB,KAAK,CAC9B;CACD,MAAM,WAAW,MAAM,KAAK,EAC1B,WAAW,wBACZ,CAAC;CAGF,MAAM,kBAAkB,UAAwC;EAC9D,MAAM,EAAE,aAAa;EACrB,MAAM,cAAc,SAAS,SAAS,SAAS;AAE/C,MACE,EAAE,mBAAmB,YAAY,sBACjC,CAAC,YAAY,kBAAkB,cAE/B,QAAO;AAGT,SAAO;;CAIT,MAAM,YAAY,OAChB,OACA,WACG;EACH,MAAM,EAAE,aAAa;AAGrB,SAAO,EACL,UAAU,CAHK,MAAM,SAAS,OAAO,UAAU,OAAO,CAGlC,EACrB;;CAIH,MAAM,cAAc,UAAqD;EACvE,MAAM,EAAE,aAAa;EAGrB,MAAM,cAAc,SAAS,SAAS,SAAS;AAC/C,MAAI,CAAC,YACH,OAAM,IAAI,MAAM,qBAAqB;AAEvC,MAAI,CAAC,YAAY,kBAAkB,cACjC,OAAM,IAAI,MAAM,qCAAqC;AAGvD,SAAO;GACL,MAAM,YAAY,kBAAkB,cAAc;GAClD,WAAW,KAAK,UACd,YAAY,kBAAkB,cAAc,UAC7C;GACD,KAAK;GACN;;CAGH,MAAM,WAAW,OACf,OACA,WACG;EACH,MAAM,SAAS,WAAW,MAAM;AAShC,SAAO,EAAE,UAAU,CALK,IAAI,gBAAgB;GAC1C,SAHe,MAAM,aAAa,OAAO,QAAQ,OAAO;GAIxD,MAAM,OAAO;GACd,CAAC,CAEkC,EAAE;;AAmDxC,QApCiB,IAAI,WAAyC,EAC5D,UATuE,EACvE,UAAU;EACR,QAAQ,GAAkB,MAAqB,EAAE,OAAO,EAAE;EAC1D,eAAe,EAAE;EAClB,EACF,EAKA,CAAC,CAEC,QAAQ,SAAS,IAAI,eAAe,EAAE,MAAM,WAAW,CAAC,CAAC,CACzD,QAAQ,UAAU,IAAI,eAAe,EAAE,MAAM,UAAU,CAAC,CAAC,CAGzD,QAAQ,OAAO,QAAQ,CAEvB,oBAGC,SAEA,gBAOA;EAEE,UAAU;EAEV,KAAK;EACN,CACF,CAGA,QAAQ,UAAU,QAAQ,CAKb,SAAS"}
@@ -23,7 +23,6 @@ interface HumanInterruptConfig {
23
23
  */
24
24
  interface ActionRequest {
25
25
  action: string;
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
26
  args: Record<string, any>;
28
27
  }
29
28
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"interrupt.d.cts","names":["HumanInterruptConfig","ActionRequest","Record","HumanInterrupt","HumanResponse"],"sources":["../../src/prebuilt/interrupt.d.ts"],"sourcesContent":["/**\n * Configuration interface that defines what actions are allowed for a human interrupt.\n * This controls the available interaction options when the graph is paused for human input.\n *\n * @property {boolean} allow_ignore - Whether the human can choose to ignore/skip the current step\n * @property {boolean} allow_respond - Whether the human can provide a text response/feedback\n * @property {boolean} allow_edit - Whether the human can edit the provided content/state\n * @property {boolean} allow_accept - Whether the human can accept/approve the current state\n */\nexport interface HumanInterruptConfig {\n allow_ignore: boolean;\n allow_respond: boolean;\n allow_edit: boolean;\n allow_accept: boolean;\n}\n/**\n * Represents a request for human action within the graph execution.\n * Contains the action type and any associated arguments needed for the action.\n *\n * @property {string} action - The type or name of action being requested (e.g., \"Approve XYZ action\")\n * @property {Record<string, any>} args - Key-value pairs of arguments needed for the action\n */\nexport interface ActionRequest {\n action: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n args: Record<string, any>;\n}\n/**\n * Represents an interrupt triggered by the graph that requires human intervention.\n * This is passed to the `interrupt` function when execution is paused for human input.\n *\n * @property {ActionRequest} action_request - The specific action being requested from the human\n * @property {HumanInterruptConfig} config - Configuration defining what actions are allowed\n * @property {string} [description] - Optional detailed description of what input is needed\n */\nexport interface HumanInterrupt {\n action_request: ActionRequest;\n config: HumanInterruptConfig;\n description?: string;\n}\n/**\n * The response provided by a human to an interrupt, which is returned when graph execution resumes.\n *\n * @property {(\"accept\"|\"ignore\"|\"response\"|\"edit\")} type - The type of response:\n * - \"accept\": Approves the current state without changes\n * - \"ignore\": Skips/ignores the current step\n * - \"response\": Provides text feedback or instructions\n * - \"edit\": Modifies the current state/content\n * @property {null|string|ActionRequest} args - The response payload:\n * - null: For ignore/accept actions\n * - string: For text responses\n * - ActionRequest: For edit actions with updated content\n */\nexport type HumanResponse = {\n type: \"accept\" | \"ignore\" | \"response\" | \"edit\";\n args: null | string | ActionRequest;\n};\n"],"mappings":";;AASA;AAaA;AAaA;;;;;AAkBA;UA5CiBA,oBAAAA;;;;;;;;;;;;;UAaAC,aAAAA;;;QAGPC;;;;;;;;;;UAUOC,cAAAA;kBACGF;UACRD;;;;;;;;;;;;;;;;KAgBAI,aAAAA;;wBAEcH"}
1
+ {"version":3,"file":"interrupt.d.cts","names":["HumanInterruptConfig","ActionRequest","Record","HumanInterrupt","HumanResponse"],"sources":["../../src/prebuilt/interrupt.d.ts"],"sourcesContent":["/**\n * Configuration interface that defines what actions are allowed for a human interrupt.\n * This controls the available interaction options when the graph is paused for human input.\n *\n * @property {boolean} allow_ignore - Whether the human can choose to ignore/skip the current step\n * @property {boolean} allow_respond - Whether the human can provide a text response/feedback\n * @property {boolean} allow_edit - Whether the human can edit the provided content/state\n * @property {boolean} allow_accept - Whether the human can accept/approve the current state\n */\nexport interface HumanInterruptConfig {\n allow_ignore: boolean;\n allow_respond: boolean;\n allow_edit: boolean;\n allow_accept: boolean;\n}\n/**\n * Represents a request for human action within the graph execution.\n * Contains the action type and any associated arguments needed for the action.\n *\n * @property {string} action - The type or name of action being requested (e.g., \"Approve XYZ action\")\n * @property {Record<string, any>} args - Key-value pairs of arguments needed for the action\n */\nexport interface ActionRequest {\n action: string;\n args: Record<string, any>;\n}\n/**\n * Represents an interrupt triggered by the graph that requires human intervention.\n * This is passed to the `interrupt` function when execution is paused for human input.\n *\n * @property {ActionRequest} action_request - The specific action being requested from the human\n * @property {HumanInterruptConfig} config - Configuration defining what actions are allowed\n * @property {string} [description] - Optional detailed description of what input is needed\n */\nexport interface HumanInterrupt {\n action_request: ActionRequest;\n config: HumanInterruptConfig;\n description?: string;\n}\n/**\n * The response provided by a human to an interrupt, which is returned when graph execution resumes.\n *\n * @property {(\"accept\"|\"ignore\"|\"response\"|\"edit\")} type - The type of response:\n * - \"accept\": Approves the current state without changes\n * - \"ignore\": Skips/ignores the current step\n * - \"response\": Provides text feedback or instructions\n * - \"edit\": Modifies the current state/content\n * @property {null|string|ActionRequest} args - The response payload:\n * - null: For ignore/accept actions\n * - string: For text responses\n * - ActionRequest: For edit actions with updated content\n */\nexport type HumanResponse = {\n type: \"accept\" | \"ignore\" | \"response\" | \"edit\";\n args: null | string | ActionRequest;\n};\n"],"mappings":";;AASA;AAaA;AAYA;;;;;AAkBA;UA3CiBA,oBAAAA;;;;;;;;;;;;;UAaAC,aAAAA;;QAEPC;;;;;;;;;;UAUOC,cAAAA;kBACGF;UACRD;;;;;;;;;;;;;;;;KAgBAI,aAAAA;;wBAEcH"}
@@ -23,7 +23,6 @@ interface HumanInterruptConfig {
23
23
  */
24
24
  interface ActionRequest {
25
25
  action: string;
26
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
26
  args: Record<string, any>;
28
27
  }
29
28
  /**