@langchain/langgraph 1.0.12 → 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.
- package/dist/channels/any_value.cjs +46 -0
- package/dist/channels/any_value.cjs.map +1 -0
- package/dist/channels/any_value.d.cts +23 -0
- package/dist/channels/any_value.d.cts.map +1 -0
- package/dist/channels/any_value.d.ts +23 -0
- package/dist/channels/any_value.d.ts.map +1 -0
- package/dist/channels/any_value.js +46 -0
- package/dist/channels/any_value.js.map +1 -0
- package/dist/channels/base.cjs +101 -0
- package/dist/channels/base.cjs.map +1 -0
- package/dist/channels/base.d.cts +79 -0
- package/dist/channels/base.d.cts.map +1 -0
- package/dist/channels/base.d.ts +79 -0
- package/dist/channels/base.d.ts.map +1 -0
- package/dist/channels/base.js +97 -0
- package/dist/channels/base.js.map +1 -0
- package/dist/channels/binop.cjs +49 -0
- package/dist/channels/binop.cjs.map +1 -0
- package/dist/channels/binop.d.cts +22 -0
- package/dist/channels/binop.d.cts.map +1 -0
- package/dist/channels/binop.d.ts +22 -0
- package/dist/channels/binop.d.ts.map +1 -0
- package/dist/channels/binop.js +49 -0
- package/dist/channels/binop.js.map +1 -0
- package/dist/channels/dynamic_barrier_value.cjs +75 -0
- package/dist/channels/dynamic_barrier_value.cjs.map +1 -0
- package/dist/channels/dynamic_barrier_value.d.cts +40 -0
- package/dist/channels/dynamic_barrier_value.d.cts.map +1 -0
- package/dist/channels/dynamic_barrier_value.d.ts +40 -0
- package/dist/channels/dynamic_barrier_value.d.ts.map +1 -0
- package/dist/channels/dynamic_barrier_value.js +75 -0
- package/dist/channels/dynamic_barrier_value.js.map +1 -0
- package/dist/channels/ephemeral_value.cjs +46 -0
- package/dist/channels/ephemeral_value.cjs.map +1 -0
- package/dist/channels/ephemeral_value.d.cts +21 -0
- package/dist/channels/ephemeral_value.d.cts.map +1 -0
- package/dist/channels/ephemeral_value.d.ts +21 -0
- package/dist/channels/ephemeral_value.d.ts.map +1 -0
- package/dist/channels/ephemeral_value.js +46 -0
- package/dist/channels/ephemeral_value.js.map +1 -0
- package/dist/channels/index.cjs +21 -0
- package/dist/channels/index.d.cts +9 -0
- package/dist/channels/index.d.ts +9 -0
- package/dist/channels/index.js +10 -0
- package/dist/channels/last_value.cjs +98 -0
- package/dist/channels/last_value.cjs.map +1 -0
- package/dist/channels/last_value.d.cts +42 -0
- package/dist/channels/last_value.d.cts.map +1 -0
- package/dist/channels/last_value.d.ts +42 -0
- package/dist/channels/last_value.d.ts.map +1 -0
- package/dist/channels/last_value.js +97 -0
- package/dist/channels/last_value.js.map +1 -0
- package/dist/channels/named_barrier_value.cjs +116 -0
- package/dist/channels/named_barrier_value.cjs.map +1 -0
- package/dist/channels/named_barrier_value.d.cts +44 -0
- package/dist/channels/named_barrier_value.d.cts.map +1 -0
- package/dist/channels/named_barrier_value.d.ts +44 -0
- package/dist/channels/named_barrier_value.d.ts.map +1 -0
- package/dist/channels/named_barrier_value.js +114 -0
- package/dist/channels/named_barrier_value.js.map +1 -0
- package/dist/channels/topic.cjs +65 -0
- package/dist/channels/topic.cjs.map +1 -0
- package/dist/channels/topic.d.cts +32 -0
- package/dist/channels/topic.d.cts.map +1 -0
- package/dist/channels/topic.d.ts +32 -0
- package/dist/channels/topic.d.ts.map +1 -0
- package/dist/channels/topic.js +65 -0
- package/dist/channels/topic.js.map +1 -0
- package/dist/constants.cjs +406 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +281 -0
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.ts +281 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +362 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors.cjs +163 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +77 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.ts +77 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +146 -0
- package/dist/errors.js.map +1 -0
- package/dist/func/index.cjs +299 -0
- package/dist/func/index.cjs.map +1 -0
- package/dist/func/index.d.cts +288 -0
- package/dist/func/index.d.cts.map +1 -0
- package/dist/func/index.d.ts +288 -0
- package/dist/func/index.d.ts.map +1 -0
- package/dist/func/index.js +297 -0
- package/dist/func/index.js.map +1 -0
- package/dist/func/types.d.cts +62 -0
- package/dist/func/types.d.cts.map +1 -0
- package/dist/func/types.d.ts +62 -0
- package/dist/func/types.d.ts.map +1 -0
- package/dist/graph/annotation.cjs +101 -0
- package/dist/graph/annotation.cjs.map +1 -0
- package/dist/graph/annotation.d.cts +116 -0
- package/dist/graph/annotation.d.cts.map +1 -0
- package/dist/graph/annotation.d.ts +116 -0
- package/dist/graph/annotation.d.ts.map +1 -0
- package/dist/graph/annotation.js +99 -0
- package/dist/graph/annotation.js.map +1 -0
- package/dist/graph/graph.cjs +420 -0
- package/dist/graph/graph.cjs.map +1 -0
- package/dist/graph/graph.d.cts +108 -0
- package/dist/graph/graph.d.cts.map +1 -0
- package/dist/graph/graph.d.ts +108 -0
- package/dist/graph/graph.d.ts.map +1 -0
- package/dist/graph/graph.js +418 -0
- package/dist/graph/graph.js.map +1 -0
- package/dist/graph/index.cjs +5 -0
- package/dist/graph/index.js +7 -0
- package/dist/graph/message.cjs +97 -0
- package/dist/graph/message.cjs.map +1 -0
- package/dist/graph/message.d.cts +40 -0
- package/dist/graph/message.d.cts.map +1 -0
- package/dist/graph/message.d.ts +40 -0
- package/dist/graph/message.d.ts.map +1 -0
- package/dist/graph/message.js +94 -0
- package/dist/graph/message.js.map +1 -0
- package/dist/graph/messages_annotation.cjs +109 -0
- package/dist/graph/messages_annotation.cjs.map +1 -0
- package/dist/graph/messages_annotation.d.cts +112 -0
- package/dist/graph/messages_annotation.d.cts.map +1 -0
- package/dist/graph/messages_annotation.d.ts +112 -0
- package/dist/graph/messages_annotation.d.ts.map +1 -0
- package/dist/graph/messages_annotation.js +107 -0
- package/dist/graph/messages_annotation.js.map +1 -0
- package/dist/graph/state.cjs +494 -0
- package/dist/graph/state.cjs.map +1 -0
- package/dist/graph/state.d.cts +229 -0
- package/dist/graph/state.d.cts.map +1 -0
- package/dist/graph/state.d.ts +229 -0
- package/dist/graph/state.d.ts.map +1 -0
- package/dist/graph/state.js +493 -0
- package/dist/graph/state.js.map +1 -0
- package/dist/graph/zod/index.cjs +10 -0
- package/dist/graph/zod/index.d.cts +3 -0
- package/dist/graph/zod/index.d.ts +3 -0
- package/dist/graph/zod/index.js +5 -0
- package/dist/graph/zod/meta.cjs +144 -0
- package/dist/graph/zod/meta.cjs.map +1 -0
- package/dist/graph/zod/meta.d.cts +115 -0
- package/dist/graph/zod/meta.d.cts.map +1 -0
- package/dist/graph/zod/meta.d.ts +115 -0
- package/dist/graph/zod/meta.d.ts.map +1 -0
- package/dist/graph/zod/meta.js +141 -0
- package/dist/graph/zod/meta.js.map +1 -0
- package/dist/graph/zod/plugin.cjs +39 -0
- package/dist/graph/zod/plugin.cjs.map +1 -0
- package/dist/graph/zod/plugin.js +40 -0
- package/dist/graph/zod/plugin.js.map +1 -0
- package/dist/graph/zod/schema.cjs +98 -0
- package/dist/graph/zod/schema.cjs.map +1 -0
- package/dist/graph/zod/schema.d.cts +38 -0
- package/dist/graph/zod/schema.d.cts.map +1 -0
- package/dist/graph/zod/schema.d.ts +38 -0
- package/dist/graph/zod/schema.d.ts.map +1 -0
- package/dist/graph/zod/schema.js +94 -0
- package/dist/graph/zod/schema.js.map +1 -0
- package/dist/graph/zod/zod-registry.cjs +42 -0
- package/dist/graph/zod/zod-registry.cjs.map +1 -0
- package/dist/graph/zod/zod-registry.d.cts +49 -0
- package/dist/graph/zod/zod-registry.d.cts.map +1 -0
- package/dist/graph/zod/zod-registry.d.ts +49 -0
- package/dist/graph/zod/zod-registry.d.ts.map +1 -0
- package/dist/graph/zod/zod-registry.js +41 -0
- package/dist/graph/zod/zod-registry.js.map +1 -0
- package/dist/hash.cjs +265 -0
- package/dist/hash.cjs.map +1 -0
- package/dist/hash.js +263 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.cjs +111 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +26 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/interrupt.cjs +79 -0
- package/dist/interrupt.cjs.map +1 -0
- package/dist/interrupt.d.cts +55 -0
- package/dist/interrupt.d.cts.map +1 -0
- package/dist/interrupt.d.ts +55 -0
- package/dist/interrupt.d.ts.map +1 -0
- package/dist/interrupt.js +79 -0
- package/dist/interrupt.js.map +1 -0
- package/dist/prebuilt/agentName.cjs +148 -0
- package/dist/prebuilt/agentName.cjs.map +1 -0
- package/dist/prebuilt/agentName.d.cts +42 -0
- package/dist/prebuilt/agentName.d.cts.map +1 -0
- package/dist/prebuilt/agentName.d.ts +42 -0
- package/dist/prebuilt/agentName.d.ts.map +1 -0
- package/dist/prebuilt/agentName.js +148 -0
- package/dist/prebuilt/agentName.js.map +1 -0
- package/dist/prebuilt/agent_executor.cjs +41 -0
- package/dist/prebuilt/agent_executor.cjs.map +1 -0
- package/dist/prebuilt/agent_executor.d.cts +58 -0
- package/dist/prebuilt/agent_executor.d.cts.map +1 -0
- package/dist/prebuilt/agent_executor.d.ts +58 -0
- package/dist/prebuilt/agent_executor.d.ts.map +1 -0
- package/dist/prebuilt/agent_executor.js +41 -0
- package/dist/prebuilt/agent_executor.js.map +1 -0
- package/dist/prebuilt/chat_agent_executor.cjs +62 -0
- package/dist/prebuilt/chat_agent_executor.cjs.map +1 -0
- package/dist/prebuilt/chat_agent_executor.d.cts +23 -0
- package/dist/prebuilt/chat_agent_executor.d.cts.map +1 -0
- package/dist/prebuilt/chat_agent_executor.d.ts +23 -0
- package/dist/prebuilt/chat_agent_executor.d.ts.map +1 -0
- package/dist/prebuilt/chat_agent_executor.js +62 -0
- package/dist/prebuilt/chat_agent_executor.js.map +1 -0
- package/dist/prebuilt/index.cjs +15 -0
- package/dist/prebuilt/index.d.cts +8 -0
- package/dist/prebuilt/index.d.ts +8 -0
- package/dist/prebuilt/index.js +8 -0
- package/dist/prebuilt/interrupt.d.cts +60 -0
- package/dist/prebuilt/interrupt.d.cts.map +1 -0
- package/dist/prebuilt/interrupt.d.ts +60 -0
- package/dist/prebuilt/interrupt.d.ts.map +1 -0
- package/dist/prebuilt/react_agent_executor.cjs +339 -0
- package/dist/prebuilt/react_agent_executor.cjs.map +1 -0
- package/dist/prebuilt/react_agent_executor.d.cts +211 -0
- package/dist/prebuilt/react_agent_executor.d.cts.map +1 -0
- package/dist/prebuilt/react_agent_executor.d.ts +211 -0
- package/dist/prebuilt/react_agent_executor.d.ts.map +1 -0
- package/dist/prebuilt/react_agent_executor.js +338 -0
- package/dist/prebuilt/react_agent_executor.js.map +1 -0
- package/dist/prebuilt/tool_executor.cjs +43 -0
- package/dist/prebuilt/tool_executor.cjs.map +1 -0
- package/dist/prebuilt/tool_executor.d.cts +40 -0
- package/dist/prebuilt/tool_executor.d.cts.map +1 -0
- package/dist/prebuilt/tool_executor.d.ts +40 -0
- package/dist/prebuilt/tool_executor.d.ts.map +1 -0
- package/dist/prebuilt/tool_executor.js +43 -0
- package/dist/prebuilt/tool_executor.js.map +1 -0
- package/dist/prebuilt/tool_node.cjs +247 -0
- package/dist/prebuilt/tool_node.cjs.map +1 -0
- package/dist/prebuilt/tool_node.d.cts +180 -0
- package/dist/prebuilt/tool_node.d.cts.map +1 -0
- package/dist/prebuilt/tool_node.d.ts +180 -0
- package/dist/prebuilt/tool_node.d.ts.map +1 -0
- package/dist/prebuilt/tool_node.js +246 -0
- package/dist/prebuilt/tool_node.js.map +1 -0
- package/dist/pregel/algo.cjs +565 -0
- package/dist/pregel/algo.cjs.map +1 -0
- package/dist/pregel/algo.d.cts +13 -0
- package/dist/pregel/algo.d.cts.map +1 -0
- package/dist/pregel/algo.d.ts +13 -0
- package/dist/pregel/algo.d.ts.map +1 -0
- package/dist/pregel/algo.js +560 -0
- package/dist/pregel/algo.js.map +1 -0
- package/dist/pregel/call.cjs +50 -0
- package/dist/pregel/call.cjs.map +1 -0
- package/dist/pregel/call.js +48 -0
- package/dist/pregel/call.js.map +1 -0
- package/dist/pregel/debug.cjs +172 -0
- package/dist/pregel/debug.cjs.map +1 -0
- package/dist/pregel/debug.js +166 -0
- package/dist/pregel/debug.js.map +1 -0
- package/dist/pregel/index.cjs +1163 -0
- package/dist/pregel/index.cjs.map +1 -0
- package/dist/pregel/index.d.cts +498 -0
- package/dist/pregel/index.d.cts.map +1 -0
- package/dist/pregel/index.d.ts +498 -0
- package/dist/pregel/index.d.ts.map +1 -0
- package/dist/pregel/index.js +1162 -0
- package/dist/pregel/index.js.map +1 -0
- package/dist/pregel/io.cjs +140 -0
- package/dist/pregel/io.cjs.map +1 -0
- package/dist/pregel/io.js +135 -0
- package/dist/pregel/io.js.map +1 -0
- package/dist/pregel/loop.cjs +545 -0
- package/dist/pregel/loop.cjs.map +1 -0
- package/dist/pregel/loop.js +545 -0
- package/dist/pregel/loop.js.map +1 -0
- package/dist/pregel/messages.cjs +107 -0
- package/dist/pregel/messages.cjs.map +1 -0
- package/dist/pregel/messages.js +107 -0
- package/dist/pregel/messages.js.map +1 -0
- package/dist/pregel/read.cjs +151 -0
- package/dist/pregel/read.cjs.map +1 -0
- package/dist/pregel/read.d.cts +45 -0
- package/dist/pregel/read.d.cts.map +1 -0
- package/dist/pregel/read.d.ts +45 -0
- package/dist/pregel/read.d.ts.map +1 -0
- package/dist/pregel/read.js +150 -0
- package/dist/pregel/read.js.map +1 -0
- package/dist/pregel/remote.cjs +341 -0
- package/dist/pregel/remote.cjs.map +1 -0
- package/dist/pregel/remote.d.cts +118 -0
- package/dist/pregel/remote.d.cts.map +1 -0
- package/dist/pregel/remote.d.ts +118 -0
- package/dist/pregel/remote.d.ts.map +1 -0
- package/dist/pregel/remote.js +341 -0
- package/dist/pregel/remote.js.map +1 -0
- package/dist/pregel/retry.cjs +91 -0
- package/dist/pregel/retry.cjs.map +1 -0
- package/dist/pregel/retry.js +91 -0
- package/dist/pregel/retry.js.map +1 -0
- package/dist/pregel/runnable_types.d.cts +43 -0
- package/dist/pregel/runnable_types.d.cts.map +1 -0
- package/dist/pregel/runnable_types.d.ts +43 -0
- package/dist/pregel/runnable_types.d.ts.map +1 -0
- package/dist/pregel/runner.cjs +228 -0
- package/dist/pregel/runner.cjs.map +1 -0
- package/dist/pregel/runner.js +228 -0
- package/dist/pregel/runner.js.map +1 -0
- package/dist/pregel/stream.cjs +197 -0
- package/dist/pregel/stream.cjs.map +1 -0
- package/dist/pregel/stream.js +195 -0
- package/dist/pregel/stream.js.map +1 -0
- package/dist/pregel/types.cjs +27 -0
- package/dist/pregel/types.cjs.map +1 -0
- package/dist/pregel/types.d.cts +440 -0
- package/dist/pregel/types.d.cts.map +1 -0
- package/dist/pregel/types.d.ts +440 -0
- package/dist/pregel/types.d.ts.map +1 -0
- package/dist/pregel/types.js +25 -0
- package/dist/pregel/types.js.map +1 -0
- package/dist/pregel/utils/config.cjs +121 -0
- package/dist/pregel/utils/config.cjs.map +1 -0
- package/dist/pregel/utils/config.d.cts +36 -0
- package/dist/pregel/utils/config.d.cts.map +1 -0
- package/dist/pregel/utils/config.d.ts +36 -0
- package/dist/pregel/utils/config.d.ts.map +1 -0
- package/dist/pregel/utils/config.js +115 -0
- package/dist/pregel/utils/config.js.map +1 -0
- package/dist/pregel/utils/index.cjs +102 -0
- package/dist/pregel/utils/index.cjs.map +1 -0
- package/dist/pregel/utils/index.d.cts +51 -0
- package/dist/pregel/utils/index.d.cts.map +1 -0
- package/dist/pregel/utils/index.d.ts +51 -0
- package/dist/pregel/utils/index.d.ts.map +1 -0
- package/dist/pregel/utils/index.js +96 -0
- package/dist/pregel/utils/index.js.map +1 -0
- package/dist/pregel/utils/subgraph.cjs +18 -0
- package/dist/pregel/utils/subgraph.cjs.map +1 -0
- package/dist/pregel/utils/subgraph.js +16 -0
- package/dist/pregel/utils/subgraph.js.map +1 -0
- package/dist/pregel/validate.cjs +45 -0
- package/dist/pregel/validate.cjs.map +1 -0
- package/dist/pregel/validate.js +44 -0
- package/dist/pregel/validate.js.map +1 -0
- package/dist/pregel/write.cjs +96 -0
- package/dist/pregel/write.cjs.map +1 -0
- package/dist/pregel/write.d.cts +31 -0
- package/dist/pregel/write.d.cts.map +1 -0
- package/dist/pregel/write.d.ts +31 -0
- package/dist/pregel/write.d.ts.map +1 -0
- package/dist/pregel/write.js +95 -0
- package/dist/pregel/write.js.map +1 -0
- package/dist/remote.cjs +3 -0
- package/dist/remote.d.cts +2 -0
- package/dist/remote.d.ts +2 -0
- package/dist/remote.js +3 -0
- package/dist/setup/async_local_storage.cjs +11 -0
- package/dist/setup/async_local_storage.cjs.map +1 -0
- package/dist/setup/async_local_storage.js +11 -0
- package/dist/setup/async_local_storage.js.map +1 -0
- package/dist/utils.cjs +86 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +25 -0
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +80 -0
- package/dist/utils.js.map +1 -0
- package/dist/web.cjs +95 -0
- package/dist/web.d.cts +23 -0
- package/dist/web.d.ts +23 -0
- package/dist/web.js +15 -0
- package/dist/writer.cjs +14 -0
- package/dist/writer.cjs.map +1 -0
- package/dist/writer.d.cts +6 -0
- package/dist/writer.d.cts.map +1 -0
- package/dist/writer.d.ts +6 -0
- package/dist/writer.d.ts.map +1 -0
- package/dist/writer.js +14 -0
- package/dist/writer.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react_agent_executor.d.cts","names":["_langchain_core_messages17","_langchain_core_language_models_chat_models0","___web_js1","BaseChatModel","LanguageModelLike","BaseMessage","BaseMessageLike","SystemMessage","Runnable","RunnableToolLike","RunnableSequence","RunnableBinding","RunnableLike","DynamicTool","StructuredToolInterface","InteropZodObject","InteropZodType","All","BaseCheckpointSaver","BaseStore","CompiledStateGraph","AnnotationRoot","MessagesAnnotation","ToolNode","LangGraphRunnableConfig","Runtime","Messages","START","InteropZodToStateDefinition","AgentState","Record","StructuredResponseType","N","StructuredResponseSchemaOptions","ServerTool","ClientTool","ConfigurableModelInterface","Promise","_shouldBindTools","_bindTools","_langchain_core_language_models_base0","BaseLanguageModelInput","MessageToolSet","MessageStructure","AIMessageChunk","BaseChatModelCallOptions","_getModel","Prompt","State","StateModifier","MessageModifier","createReactAgentAnnotation","MessageType","BinaryOperatorAggregate","T","LastValue","SingleReducer","StateDefinition","S","PreHookAnnotation","AnyAnnotationRoot","ToAnnotationRoot","A","CreateReactAgentParams","C","createReactAgent","StructuredResponseFormat","spec","ReturnType"],"sources":["../../src/prebuilt/react_agent_executor.d.ts"],"sourcesContent":["import { BaseChatModel } from \"@langchain/core/language_models/chat_models\";\nimport { LanguageModelLike } from \"@langchain/core/language_models/base\";\nimport { BaseMessage, BaseMessageLike, SystemMessage } from \"@langchain/core/messages\";\nimport { Runnable, RunnableToolLike, RunnableSequence, RunnableBinding, type RunnableLike } from \"@langchain/core/runnables\";\nimport { DynamicTool, StructuredToolInterface } from \"@langchain/core/tools\";\nimport type { InteropZodObject, InteropZodType } from \"@langchain/core/utils/types\";\nimport { All, BaseCheckpointSaver, BaseStore } from \"@langchain/langgraph-checkpoint\";\nimport { type CompiledStateGraph, AnnotationRoot } from \"../graph/index.js\";\nimport { MessagesAnnotation } from \"../graph/messages_annotation.js\";\nimport { ToolNode } from \"./tool_node.js\";\nimport { LangGraphRunnableConfig, Runtime } from \"../pregel/runnable_types.js\";\nimport { Messages } from \"../graph/message.js\";\nimport { START } from \"../constants.js\";\nimport type { InteropZodToStateDefinition } from \"../graph/zod/meta.js\";\n/**\n * @deprecated `AgentState` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.\n * Update your import to `import { AgentState } from \"langchain\";`\n */\nexport interface AgentState<StructuredResponseType extends Record<string, any> = Record<string, any>> {\n messages: BaseMessage[];\n structuredResponse: StructuredResponseType;\n}\nexport type N = typeof START | \"agent\" | \"tools\";\ntype StructuredResponseSchemaOptions<StructuredResponseType> = {\n schema: InteropZodType<StructuredResponseType> | Record<string, any>;\n prompt?: string;\n strict?: boolean;\n [key: string]: unknown;\n};\ntype ServerTool = Record<string, unknown>;\ntype ClientTool = StructuredToolInterface | DynamicTool | RunnableToolLike;\ninterface ConfigurableModelInterface {\n _queuedMethodOperations: Record<string, any>;\n _model: () => Promise<BaseChatModel>;\n}\nexport declare function _shouldBindTools(llm: LanguageModelLike, tools: (ClientTool | ServerTool)[]): Promise<boolean>;\nexport declare function _bindTools(llm: LanguageModelLike, toolClasses: (ClientTool | ServerTool)[]): Promise<Runnable<import(\"@langchain/core/language_models/base\").BaseLanguageModelInput, import(\"@langchain/core/messages\").AIMessageChunk<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>>, import(\"@langchain/core/language_models/chat_models\").BaseChatModelCallOptions> | RunnableBinding<any, any, any> | RunnableSequence<any, any>>;\nexport declare function _getModel(llm: LanguageModelLike | ConfigurableModelInterface): Promise<LanguageModelLike>;\nexport type Prompt = SystemMessage | string | ((state: typeof MessagesAnnotation.State, config: LangGraphRunnableConfig) => BaseMessageLike[]) | ((state: typeof MessagesAnnotation.State, config: LangGraphRunnableConfig) => Promise<BaseMessageLike[]>) | Runnable;\n/** @deprecated Use Prompt instead. */\nexport type StateModifier = Prompt;\n/** @deprecated Use Prompt instead. */\nexport type MessageModifier = SystemMessage | string | ((messages: BaseMessage[]) => BaseMessage[]) | ((messages: BaseMessage[]) => Promise<BaseMessage[]>) | Runnable;\nexport declare const createReactAgentAnnotation: <T extends Record<string, any> = Record<string, any>>() => AnnotationRoot<{\n messages: import(\"../web.js\").BinaryOperatorAggregate<BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[], Messages>;\n structuredResponse: {\n (): import(\"../web.js\").LastValue<T>;\n (annotation: import(\"../web.js\").SingleReducer<T, T>): import(\"../web.js\").BinaryOperatorAggregate<T, T>;\n Root: <S extends import(\"../web.js\").StateDefinition>(sd: S) => AnnotationRoot<S>;\n };\n}>;\ndeclare const PreHookAnnotation: AnnotationRoot<{\n llmInputMessages: import(\"../web.js\").BinaryOperatorAggregate<BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[], Messages>;\n}>;\ntype PreHookAnnotation = typeof PreHookAnnotation;\ntype AnyAnnotationRoot = AnnotationRoot<any>;\ntype ToAnnotationRoot<A extends AnyAnnotationRoot | InteropZodObject> = A extends AnyAnnotationRoot ? A : A extends InteropZodObject ? AnnotationRoot<InteropZodToStateDefinition<A>> : never;\n/**\n * @deprecated `CreateReactAgentParams` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.\n * Update your import to `import { CreateAgentParams } from \"langchain\";`\n */\nexport type CreateReactAgentParams<A extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, StructuredResponseType extends Record<string, any> = Record<string, any>, C extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot> = {\n /** The chat model that can utilize OpenAI-style tool calling. */\n llm: LanguageModelLike | ((state: ToAnnotationRoot<A>[\"State\"] & PreHookAnnotation[\"State\"], runtime: Runtime<ToAnnotationRoot<C>[\"State\"]>) => Promise<LanguageModelLike> | LanguageModelLike);\n /** A list of tools or a ToolNode. */\n tools: ToolNode | (ServerTool | ClientTool)[];\n /**\n * @deprecated Use prompt instead.\n */\n messageModifier?: MessageModifier;\n /**\n * @deprecated Use prompt instead.\n */\n stateModifier?: StateModifier;\n /**\n * An optional prompt for the LLM. This takes full graph state BEFORE the LLM is called and prepares the input to LLM.\n *\n * Can take a few different forms:\n *\n * - str: This is converted to a SystemMessage and added to the beginning of the list of messages in state[\"messages\"].\n * - SystemMessage: this is added to the beginning of the list of messages in state[\"messages\"].\n * - Function: This function should take in full graph state and the output is then passed to the language model.\n * - Runnable: This runnable should take in full graph state and the output is then passed to the language model.\n *\n * Note:\n * Prior to `v0.2.46`, the prompt was set using `stateModifier` / `messagesModifier` parameters.\n * This is now deprecated and will be removed in a future release.\n */\n prompt?: Prompt;\n /**\n * Additional state schema for the agent.\n */\n stateSchema?: A;\n /**\n * An optional schema for the context.\n */\n contextSchema?: C;\n /** An optional checkpoint saver to persist the agent's state. */\n checkpointSaver?: BaseCheckpointSaver | boolean;\n /** An optional checkpoint saver to persist the agent's state. Alias of \"checkpointSaver\". */\n checkpointer?: BaseCheckpointSaver | boolean;\n /** An optional list of node names to interrupt before running. */\n interruptBefore?: N[] | All;\n /** An optional list of node names to interrupt after running. */\n interruptAfter?: N[] | All;\n store?: BaseStore;\n /**\n * An optional schema for the final agent output.\n *\n * If provided, output will be formatted to match the given schema and returned in the 'structuredResponse' state key.\n * If not provided, `structuredResponse` will not be present in the output state.\n *\n * Can be passed in as:\n * - Zod schema\n * - JSON schema\n * - { prompt, schema }, where schema is one of the above.\n * The prompt will be used together with the model that is being used to generate the structured response.\n *\n * @remarks\n * **Important**: `responseFormat` requires the model to support `.withStructuredOutput()`.\n *\n * **Note**: The graph will make a separate call to the LLM to generate the structured response after the agent loop is finished.\n * This is not the only strategy to get structured responses, see more options in [this guide](https://langchain-ai.github.io/langgraph/how-tos/react-agent-structured-output/).\n */\n responseFormat?: InteropZodType<StructuredResponseType> | StructuredResponseSchemaOptions<StructuredResponseType> | Record<string, any>;\n /**\n * An optional name for the agent.\n */\n name?: string;\n /**\n * An optional description for the agent.\n * This can be used to describe the agent to the underlying supervisor LLM.\n */\n description?: string | undefined;\n /**\n * Use to specify how to expose the agent name to the underlying supervisor LLM.\n \n - undefined: Relies on the LLM provider {@link AIMessage#name}. Currently, only OpenAI supports this.\n - `\"inline\"`: Add the agent name directly into the content field of the {@link AIMessage} using XML-style tags.\n Example: `\"How can I help you\"` -> `\"<name>agent_name</name><content>How can I help you?</content>\"`\n */\n includeAgentName?: \"inline\" | undefined;\n /**\n * An optional node to add before the `agent` node (i.e., the node that calls the LLM).\n * Useful for managing long message histories (e.g., message trimming, summarization, etc.).\n */\n preModelHook?: RunnableLike<ToAnnotationRoot<A>[\"State\"] & PreHookAnnotation[\"State\"], ToAnnotationRoot<A>[\"Update\"] & PreHookAnnotation[\"Update\"], LangGraphRunnableConfig>;\n /**\n * An optional node to add after the `agent` node (i.e., the node that calls the LLM).\n * Useful for implementing human-in-the-loop, guardrails, validation, or other post-processing.\n */\n postModelHook?: RunnableLike<ToAnnotationRoot<A>[\"State\"], ToAnnotationRoot<A>[\"Update\"], LangGraphRunnableConfig>;\n /**\n * Determines the version of the graph to create.\n *\n * Can be one of\n * - `\"v1\"`: The tool node processes a single message. All tool calls in the message are\n * executed in parallel within the tool node.\n * - `\"v2\"`: The tool node processes a single tool call. Tool calls are distributed across\n * multiple instances of the tool node using the Send API.\n *\n * @default `\"v1\"`\n */\n version?: \"v1\" | \"v2\";\n};\n/**\n * @deprecated `createReactAgent` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.\n * Update your import to `import { createAgent } from \"langchain\";`\n *\n * Creates a StateGraph agent that relies on a chat model utilizing tool calling.\n *\n * @example\n * ```ts\n * import { ChatOpenAI } from \"@langchain/openai\";\n * import { tool } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n * import { createReactAgent } from \"@langchain/langgraph/prebuilt\";\n *\n * const model = new ChatOpenAI({\n * model: \"gpt-4o\",\n * });\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * })\n * })\n *\n * const agent = createReactAgent({ llm: model, tools: [getWeather] });\n *\n * const inputs = {\n * messages: [{ role: \"user\", content: \"what is the weather in SF?\" }],\n * };\n *\n * const stream = await agent.stream(inputs, { streamMode: \"values\" });\n *\n * for await (const { messages } of stream) {\n * console.log(messages);\n * }\n * // Returns the messages in the state at each step of execution\n * ```\n */\nexport declare function createReactAgent<A extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, StructuredResponseFormat extends Record<string, any> = Record<string, any>, C extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateReactAgentParams<A, StructuredResponseFormat, C>): CompiledStateGraph<ToAnnotationRoot<A>[\"State\"], ToAnnotationRoot<A>[\"Update\"], any, typeof MessagesAnnotation.spec & ToAnnotationRoot<A>[\"spec\"], ReturnType<typeof createReactAgentAnnotation<StructuredResponseFormat>>[\"spec\"] & ToAnnotationRoot<A>[\"spec\"]>;\nexport {};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;UAkBiB6B,0CAA0CC,sBAAsBA;EAAhED,QAAAA,EACHxB,WADa,EAAA;EAAA,kBAAA,EAEH0B,sBAFG;;AAAsDD,KAIrEE,CAAAA,GAJqEF,OAI1DH,KAJ0DG,GAAAA,OAAAA,GAAAA,OAAAA;KAK5EG,+BAJS5B,CAAAA,sBAAAA,CAAAA,GAAAA;QACU0B,EAIZf,cAJYe,CAIGA,sBAJHA,CAAAA,GAI6BD,MAJ7BC,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA;EAAsB,MAAA,CAAA,EAAA,MAAA;EAElCC,MAAC,CAAA,EAAA,OAAUL;EAClBM,CAAAA,GAAAA,EAAAA,MAAAA,CAAAA,EAAAA,OAAAA;CAA+B;KAM/BC,UAAAA,GAAaJ,MALSC,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;KAMtBI,UAAAA,GAAarB,uBANNE,GAMgCH,WANhCG,GAM8CP,gBAN9CO;AAM8CP,KAQ9CsC,MAAAA,GAASxC,aARqCE,GAAAA,MAAAA,GAAAA,CAAAA,CAAAA,KAAAA,EAAAA,OAQIa,kBAAAA,CAAmB0B,KARvBvC,EAAAA,MAAAA,EAQsCe,uBARtCf,EAAAA,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CAAAA,GAyC+GwC,iBAzC/GxC,CAAAA,QAAAA,CAAAA,EAyC4IK,uBAzC5IL,CAAAA;;;;;eAmB4GW,CAAAA,EA2BpGlB,YA3BoGkB,CA2BvF+B,gBA3BuF/B,CA2BtEgC,CA3BsEhC,CAAAA,CAAAA,OAAAA,CAAAA,EA2BzD+B,gBA3ByD/B,CA2BxCgC,CA3BwChC,CAAAA,CAAAA,QAAAA,CAAAA,EA2B1BN,uBA3B0BM,CAAAA;;;;;;;;;;;;SA2BzD+B,CAAAA,EAAAA,IAAAA,GAAAA,IAAAA;;;;AA2D/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAwBI,2BAA2BL,oBAAoB7C,0BAA0BO,qDAAqDQ,sBAAsBA,+BAA+B8B,oBAAoB7C,mBAAmB6C,2BAA2BG,uBAAuBD,GAAGI,0BAA0BF,KAAK5C,mBAAmByC,iBAAiBC,aAAaD,iBAAiBC,0BAA0BxC,kBAAAA,CAAmB6C,OAAON,iBAAiBC,YAAYM,kBAAkBjB,2BAA2Be,qCAAqCL,iBAAiBC"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { BinaryOperatorAggregate } from "../channels/binop.js";
|
|
2
|
+
import { LastValue } from "../channels/last_value.js";
|
|
3
|
+
import { InteropZodToStateDefinition } from "../graph/zod/meta.js";
|
|
4
|
+
import { LangGraphRunnableConfig, Runtime } from "../pregel/runnable_types.js";
|
|
5
|
+
import { AnnotationRoot, SingleReducer, StateDefinition } from "../graph/annotation.js";
|
|
6
|
+
import { START } from "../constants.js";
|
|
7
|
+
import { CompiledStateGraph } from "../graph/state.js";
|
|
8
|
+
import { Messages } from "../graph/message.js";
|
|
9
|
+
import { MessagesAnnotation } from "../graph/messages_annotation.js";
|
|
10
|
+
import { ToolNode } from "./tool_node.js";
|
|
11
|
+
import { All, BaseCheckpointSaver, BaseStore } from "@langchain/langgraph-checkpoint";
|
|
12
|
+
import { Runnable, RunnableBinding, RunnableLike, RunnableSequence, RunnableToolLike } from "@langchain/core/runnables";
|
|
13
|
+
import * as _langchain_core_messages17 from "@langchain/core/messages";
|
|
14
|
+
import { BaseMessage, BaseMessageLike, SystemMessage } from "@langchain/core/messages";
|
|
15
|
+
import { InteropZodObject, InteropZodType } from "@langchain/core/utils/types";
|
|
16
|
+
import { DynamicTool, StructuredToolInterface } from "@langchain/core/tools";
|
|
17
|
+
import { LanguageModelLike } from "@langchain/core/language_models/base";
|
|
18
|
+
|
|
19
|
+
//#region src/prebuilt/react_agent_executor.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated `AgentState` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.
|
|
22
|
+
* Update your import to `import { AgentState } from "langchain";`
|
|
23
|
+
*/
|
|
24
|
+
interface AgentState<StructuredResponseType extends Record<string, any> = Record<string, any>> {
|
|
25
|
+
messages: BaseMessage[];
|
|
26
|
+
structuredResponse: StructuredResponseType;
|
|
27
|
+
}
|
|
28
|
+
type N = typeof START | "agent" | "tools";
|
|
29
|
+
type StructuredResponseSchemaOptions<StructuredResponseType> = {
|
|
30
|
+
schema: InteropZodType<StructuredResponseType> | Record<string, any>;
|
|
31
|
+
prompt?: string;
|
|
32
|
+
strict?: boolean;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
};
|
|
35
|
+
type ServerTool = Record<string, unknown>;
|
|
36
|
+
type ClientTool = StructuredToolInterface | DynamicTool | RunnableToolLike;
|
|
37
|
+
type Prompt = SystemMessage | string | ((state: typeof MessagesAnnotation.State, config: LangGraphRunnableConfig) => BaseMessageLike[]) | ((state: typeof MessagesAnnotation.State, config: LangGraphRunnableConfig) => Promise<BaseMessageLike[]>) | Runnable;
|
|
38
|
+
/** @deprecated Use Prompt instead. */
|
|
39
|
+
type StateModifier = Prompt;
|
|
40
|
+
/** @deprecated Use Prompt instead. */
|
|
41
|
+
type MessageModifier = SystemMessage | string | ((messages: BaseMessage[]) => BaseMessage[]) | ((messages: BaseMessage[]) => Promise<BaseMessage[]>) | Runnable;
|
|
42
|
+
declare const createReactAgentAnnotation: <T extends Record<string, any> = Record<string, any>>() => AnnotationRoot<{
|
|
43
|
+
messages: BinaryOperatorAggregate<BaseMessage<_langchain_core_messages17.MessageStructure<_langchain_core_messages17.MessageToolSet>, _langchain_core_messages17.MessageType>[], Messages>;
|
|
44
|
+
structuredResponse: {
|
|
45
|
+
(): LastValue<T>;
|
|
46
|
+
(annotation: SingleReducer<T, T>): BinaryOperatorAggregate<T, T>;
|
|
47
|
+
Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<S>;
|
|
48
|
+
};
|
|
49
|
+
}>;
|
|
50
|
+
declare const PreHookAnnotation: AnnotationRoot<{
|
|
51
|
+
llmInputMessages: BinaryOperatorAggregate<BaseMessage<_langchain_core_messages17.MessageStructure<_langchain_core_messages17.MessageToolSet>, _langchain_core_messages17.MessageType>[], Messages>;
|
|
52
|
+
}>;
|
|
53
|
+
type PreHookAnnotation = typeof PreHookAnnotation;
|
|
54
|
+
type AnyAnnotationRoot = AnnotationRoot<any>;
|
|
55
|
+
type ToAnnotationRoot<A extends AnyAnnotationRoot | InteropZodObject> = A extends AnyAnnotationRoot ? A : A extends InteropZodObject ? AnnotationRoot<InteropZodToStateDefinition<A>> : never;
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated `CreateReactAgentParams` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.
|
|
58
|
+
* Update your import to `import { CreateAgentParams } from "langchain";`
|
|
59
|
+
*/
|
|
60
|
+
type CreateReactAgentParams<A extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, StructuredResponseType extends Record<string, any> = Record<string, any>, C extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot> = {
|
|
61
|
+
/** The chat model that can utilize OpenAI-style tool calling. */
|
|
62
|
+
llm: LanguageModelLike | ((state: ToAnnotationRoot<A>["State"] & PreHookAnnotation["State"], runtime: Runtime<ToAnnotationRoot<C>["State"]>) => Promise<LanguageModelLike> | LanguageModelLike);
|
|
63
|
+
/** A list of tools or a ToolNode. */
|
|
64
|
+
tools: ToolNode | (ServerTool | ClientTool)[];
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated Use prompt instead.
|
|
67
|
+
*/
|
|
68
|
+
messageModifier?: MessageModifier;
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated Use prompt instead.
|
|
71
|
+
*/
|
|
72
|
+
stateModifier?: StateModifier;
|
|
73
|
+
/**
|
|
74
|
+
* An optional prompt for the LLM. This takes full graph state BEFORE the LLM is called and prepares the input to LLM.
|
|
75
|
+
*
|
|
76
|
+
* Can take a few different forms:
|
|
77
|
+
*
|
|
78
|
+
* - str: This is converted to a SystemMessage and added to the beginning of the list of messages in state["messages"].
|
|
79
|
+
* - SystemMessage: this is added to the beginning of the list of messages in state["messages"].
|
|
80
|
+
* - Function: This function should take in full graph state and the output is then passed to the language model.
|
|
81
|
+
* - Runnable: This runnable should take in full graph state and the output is then passed to the language model.
|
|
82
|
+
*
|
|
83
|
+
* Note:
|
|
84
|
+
* Prior to `v0.2.46`, the prompt was set using `stateModifier` / `messagesModifier` parameters.
|
|
85
|
+
* This is now deprecated and will be removed in a future release.
|
|
86
|
+
*/
|
|
87
|
+
prompt?: Prompt;
|
|
88
|
+
/**
|
|
89
|
+
* Additional state schema for the agent.
|
|
90
|
+
*/
|
|
91
|
+
stateSchema?: A;
|
|
92
|
+
/**
|
|
93
|
+
* An optional schema for the context.
|
|
94
|
+
*/
|
|
95
|
+
contextSchema?: C;
|
|
96
|
+
/** An optional checkpoint saver to persist the agent's state. */
|
|
97
|
+
checkpointSaver?: BaseCheckpointSaver | boolean;
|
|
98
|
+
/** An optional checkpoint saver to persist the agent's state. Alias of "checkpointSaver". */
|
|
99
|
+
checkpointer?: BaseCheckpointSaver | boolean;
|
|
100
|
+
/** An optional list of node names to interrupt before running. */
|
|
101
|
+
interruptBefore?: N[] | All;
|
|
102
|
+
/** An optional list of node names to interrupt after running. */
|
|
103
|
+
interruptAfter?: N[] | All;
|
|
104
|
+
store?: BaseStore;
|
|
105
|
+
/**
|
|
106
|
+
* An optional schema for the final agent output.
|
|
107
|
+
*
|
|
108
|
+
* If provided, output will be formatted to match the given schema and returned in the 'structuredResponse' state key.
|
|
109
|
+
* If not provided, `structuredResponse` will not be present in the output state.
|
|
110
|
+
*
|
|
111
|
+
* Can be passed in as:
|
|
112
|
+
* - Zod schema
|
|
113
|
+
* - JSON schema
|
|
114
|
+
* - { prompt, schema }, where schema is one of the above.
|
|
115
|
+
* The prompt will be used together with the model that is being used to generate the structured response.
|
|
116
|
+
*
|
|
117
|
+
* @remarks
|
|
118
|
+
* **Important**: `responseFormat` requires the model to support `.withStructuredOutput()`.
|
|
119
|
+
*
|
|
120
|
+
* **Note**: The graph will make a separate call to the LLM to generate the structured response after the agent loop is finished.
|
|
121
|
+
* This is not the only strategy to get structured responses, see more options in [this guide](https://langchain-ai.github.io/langgraph/how-tos/react-agent-structured-output/).
|
|
122
|
+
*/
|
|
123
|
+
responseFormat?: InteropZodType<StructuredResponseType> | StructuredResponseSchemaOptions<StructuredResponseType> | Record<string, any>;
|
|
124
|
+
/**
|
|
125
|
+
* An optional name for the agent.
|
|
126
|
+
*/
|
|
127
|
+
name?: string;
|
|
128
|
+
/**
|
|
129
|
+
* An optional description for the agent.
|
|
130
|
+
* This can be used to describe the agent to the underlying supervisor LLM.
|
|
131
|
+
*/
|
|
132
|
+
description?: string | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* Use to specify how to expose the agent name to the underlying supervisor LLM.
|
|
135
|
+
- undefined: Relies on the LLM provider {@link AIMessage#name}. Currently, only OpenAI supports this.
|
|
136
|
+
- `"inline"`: Add the agent name directly into the content field of the {@link AIMessage} using XML-style tags.
|
|
137
|
+
Example: `"How can I help you"` -> `"<name>agent_name</name><content>How can I help you?</content>"`
|
|
138
|
+
*/
|
|
139
|
+
includeAgentName?: "inline" | undefined;
|
|
140
|
+
/**
|
|
141
|
+
* An optional node to add before the `agent` node (i.e., the node that calls the LLM).
|
|
142
|
+
* Useful for managing long message histories (e.g., message trimming, summarization, etc.).
|
|
143
|
+
*/
|
|
144
|
+
preModelHook?: RunnableLike<ToAnnotationRoot<A>["State"] & PreHookAnnotation["State"], ToAnnotationRoot<A>["Update"] & PreHookAnnotation["Update"], LangGraphRunnableConfig>;
|
|
145
|
+
/**
|
|
146
|
+
* An optional node to add after the `agent` node (i.e., the node that calls the LLM).
|
|
147
|
+
* Useful for implementing human-in-the-loop, guardrails, validation, or other post-processing.
|
|
148
|
+
*/
|
|
149
|
+
postModelHook?: RunnableLike<ToAnnotationRoot<A>["State"], ToAnnotationRoot<A>["Update"], LangGraphRunnableConfig>;
|
|
150
|
+
/**
|
|
151
|
+
* Determines the version of the graph to create.
|
|
152
|
+
*
|
|
153
|
+
* Can be one of
|
|
154
|
+
* - `"v1"`: The tool node processes a single message. All tool calls in the message are
|
|
155
|
+
* executed in parallel within the tool node.
|
|
156
|
+
* - `"v2"`: The tool node processes a single tool call. Tool calls are distributed across
|
|
157
|
+
* multiple instances of the tool node using the Send API.
|
|
158
|
+
*
|
|
159
|
+
* @default `"v1"`
|
|
160
|
+
*/
|
|
161
|
+
version?: "v1" | "v2";
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* @deprecated `createReactAgent` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.
|
|
165
|
+
* Update your import to `import { createAgent } from "langchain";`
|
|
166
|
+
*
|
|
167
|
+
* Creates a StateGraph agent that relies on a chat model utilizing tool calling.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* import { ChatOpenAI } from "@langchain/openai";
|
|
172
|
+
* import { tool } from "@langchain/core/tools";
|
|
173
|
+
* import { z } from "zod";
|
|
174
|
+
* import { createReactAgent } from "@langchain/langgraph/prebuilt";
|
|
175
|
+
*
|
|
176
|
+
* const model = new ChatOpenAI({
|
|
177
|
+
* model: "gpt-4o",
|
|
178
|
+
* });
|
|
179
|
+
*
|
|
180
|
+
* const getWeather = tool((input) => {
|
|
181
|
+
* if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
|
|
182
|
+
* return "It's 60 degrees and foggy.";
|
|
183
|
+
* } else {
|
|
184
|
+
* return "It's 90 degrees and sunny.";
|
|
185
|
+
* }
|
|
186
|
+
* }, {
|
|
187
|
+
* name: "get_weather",
|
|
188
|
+
* description: "Call to get the current weather.",
|
|
189
|
+
* schema: z.object({
|
|
190
|
+
* location: z.string().describe("Location to get the weather for."),
|
|
191
|
+
* })
|
|
192
|
+
* })
|
|
193
|
+
*
|
|
194
|
+
* const agent = createReactAgent({ llm: model, tools: [getWeather] });
|
|
195
|
+
*
|
|
196
|
+
* const inputs = {
|
|
197
|
+
* messages: [{ role: "user", content: "what is the weather in SF?" }],
|
|
198
|
+
* };
|
|
199
|
+
*
|
|
200
|
+
* const stream = await agent.stream(inputs, { streamMode: "values" });
|
|
201
|
+
*
|
|
202
|
+
* for await (const { messages } of stream) {
|
|
203
|
+
* console.log(messages);
|
|
204
|
+
* }
|
|
205
|
+
* // Returns the messages in the state at each step of execution
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
declare function createReactAgent<A extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, StructuredResponseFormat extends Record<string, any> = Record<string, any>, C extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateReactAgentParams<A, StructuredResponseFormat, C>): CompiledStateGraph<ToAnnotationRoot<A>["State"], ToAnnotationRoot<A>["Update"], any, typeof MessagesAnnotation.spec & ToAnnotationRoot<A>["spec"], ReturnType<typeof createReactAgentAnnotation<StructuredResponseFormat>>["spec"] & ToAnnotationRoot<A>["spec"]>;
|
|
209
|
+
//#endregion
|
|
210
|
+
export { AgentState, CreateReactAgentParams, createReactAgent, createReactAgentAnnotation };
|
|
211
|
+
//# sourceMappingURL=react_agent_executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react_agent_executor.d.ts","names":["_langchain_core_messages17","_langchain_core_language_models_chat_models0","___web_js1","BaseChatModel","LanguageModelLike","BaseMessage","BaseMessageLike","SystemMessage","Runnable","RunnableToolLike","RunnableSequence","RunnableBinding","RunnableLike","DynamicTool","StructuredToolInterface","InteropZodObject","InteropZodType","All","BaseCheckpointSaver","BaseStore","CompiledStateGraph","AnnotationRoot","MessagesAnnotation","ToolNode","LangGraphRunnableConfig","Runtime","Messages","START","InteropZodToStateDefinition","AgentState","Record","StructuredResponseType","N","StructuredResponseSchemaOptions","ServerTool","ClientTool","ConfigurableModelInterface","Promise","_shouldBindTools","_bindTools","_langchain_core_language_models_base0","BaseLanguageModelInput","MessageToolSet","MessageStructure","AIMessageChunk","BaseChatModelCallOptions","_getModel","Prompt","State","StateModifier","MessageModifier","createReactAgentAnnotation","MessageType","BinaryOperatorAggregate","T","LastValue","SingleReducer","StateDefinition","S","PreHookAnnotation","AnyAnnotationRoot","ToAnnotationRoot","A","CreateReactAgentParams","C","createReactAgent","StructuredResponseFormat","spec","ReturnType"],"sources":["../../src/prebuilt/react_agent_executor.d.ts"],"sourcesContent":["import { BaseChatModel } from \"@langchain/core/language_models/chat_models\";\nimport { LanguageModelLike } from \"@langchain/core/language_models/base\";\nimport { BaseMessage, BaseMessageLike, SystemMessage } from \"@langchain/core/messages\";\nimport { Runnable, RunnableToolLike, RunnableSequence, RunnableBinding, type RunnableLike } from \"@langchain/core/runnables\";\nimport { DynamicTool, StructuredToolInterface } from \"@langchain/core/tools\";\nimport type { InteropZodObject, InteropZodType } from \"@langchain/core/utils/types\";\nimport { All, BaseCheckpointSaver, BaseStore } from \"@langchain/langgraph-checkpoint\";\nimport { type CompiledStateGraph, AnnotationRoot } from \"../graph/index.js\";\nimport { MessagesAnnotation } from \"../graph/messages_annotation.js\";\nimport { ToolNode } from \"./tool_node.js\";\nimport { LangGraphRunnableConfig, Runtime } from \"../pregel/runnable_types.js\";\nimport { Messages } from \"../graph/message.js\";\nimport { START } from \"../constants.js\";\nimport type { InteropZodToStateDefinition } from \"../graph/zod/meta.js\";\n/**\n * @deprecated `AgentState` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.\n * Update your import to `import { AgentState } from \"langchain\";`\n */\nexport interface AgentState<StructuredResponseType extends Record<string, any> = Record<string, any>> {\n messages: BaseMessage[];\n structuredResponse: StructuredResponseType;\n}\nexport type N = typeof START | \"agent\" | \"tools\";\ntype StructuredResponseSchemaOptions<StructuredResponseType> = {\n schema: InteropZodType<StructuredResponseType> | Record<string, any>;\n prompt?: string;\n strict?: boolean;\n [key: string]: unknown;\n};\ntype ServerTool = Record<string, unknown>;\ntype ClientTool = StructuredToolInterface | DynamicTool | RunnableToolLike;\ninterface ConfigurableModelInterface {\n _queuedMethodOperations: Record<string, any>;\n _model: () => Promise<BaseChatModel>;\n}\nexport declare function _shouldBindTools(llm: LanguageModelLike, tools: (ClientTool | ServerTool)[]): Promise<boolean>;\nexport declare function _bindTools(llm: LanguageModelLike, toolClasses: (ClientTool | ServerTool)[]): Promise<Runnable<import(\"@langchain/core/language_models/base\").BaseLanguageModelInput, import(\"@langchain/core/messages\").AIMessageChunk<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>>, import(\"@langchain/core/language_models/chat_models\").BaseChatModelCallOptions> | RunnableBinding<any, any, any> | RunnableSequence<any, any>>;\nexport declare function _getModel(llm: LanguageModelLike | ConfigurableModelInterface): Promise<LanguageModelLike>;\nexport type Prompt = SystemMessage | string | ((state: typeof MessagesAnnotation.State, config: LangGraphRunnableConfig) => BaseMessageLike[]) | ((state: typeof MessagesAnnotation.State, config: LangGraphRunnableConfig) => Promise<BaseMessageLike[]>) | Runnable;\n/** @deprecated Use Prompt instead. */\nexport type StateModifier = Prompt;\n/** @deprecated Use Prompt instead. */\nexport type MessageModifier = SystemMessage | string | ((messages: BaseMessage[]) => BaseMessage[]) | ((messages: BaseMessage[]) => Promise<BaseMessage[]>) | Runnable;\nexport declare const createReactAgentAnnotation: <T extends Record<string, any> = Record<string, any>>() => AnnotationRoot<{\n messages: import(\"../web.js\").BinaryOperatorAggregate<BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[], Messages>;\n structuredResponse: {\n (): import(\"../web.js\").LastValue<T>;\n (annotation: import(\"../web.js\").SingleReducer<T, T>): import(\"../web.js\").BinaryOperatorAggregate<T, T>;\n Root: <S extends import(\"../web.js\").StateDefinition>(sd: S) => AnnotationRoot<S>;\n };\n}>;\ndeclare const PreHookAnnotation: AnnotationRoot<{\n llmInputMessages: import(\"../web.js\").BinaryOperatorAggregate<BaseMessage<import(\"@langchain/core/messages\").MessageStructure<import(\"@langchain/core/messages\").MessageToolSet>, import(\"@langchain/core/messages\").MessageType>[], Messages>;\n}>;\ntype PreHookAnnotation = typeof PreHookAnnotation;\ntype AnyAnnotationRoot = AnnotationRoot<any>;\ntype ToAnnotationRoot<A extends AnyAnnotationRoot | InteropZodObject> = A extends AnyAnnotationRoot ? A : A extends InteropZodObject ? AnnotationRoot<InteropZodToStateDefinition<A>> : never;\n/**\n * @deprecated `CreateReactAgentParams` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.\n * Update your import to `import { CreateAgentParams } from \"langchain\";`\n */\nexport type CreateReactAgentParams<A extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, StructuredResponseType extends Record<string, any> = Record<string, any>, C extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot> = {\n /** The chat model that can utilize OpenAI-style tool calling. */\n llm: LanguageModelLike | ((state: ToAnnotationRoot<A>[\"State\"] & PreHookAnnotation[\"State\"], runtime: Runtime<ToAnnotationRoot<C>[\"State\"]>) => Promise<LanguageModelLike> | LanguageModelLike);\n /** A list of tools or a ToolNode. */\n tools: ToolNode | (ServerTool | ClientTool)[];\n /**\n * @deprecated Use prompt instead.\n */\n messageModifier?: MessageModifier;\n /**\n * @deprecated Use prompt instead.\n */\n stateModifier?: StateModifier;\n /**\n * An optional prompt for the LLM. This takes full graph state BEFORE the LLM is called and prepares the input to LLM.\n *\n * Can take a few different forms:\n *\n * - str: This is converted to a SystemMessage and added to the beginning of the list of messages in state[\"messages\"].\n * - SystemMessage: this is added to the beginning of the list of messages in state[\"messages\"].\n * - Function: This function should take in full graph state and the output is then passed to the language model.\n * - Runnable: This runnable should take in full graph state and the output is then passed to the language model.\n *\n * Note:\n * Prior to `v0.2.46`, the prompt was set using `stateModifier` / `messagesModifier` parameters.\n * This is now deprecated and will be removed in a future release.\n */\n prompt?: Prompt;\n /**\n * Additional state schema for the agent.\n */\n stateSchema?: A;\n /**\n * An optional schema for the context.\n */\n contextSchema?: C;\n /** An optional checkpoint saver to persist the agent's state. */\n checkpointSaver?: BaseCheckpointSaver | boolean;\n /** An optional checkpoint saver to persist the agent's state. Alias of \"checkpointSaver\". */\n checkpointer?: BaseCheckpointSaver | boolean;\n /** An optional list of node names to interrupt before running. */\n interruptBefore?: N[] | All;\n /** An optional list of node names to interrupt after running. */\n interruptAfter?: N[] | All;\n store?: BaseStore;\n /**\n * An optional schema for the final agent output.\n *\n * If provided, output will be formatted to match the given schema and returned in the 'structuredResponse' state key.\n * If not provided, `structuredResponse` will not be present in the output state.\n *\n * Can be passed in as:\n * - Zod schema\n * - JSON schema\n * - { prompt, schema }, where schema is one of the above.\n * The prompt will be used together with the model that is being used to generate the structured response.\n *\n * @remarks\n * **Important**: `responseFormat` requires the model to support `.withStructuredOutput()`.\n *\n * **Note**: The graph will make a separate call to the LLM to generate the structured response after the agent loop is finished.\n * This is not the only strategy to get structured responses, see more options in [this guide](https://langchain-ai.github.io/langgraph/how-tos/react-agent-structured-output/).\n */\n responseFormat?: InteropZodType<StructuredResponseType> | StructuredResponseSchemaOptions<StructuredResponseType> | Record<string, any>;\n /**\n * An optional name for the agent.\n */\n name?: string;\n /**\n * An optional description for the agent.\n * This can be used to describe the agent to the underlying supervisor LLM.\n */\n description?: string | undefined;\n /**\n * Use to specify how to expose the agent name to the underlying supervisor LLM.\n \n - undefined: Relies on the LLM provider {@link AIMessage#name}. Currently, only OpenAI supports this.\n - `\"inline\"`: Add the agent name directly into the content field of the {@link AIMessage} using XML-style tags.\n Example: `\"How can I help you\"` -> `\"<name>agent_name</name><content>How can I help you?</content>\"`\n */\n includeAgentName?: \"inline\" | undefined;\n /**\n * An optional node to add before the `agent` node (i.e., the node that calls the LLM).\n * Useful for managing long message histories (e.g., message trimming, summarization, etc.).\n */\n preModelHook?: RunnableLike<ToAnnotationRoot<A>[\"State\"] & PreHookAnnotation[\"State\"], ToAnnotationRoot<A>[\"Update\"] & PreHookAnnotation[\"Update\"], LangGraphRunnableConfig>;\n /**\n * An optional node to add after the `agent` node (i.e., the node that calls the LLM).\n * Useful for implementing human-in-the-loop, guardrails, validation, or other post-processing.\n */\n postModelHook?: RunnableLike<ToAnnotationRoot<A>[\"State\"], ToAnnotationRoot<A>[\"Update\"], LangGraphRunnableConfig>;\n /**\n * Determines the version of the graph to create.\n *\n * Can be one of\n * - `\"v1\"`: The tool node processes a single message. All tool calls in the message are\n * executed in parallel within the tool node.\n * - `\"v2\"`: The tool node processes a single tool call. Tool calls are distributed across\n * multiple instances of the tool node using the Send API.\n *\n * @default `\"v1\"`\n */\n version?: \"v1\" | \"v2\";\n};\n/**\n * @deprecated `createReactAgent` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.\n * Update your import to `import { createAgent } from \"langchain\";`\n *\n * Creates a StateGraph agent that relies on a chat model utilizing tool calling.\n *\n * @example\n * ```ts\n * import { ChatOpenAI } from \"@langchain/openai\";\n * import { tool } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n * import { createReactAgent } from \"@langchain/langgraph/prebuilt\";\n *\n * const model = new ChatOpenAI({\n * model: \"gpt-4o\",\n * });\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * })\n * })\n *\n * const agent = createReactAgent({ llm: model, tools: [getWeather] });\n *\n * const inputs = {\n * messages: [{ role: \"user\", content: \"what is the weather in SF?\" }],\n * };\n *\n * const stream = await agent.stream(inputs, { streamMode: \"values\" });\n *\n * for await (const { messages } of stream) {\n * console.log(messages);\n * }\n * // Returns the messages in the state at each step of execution\n * ```\n */\nexport declare function createReactAgent<A extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation, StructuredResponseFormat extends Record<string, any> = Record<string, any>, C extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot>(params: CreateReactAgentParams<A, StructuredResponseFormat, C>): CompiledStateGraph<ToAnnotationRoot<A>[\"State\"], ToAnnotationRoot<A>[\"Update\"], any, typeof MessagesAnnotation.spec & ToAnnotationRoot<A>[\"spec\"], ReturnType<typeof createReactAgentAnnotation<StructuredResponseFormat>>[\"spec\"] & ToAnnotationRoot<A>[\"spec\"]>;\nexport {};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;UAkBiB6B,0CAA0CC,sBAAsBA;EAAhED,QAAAA,EACHxB,WADa,EAAA;EAAA,kBAAA,EAEH0B,sBAFG;;AAAsDD,KAIrEE,CAAAA,GAJqEF,OAI1DH,KAJ0DG,GAAAA,OAAAA,GAAAA,OAAAA;KAK5EG,+BAJS5B,CAAAA,sBAAAA,CAAAA,GAAAA;QACU0B,EAIZf,cAJYe,CAIGA,sBAJHA,CAAAA,GAI6BD,MAJ7BC,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA;EAAsB,MAAA,CAAA,EAAA,MAAA;EAElCC,MAAC,CAAA,EAAA,OAAUL;EAClBM,CAAAA,GAAAA,EAAAA,MAAAA,CAAAA,EAAAA,OAAAA;CAA+B;KAM/BC,UAAAA,GAAaJ,MALSC,CAAAA,MA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AAAA,EAAAA,QAAAA,GAAAA,SAAAA;;;;;cAKPC,CAAAA,EAyCOP,YAzCPO,CAyCoB0C,gBAzCpB1C,CAyCqC2C,CAzCrC3C,CAAAA,CAAAA,OAAAA,CAAAA,GAyCmDwC,iBAzCnDxC,CAAAA,OAAAA,CAAAA,EAyC+E0C,gBAzC/E1C,CAyCgG2C,CAzChG3C,CAAAA,CAAAA,QAAAA,CAAAA,GAyC+GwC,iBAzC/GxC,CAAAA,QAAAA,CAAAA,EAyC4IK,uBAzC5IL,CAAAA;;;;;eAmB4GW,CAAAA,EA2BpGlB,YA3BoGkB,CA2BvF+B,gBA3BuF/B,CA2BtEgC,CA3BsEhC,CAAAA,CAAAA,OAAAA,CAAAA,EA2BzD+B,gBA3ByD/B,CA2BxCgC,CA3BwChC,CAAAA,CAAAA,QAAAA,CAAAA,EA2B1BN,uBA3B0BM,CAAAA;;;;;;;;;;;;SA2BzD+B,CAAAA,EAAAA,IAAAA,GAAAA,IAAAA;;;;AA2D/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAwBI,2BAA2BL,oBAAoB7C,0BAA0BO,qDAAqDQ,sBAAsBA,+BAA+B8B,oBAAoB7C,mBAAmB6C,2BAA2BG,uBAAuBD,GAAGI,0BAA0BF,KAAK5C,mBAAmByC,iBAAiBC,aAAaD,iBAAiBC,0BAA0BxC,kBAAAA,CAAmB6C,OAAON,iBAAiBC,YAAYM,kBAAkBjB,2BAA2Be,qCAAqCL,iBAAiBC"}
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { Annotation } from "../graph/annotation.js";
|
|
2
|
+
import { END, START, Send } from "../constants.js";
|
|
3
|
+
import { StateGraph } from "../graph/state.js";
|
|
4
|
+
import { messagesStateReducer } from "../graph/message.js";
|
|
5
|
+
import "../graph/index.js";
|
|
6
|
+
import { ToolNode } from "./tool_node.js";
|
|
7
|
+
import { withAgentName } from "./agentName.js";
|
|
8
|
+
import { Runnable, RunnableBinding, RunnableLambda, RunnableSequence } from "@langchain/core/runnables";
|
|
9
|
+
import { SystemMessage, isAIMessage, isBaseMessage, isToolMessage } from "@langchain/core/messages";
|
|
10
|
+
|
|
11
|
+
//#region src/prebuilt/react_agent_executor.ts
|
|
12
|
+
function _convertMessageModifierToPrompt(messageModifier) {
|
|
13
|
+
if (typeof messageModifier === "string" || isBaseMessage(messageModifier) && messageModifier._getType() === "system") return messageModifier;
|
|
14
|
+
if (typeof messageModifier === "function") return async (state) => messageModifier(state.messages);
|
|
15
|
+
if (Runnable.isRunnable(messageModifier)) return RunnableLambda.from((state) => state.messages).pipe(messageModifier);
|
|
16
|
+
throw new Error(`Unexpected type for messageModifier: ${typeof messageModifier}`);
|
|
17
|
+
}
|
|
18
|
+
const PROMPT_RUNNABLE_NAME = "prompt";
|
|
19
|
+
function _getPromptRunnable(prompt) {
|
|
20
|
+
let promptRunnable;
|
|
21
|
+
if (prompt == null) promptRunnable = RunnableLambda.from((state) => state.messages).withConfig({ runName: PROMPT_RUNNABLE_NAME });
|
|
22
|
+
else if (typeof prompt === "string") {
|
|
23
|
+
const systemMessage = new SystemMessage(prompt);
|
|
24
|
+
promptRunnable = RunnableLambda.from((state) => {
|
|
25
|
+
return [systemMessage, ...state.messages ?? []];
|
|
26
|
+
}).withConfig({ runName: PROMPT_RUNNABLE_NAME });
|
|
27
|
+
} else if (isBaseMessage(prompt) && prompt._getType() === "system") promptRunnable = RunnableLambda.from((state) => [prompt, ...state.messages]).withConfig({ runName: PROMPT_RUNNABLE_NAME });
|
|
28
|
+
else if (typeof prompt === "function") promptRunnable = RunnableLambda.from(prompt).withConfig({ runName: PROMPT_RUNNABLE_NAME });
|
|
29
|
+
else if (Runnable.isRunnable(prompt)) promptRunnable = prompt;
|
|
30
|
+
else throw new Error(`Got unexpected type for 'prompt': ${typeof prompt}`);
|
|
31
|
+
return promptRunnable;
|
|
32
|
+
}
|
|
33
|
+
function isClientTool(tool) {
|
|
34
|
+
return Runnable.isRunnable(tool);
|
|
35
|
+
}
|
|
36
|
+
function _getPrompt(prompt, stateModifier, messageModifier) {
|
|
37
|
+
if ([
|
|
38
|
+
prompt,
|
|
39
|
+
stateModifier,
|
|
40
|
+
messageModifier
|
|
41
|
+
].filter((x) => x != null).length > 1) throw new Error("Expected only one of prompt, stateModifier, or messageModifier, got multiple values");
|
|
42
|
+
let finalPrompt = prompt;
|
|
43
|
+
if (stateModifier != null) finalPrompt = stateModifier;
|
|
44
|
+
else if (messageModifier != null) finalPrompt = _convertMessageModifierToPrompt(messageModifier);
|
|
45
|
+
return _getPromptRunnable(finalPrompt);
|
|
46
|
+
}
|
|
47
|
+
function _isBaseChatModel(model) {
|
|
48
|
+
return "invoke" in model && typeof model.invoke === "function" && "_modelType" in model;
|
|
49
|
+
}
|
|
50
|
+
function _isConfigurableModel(model) {
|
|
51
|
+
return "_queuedMethodOperations" in model && "_model" in model && typeof model._model === "function";
|
|
52
|
+
}
|
|
53
|
+
function _isChatModelWithBindTools(llm) {
|
|
54
|
+
if (!_isBaseChatModel(llm)) return false;
|
|
55
|
+
return "bindTools" in llm && typeof llm.bindTools === "function";
|
|
56
|
+
}
|
|
57
|
+
async function _shouldBindTools(llm, tools) {
|
|
58
|
+
let model = llm;
|
|
59
|
+
if (RunnableSequence.isRunnableSequence(model)) model = model.steps.find((step) => RunnableBinding.isRunnableBinding(step) || _isBaseChatModel(step) || _isConfigurableModel(step)) || model;
|
|
60
|
+
if (_isConfigurableModel(model)) model = await model._model();
|
|
61
|
+
if (!RunnableBinding.isRunnableBinding(model)) return true;
|
|
62
|
+
let boundTools = (() => {
|
|
63
|
+
if (model.kwargs != null && typeof model.kwargs === "object" && "tools" in model.kwargs && Array.isArray(model.kwargs.tools)) return model.kwargs.tools ?? null;
|
|
64
|
+
if (model.config != null && typeof model.config === "object" && "tools" in model.config && Array.isArray(model.config.tools)) return model.config.tools ?? null;
|
|
65
|
+
return null;
|
|
66
|
+
})();
|
|
67
|
+
if (boundTools != null && boundTools.length === 1 && "functionDeclarations" in boundTools[0]) boundTools = boundTools[0].functionDeclarations;
|
|
68
|
+
if (boundTools == null) return true;
|
|
69
|
+
if (tools.length !== boundTools.length) throw new Error("Number of tools in the model.bindTools() and tools passed to createReactAgent must match");
|
|
70
|
+
const toolNames = new Set(tools.flatMap((tool) => isClientTool(tool) ? tool.name : []));
|
|
71
|
+
const boundToolNames = /* @__PURE__ */ new Set();
|
|
72
|
+
for (const boundTool of boundTools) {
|
|
73
|
+
let boundToolName;
|
|
74
|
+
if ("type" in boundTool && boundTool.type === "function") boundToolName = boundTool.function.name;
|
|
75
|
+
else if ("name" in boundTool) boundToolName = boundTool.name;
|
|
76
|
+
else if ("toolSpec" in boundTool && "name" in boundTool.toolSpec) boundToolName = boundTool.toolSpec.name;
|
|
77
|
+
else continue;
|
|
78
|
+
if (boundToolName) boundToolNames.add(boundToolName);
|
|
79
|
+
}
|
|
80
|
+
const missingTools = [...toolNames].filter((x) => !boundToolNames.has(x));
|
|
81
|
+
if (missingTools.length > 0) throw new Error(`Missing tools '${missingTools}' in the model.bindTools().Tools in the model.bindTools() must match the tools passed to createReactAgent.`);
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
const _simpleBindTools = (llm, toolClasses) => {
|
|
85
|
+
if (_isChatModelWithBindTools(llm)) return llm.bindTools(toolClasses);
|
|
86
|
+
if (RunnableBinding.isRunnableBinding(llm) && _isChatModelWithBindTools(llm.bound)) {
|
|
87
|
+
const newBound = llm.bound.bindTools(toolClasses);
|
|
88
|
+
if (RunnableBinding.isRunnableBinding(newBound)) return new RunnableBinding({
|
|
89
|
+
bound: newBound.bound,
|
|
90
|
+
config: {
|
|
91
|
+
...llm.config,
|
|
92
|
+
...newBound.config
|
|
93
|
+
},
|
|
94
|
+
kwargs: {
|
|
95
|
+
...llm.kwargs,
|
|
96
|
+
...newBound.kwargs
|
|
97
|
+
},
|
|
98
|
+
configFactories: newBound.configFactories ?? llm.configFactories
|
|
99
|
+
});
|
|
100
|
+
return new RunnableBinding({
|
|
101
|
+
bound: newBound,
|
|
102
|
+
config: llm.config,
|
|
103
|
+
kwargs: llm.kwargs,
|
|
104
|
+
configFactories: llm.configFactories
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
};
|
|
109
|
+
async function _bindTools(llm, toolClasses) {
|
|
110
|
+
const model = _simpleBindTools(llm, toolClasses);
|
|
111
|
+
if (model) return model;
|
|
112
|
+
if (_isConfigurableModel(llm)) {
|
|
113
|
+
const model$1 = _simpleBindTools(await llm._model(), toolClasses);
|
|
114
|
+
if (model$1) return model$1;
|
|
115
|
+
}
|
|
116
|
+
if (RunnableSequence.isRunnableSequence(llm)) {
|
|
117
|
+
const modelStep = llm.steps.findIndex((step) => RunnableBinding.isRunnableBinding(step) || _isBaseChatModel(step) || _isConfigurableModel(step));
|
|
118
|
+
if (modelStep >= 0) {
|
|
119
|
+
const model$1 = _simpleBindTools(llm.steps[modelStep], toolClasses);
|
|
120
|
+
if (model$1) {
|
|
121
|
+
const nextSteps = llm.steps.slice();
|
|
122
|
+
nextSteps.splice(modelStep, 1, model$1);
|
|
123
|
+
return RunnableSequence.from(nextSteps);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
throw new Error(`llm ${llm} must define bindTools method.`);
|
|
128
|
+
}
|
|
129
|
+
async function _getModel(llm) {
|
|
130
|
+
let model = llm;
|
|
131
|
+
if (RunnableSequence.isRunnableSequence(model)) model = model.steps.find((step) => RunnableBinding.isRunnableBinding(step) || _isBaseChatModel(step) || _isConfigurableModel(step)) || model;
|
|
132
|
+
if (_isConfigurableModel(model)) model = await model._model();
|
|
133
|
+
if (RunnableBinding.isRunnableBinding(model)) model = model.bound;
|
|
134
|
+
if (!_isBaseChatModel(model)) throw new Error(`Expected \`llm\` to be a ChatModel or RunnableBinding (e.g. llm.bind_tools(...)) with invoke() and generate() methods, got ${model.constructor.name}`);
|
|
135
|
+
return model;
|
|
136
|
+
}
|
|
137
|
+
const createReactAgentAnnotation = () => Annotation.Root({
|
|
138
|
+
messages: Annotation({
|
|
139
|
+
reducer: messagesStateReducer,
|
|
140
|
+
default: () => []
|
|
141
|
+
}),
|
|
142
|
+
structuredResponse: Annotation
|
|
143
|
+
});
|
|
144
|
+
const PreHookAnnotation = Annotation.Root({ llmInputMessages: Annotation({
|
|
145
|
+
reducer: (_, update) => messagesStateReducer([], update),
|
|
146
|
+
default: () => []
|
|
147
|
+
}) });
|
|
148
|
+
/**
|
|
149
|
+
* @deprecated `createReactAgent` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.
|
|
150
|
+
* Update your import to `import { createAgent } from "langchain";`
|
|
151
|
+
*
|
|
152
|
+
* Creates a StateGraph agent that relies on a chat model utilizing tool calling.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* import { ChatOpenAI } from "@langchain/openai";
|
|
157
|
+
* import { tool } from "@langchain/core/tools";
|
|
158
|
+
* import { z } from "zod";
|
|
159
|
+
* import { createReactAgent } from "@langchain/langgraph/prebuilt";
|
|
160
|
+
*
|
|
161
|
+
* const model = new ChatOpenAI({
|
|
162
|
+
* model: "gpt-4o",
|
|
163
|
+
* });
|
|
164
|
+
*
|
|
165
|
+
* const getWeather = tool((input) => {
|
|
166
|
+
* if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
|
|
167
|
+
* return "It's 60 degrees and foggy.";
|
|
168
|
+
* } else {
|
|
169
|
+
* return "It's 90 degrees and sunny.";
|
|
170
|
+
* }
|
|
171
|
+
* }, {
|
|
172
|
+
* name: "get_weather",
|
|
173
|
+
* description: "Call to get the current weather.",
|
|
174
|
+
* schema: z.object({
|
|
175
|
+
* location: z.string().describe("Location to get the weather for."),
|
|
176
|
+
* })
|
|
177
|
+
* })
|
|
178
|
+
*
|
|
179
|
+
* const agent = createReactAgent({ llm: model, tools: [getWeather] });
|
|
180
|
+
*
|
|
181
|
+
* const inputs = {
|
|
182
|
+
* messages: [{ role: "user", content: "what is the weather in SF?" }],
|
|
183
|
+
* };
|
|
184
|
+
*
|
|
185
|
+
* const stream = await agent.stream(inputs, { streamMode: "values" });
|
|
186
|
+
*
|
|
187
|
+
* for await (const { messages } of stream) {
|
|
188
|
+
* console.log(messages);
|
|
189
|
+
* }
|
|
190
|
+
* // Returns the messages in the state at each step of execution
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
function createReactAgent(params) {
|
|
194
|
+
const { llm, tools, messageModifier, stateModifier, prompt, stateSchema, contextSchema, checkpointSaver, checkpointer, interruptBefore, interruptAfter, store, responseFormat, preModelHook, postModelHook, name, description, version = "v1", includeAgentName } = params;
|
|
195
|
+
let toolClasses;
|
|
196
|
+
let toolNode;
|
|
197
|
+
if (!Array.isArray(tools)) {
|
|
198
|
+
toolClasses = tools.tools;
|
|
199
|
+
toolNode = tools;
|
|
200
|
+
} else {
|
|
201
|
+
toolClasses = tools;
|
|
202
|
+
toolNode = new ToolNode(toolClasses.filter(isClientTool));
|
|
203
|
+
}
|
|
204
|
+
let cachedStaticModel = null;
|
|
205
|
+
const _getStaticModel = async (llm$1) => {
|
|
206
|
+
if (cachedStaticModel) return cachedStaticModel;
|
|
207
|
+
let modelWithTools;
|
|
208
|
+
if (await _shouldBindTools(llm$1, toolClasses)) modelWithTools = await _bindTools(llm$1, toolClasses);
|
|
209
|
+
else modelWithTools = llm$1;
|
|
210
|
+
const promptRunnable = _getPrompt(prompt, stateModifier, messageModifier);
|
|
211
|
+
const modelRunnable = includeAgentName === "inline" ? withAgentName(modelWithTools, includeAgentName) : modelWithTools;
|
|
212
|
+
cachedStaticModel = promptRunnable.pipe(modelRunnable);
|
|
213
|
+
return cachedStaticModel;
|
|
214
|
+
};
|
|
215
|
+
const _getDynamicModel = async (llm$1, state, config) => {
|
|
216
|
+
const model = await llm$1(state, config);
|
|
217
|
+
return _getPrompt(prompt, stateModifier, messageModifier).pipe(includeAgentName === "inline" ? withAgentName(model, includeAgentName) : model);
|
|
218
|
+
};
|
|
219
|
+
const shouldReturnDirect = new Set(toolClasses.filter(isClientTool).filter((tool) => "returnDirect" in tool && tool.returnDirect).map((tool) => tool.name));
|
|
220
|
+
function getModelInputState(state) {
|
|
221
|
+
const { messages, llmInputMessages, ...rest } = state;
|
|
222
|
+
if (llmInputMessages != null && llmInputMessages.length > 0) return {
|
|
223
|
+
messages: llmInputMessages,
|
|
224
|
+
...rest
|
|
225
|
+
};
|
|
226
|
+
return {
|
|
227
|
+
messages,
|
|
228
|
+
...rest
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
const generateStructuredResponse = async (state, config) => {
|
|
232
|
+
if (responseFormat == null) throw new Error("Attempted to generate structured output with no passed response schema. Please contact us for help.");
|
|
233
|
+
const messages = [...state.messages];
|
|
234
|
+
let modelWithStructuredOutput;
|
|
235
|
+
const model = typeof llm === "function" ? await llm(state, config) : await _getModel(llm);
|
|
236
|
+
if (!_isBaseChatModel(model)) throw new Error(`Expected \`llm\` to be a ChatModel with .withStructuredOutput() method, got ${model.constructor.name}`);
|
|
237
|
+
if (typeof responseFormat === "object" && "schema" in responseFormat) {
|
|
238
|
+
const { prompt: prompt$1, schema, ...options } = responseFormat;
|
|
239
|
+
modelWithStructuredOutput = model.withStructuredOutput(schema, options);
|
|
240
|
+
if (prompt$1 != null) messages.unshift(new SystemMessage({ content: prompt$1 }));
|
|
241
|
+
} else modelWithStructuredOutput = model.withStructuredOutput(responseFormat);
|
|
242
|
+
return { structuredResponse: await modelWithStructuredOutput.invoke(messages, config) };
|
|
243
|
+
};
|
|
244
|
+
const callModel = async (state, config) => {
|
|
245
|
+
const response = await (typeof llm === "function" ? await _getDynamicModel(llm, state, config) : await _getStaticModel(llm)).invoke(getModelInputState(state), config);
|
|
246
|
+
response.name = name;
|
|
247
|
+
response.lc_kwargs.name = name;
|
|
248
|
+
return { messages: [response] };
|
|
249
|
+
};
|
|
250
|
+
const workflow = new StateGraph(stateSchema ?? createReactAgentAnnotation(), contextSchema).addNode("tools", toolNode);
|
|
251
|
+
if (!("messages" in workflow._schemaDefinition)) throw new Error("Missing required `messages` key in state schema.");
|
|
252
|
+
const allNodeWorkflows = workflow;
|
|
253
|
+
const conditionalMap = (map) => {
|
|
254
|
+
return Object.fromEntries(Object.entries(map).filter(([_, v]) => v != null));
|
|
255
|
+
};
|
|
256
|
+
let entrypoint = "agent";
|
|
257
|
+
let inputSchema;
|
|
258
|
+
if (preModelHook != null) {
|
|
259
|
+
allNodeWorkflows.addNode("pre_model_hook", preModelHook).addEdge("pre_model_hook", "agent");
|
|
260
|
+
entrypoint = "pre_model_hook";
|
|
261
|
+
inputSchema = Annotation.Root({
|
|
262
|
+
...workflow._schemaDefinition,
|
|
263
|
+
...PreHookAnnotation.spec
|
|
264
|
+
});
|
|
265
|
+
} else entrypoint = "agent";
|
|
266
|
+
allNodeWorkflows.addNode("agent", callModel, { input: inputSchema }).addEdge(START, entrypoint);
|
|
267
|
+
if (postModelHook != null) allNodeWorkflows.addNode("post_model_hook", postModelHook).addEdge("agent", "post_model_hook").addConditionalEdges("post_model_hook", (state) => {
|
|
268
|
+
const { messages } = state;
|
|
269
|
+
const toolMessageIds = new Set(messages.filter(isToolMessage).map((msg) => msg.tool_call_id));
|
|
270
|
+
let lastAiMessage;
|
|
271
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
272
|
+
const message = messages[i];
|
|
273
|
+
if (isAIMessage(message)) {
|
|
274
|
+
lastAiMessage = message;
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const pendingToolCalls = lastAiMessage?.tool_calls?.filter((i) => i.id == null || !toolMessageIds.has(i.id)) ?? [];
|
|
279
|
+
const lastMessage = messages.at(-1);
|
|
280
|
+
if (pendingToolCalls.length > 0) {
|
|
281
|
+
if (version === "v2") return pendingToolCalls.map((toolCall) => new Send("tools", {
|
|
282
|
+
...state,
|
|
283
|
+
lg_tool_call: toolCall
|
|
284
|
+
}));
|
|
285
|
+
return "tools";
|
|
286
|
+
}
|
|
287
|
+
if (lastMessage && isToolMessage(lastMessage)) return entrypoint;
|
|
288
|
+
if (responseFormat != null) return "generate_structured_response";
|
|
289
|
+
return END;
|
|
290
|
+
}, conditionalMap({
|
|
291
|
+
tools: "tools",
|
|
292
|
+
[entrypoint]: entrypoint,
|
|
293
|
+
generate_structured_response: responseFormat != null ? "generate_structured_response" : null,
|
|
294
|
+
[END]: responseFormat != null ? null : END
|
|
295
|
+
}));
|
|
296
|
+
if (responseFormat !== void 0) workflow.addNode("generate_structured_response", generateStructuredResponse).addEdge("generate_structured_response", END);
|
|
297
|
+
if (postModelHook == null) allNodeWorkflows.addConditionalEdges("agent", (state) => {
|
|
298
|
+
const { messages } = state;
|
|
299
|
+
const lastMessage = messages[messages.length - 1];
|
|
300
|
+
if (!isAIMessage(lastMessage) || !lastMessage.tool_calls?.length) {
|
|
301
|
+
if (responseFormat != null) return "generate_structured_response";
|
|
302
|
+
return END;
|
|
303
|
+
}
|
|
304
|
+
if (version === "v2") return lastMessage.tool_calls.map((toolCall) => new Send("tools", {
|
|
305
|
+
...state,
|
|
306
|
+
lg_tool_call: toolCall
|
|
307
|
+
}));
|
|
308
|
+
return "tools";
|
|
309
|
+
}, conditionalMap({
|
|
310
|
+
tools: "tools",
|
|
311
|
+
generate_structured_response: responseFormat != null ? "generate_structured_response" : null,
|
|
312
|
+
[END]: responseFormat != null ? null : END
|
|
313
|
+
}));
|
|
314
|
+
if (shouldReturnDirect.size > 0) allNodeWorkflows.addConditionalEdges("tools", (state) => {
|
|
315
|
+
for (let i = state.messages.length - 1; i >= 0; i -= 1) {
|
|
316
|
+
const message = state.messages[i];
|
|
317
|
+
if (!isToolMessage(message)) break;
|
|
318
|
+
if (message.name !== void 0 && shouldReturnDirect.has(message.name)) return END;
|
|
319
|
+
}
|
|
320
|
+
return entrypoint;
|
|
321
|
+
}, conditionalMap({
|
|
322
|
+
[entrypoint]: entrypoint,
|
|
323
|
+
[END]: END
|
|
324
|
+
}));
|
|
325
|
+
else allNodeWorkflows.addEdge("tools", entrypoint);
|
|
326
|
+
return allNodeWorkflows.compile({
|
|
327
|
+
checkpointer: checkpointer ?? checkpointSaver,
|
|
328
|
+
interruptBefore,
|
|
329
|
+
interruptAfter,
|
|
330
|
+
store,
|
|
331
|
+
name,
|
|
332
|
+
description
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
//#endregion
|
|
337
|
+
export { createReactAgent, createReactAgentAnnotation };
|
|
338
|
+
//# sourceMappingURL=react_agent_executor.js.map
|