@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.
- package/dist/channels/any_value.cjs.map +1 -1
- package/dist/channels/any_value.d.cts +0 -1
- package/dist/channels/any_value.d.cts.map +1 -1
- package/dist/channels/any_value.d.ts +0 -1
- package/dist/channels/any_value.d.ts.map +1 -1
- package/dist/channels/any_value.js.map +1 -1
- package/dist/channels/base.cjs +2 -3
- package/dist/channels/base.cjs.map +1 -1
- package/dist/channels/base.d.cts.map +1 -1
- package/dist/channels/base.d.ts.map +1 -1
- package/dist/channels/base.js.map +1 -1
- package/dist/channels/binop.cjs.map +1 -1
- package/dist/channels/binop.d.cts.map +1 -1
- package/dist/channels/binop.d.ts.map +1 -1
- package/dist/channels/binop.js.map +1 -1
- package/dist/channels/dynamic_barrier_value.cjs +0 -1
- package/dist/channels/dynamic_barrier_value.cjs.map +1 -1
- package/dist/channels/dynamic_barrier_value.d.cts +1 -3
- package/dist/channels/dynamic_barrier_value.d.cts.map +1 -1
- package/dist/channels/dynamic_barrier_value.d.ts +1 -3
- package/dist/channels/dynamic_barrier_value.d.ts.map +1 -1
- package/dist/channels/dynamic_barrier_value.js +0 -1
- package/dist/channels/dynamic_barrier_value.js.map +1 -1
- package/dist/channels/ephemeral_value.cjs.map +1 -1
- package/dist/channels/ephemeral_value.d.cts +0 -1
- package/dist/channels/ephemeral_value.d.cts.map +1 -1
- package/dist/channels/ephemeral_value.d.ts +0 -1
- package/dist/channels/ephemeral_value.d.ts.map +1 -1
- package/dist/channels/ephemeral_value.js.map +1 -1
- package/dist/channels/last_value.cjs.map +1 -1
- package/dist/channels/last_value.d.cts +0 -2
- package/dist/channels/last_value.d.cts.map +1 -1
- package/dist/channels/last_value.d.ts +0 -2
- package/dist/channels/last_value.d.ts.map +1 -1
- package/dist/channels/last_value.js.map +1 -1
- package/dist/channels/named_barrier_value.cjs +0 -2
- package/dist/channels/named_barrier_value.cjs.map +1 -1
- package/dist/channels/named_barrier_value.d.cts +2 -4
- package/dist/channels/named_barrier_value.d.cts.map +1 -1
- package/dist/channels/named_barrier_value.d.ts +2 -4
- package/dist/channels/named_barrier_value.d.ts.map +1 -1
- package/dist/channels/named_barrier_value.js +0 -2
- package/dist/channels/named_barrier_value.js.map +1 -1
- package/dist/channels/topic.cjs.map +1 -1
- package/dist/channels/topic.d.cts.map +1 -1
- package/dist/channels/topic.d.ts.map +1 -1
- package/dist/channels/topic.js.map +1 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +2 -6
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.ts +2 -6
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +0 -4
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.ts +0 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/func/index.cjs +2 -4
- package/dist/func/index.cjs.map +1 -1
- package/dist/func/index.d.cts +1 -6
- package/dist/func/index.d.cts.map +1 -1
- package/dist/func/index.d.ts +1 -6
- package/dist/func/index.d.ts.map +1 -1
- package/dist/func/index.js +1 -2
- package/dist/func/index.js.map +1 -1
- package/dist/func/types.d.cts +2 -4
- package/dist/func/types.d.cts.map +1 -1
- package/dist/func/types.d.ts +2 -4
- package/dist/func/types.d.ts.map +1 -1
- package/dist/graph/annotation.cjs.map +1 -1
- package/dist/graph/annotation.d.cts.map +1 -1
- package/dist/graph/annotation.d.ts.map +1 -1
- package/dist/graph/annotation.js.map +1 -1
- package/dist/graph/graph.cjs +15 -18
- package/dist/graph/graph.cjs.map +1 -1
- package/dist/graph/graph.d.cts +4 -28
- package/dist/graph/graph.d.cts.map +1 -1
- package/dist/graph/graph.d.ts +4 -28
- package/dist/graph/graph.d.ts.map +1 -1
- package/dist/graph/graph.js +4 -6
- package/dist/graph/graph.js.map +1 -1
- package/dist/graph/message.cjs +8 -10
- package/dist/graph/message.cjs.map +1 -1
- package/dist/graph/message.d.cts +2 -2
- package/dist/graph/message.d.cts.map +1 -1
- package/dist/graph/message.d.ts +2 -2
- package/dist/graph/message.d.ts.map +1 -1
- package/dist/graph/message.js +3 -4
- package/dist/graph/message.js.map +1 -1
- package/dist/graph/messages_annotation.cjs +1 -2
- package/dist/graph/messages_annotation.cjs.map +1 -1
- package/dist/graph/messages_annotation.d.cts +5 -5
- package/dist/graph/messages_annotation.d.cts.map +1 -1
- package/dist/graph/messages_annotation.d.ts +5 -5
- package/dist/graph/messages_annotation.d.ts.map +1 -1
- package/dist/graph/messages_annotation.js.map +1 -1
- package/dist/graph/state.cjs +23 -30
- package/dist/graph/state.cjs.map +1 -1
- package/dist/graph/state.d.cts +2 -9
- package/dist/graph/state.d.cts.map +1 -1
- package/dist/graph/state.d.ts +2 -9
- package/dist/graph/state.d.ts.map +1 -1
- package/dist/graph/state.js +6 -12
- package/dist/graph/state.js.map +1 -1
- package/dist/graph/zod/meta.cjs +8 -9
- package/dist/graph/zod/meta.cjs.map +1 -1
- package/dist/graph/zod/meta.d.cts +0 -1
- package/dist/graph/zod/meta.d.cts.map +1 -1
- package/dist/graph/zod/meta.d.ts +0 -1
- package/dist/graph/zod/meta.d.ts.map +1 -1
- package/dist/graph/zod/meta.js.map +1 -1
- package/dist/graph/zod/plugin.cjs +4 -6
- package/dist/graph/zod/plugin.cjs.map +1 -1
- package/dist/graph/zod/plugin.js +1 -2
- package/dist/graph/zod/plugin.js.map +1 -1
- package/dist/graph/zod/schema.cjs +2 -3
- package/dist/graph/zod/schema.cjs.map +1 -1
- package/dist/graph/zod/schema.d.cts.map +1 -1
- package/dist/graph/zod/schema.d.ts.map +1 -1
- package/dist/graph/zod/schema.js.map +1 -1
- package/dist/graph/zod/zod-registry.cjs +3 -4
- package/dist/graph/zod/zod-registry.cjs.map +1 -1
- package/dist/graph/zod/zod-registry.d.cts +0 -2
- package/dist/graph/zod/zod-registry.d.cts.map +1 -1
- package/dist/graph/zod/zod-registry.d.ts +0 -2
- package/dist/graph/zod/zod-registry.d.ts.map +1 -1
- package/dist/graph/zod/zod-registry.js.map +1 -1
- package/dist/hash.cjs +4 -10
- package/dist/hash.cjs.map +1 -1
- package/dist/hash.js +4 -10
- package/dist/hash.js.map +1 -1
- package/dist/index.cjs +8 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interrupt.cjs +4 -7
- package/dist/interrupt.cjs.map +1 -1
- package/dist/interrupt.d.cts +1 -4
- package/dist/interrupt.d.cts.map +1 -1
- package/dist/interrupt.d.ts +1 -4
- package/dist/interrupt.d.ts.map +1 -1
- package/dist/interrupt.js +2 -4
- package/dist/interrupt.js.map +1 -1
- package/dist/prebuilt/agentName.cjs +14 -19
- package/dist/prebuilt/agentName.cjs.map +1 -1
- package/dist/prebuilt/agentName.js +6 -10
- package/dist/prebuilt/agentName.js.map +1 -1
- package/dist/prebuilt/agent_executor.cjs +4 -7
- package/dist/prebuilt/agent_executor.cjs.map +1 -1
- package/dist/prebuilt/agent_executor.d.cts +5 -5
- package/dist/prebuilt/agent_executor.d.cts.map +1 -1
- package/dist/prebuilt/agent_executor.d.ts +5 -5
- package/dist/prebuilt/agent_executor.d.ts.map +1 -1
- package/dist/prebuilt/agent_executor.js +4 -7
- package/dist/prebuilt/agent_executor.js.map +1 -1
- package/dist/prebuilt/chat_agent_executor.cjs +11 -17
- package/dist/prebuilt/chat_agent_executor.cjs.map +1 -1
- package/dist/prebuilt/chat_agent_executor.d.cts.map +1 -1
- package/dist/prebuilt/chat_agent_executor.d.ts.map +1 -1
- package/dist/prebuilt/chat_agent_executor.js +7 -12
- package/dist/prebuilt/chat_agent_executor.js.map +1 -1
- package/dist/prebuilt/interrupt.d.cts +0 -1
- package/dist/prebuilt/interrupt.d.cts.map +1 -1
- package/dist/prebuilt/interrupt.d.ts +0 -1
- package/dist/prebuilt/interrupt.d.ts.map +1 -1
- package/dist/prebuilt/react_agent_executor.cjs +35 -40
- package/dist/prebuilt/react_agent_executor.cjs.map +1 -1
- package/dist/prebuilt/react_agent_executor.d.cts +8 -27
- package/dist/prebuilt/react_agent_executor.d.cts.map +1 -1
- package/dist/prebuilt/react_agent_executor.d.ts +8 -27
- package/dist/prebuilt/react_agent_executor.d.ts.map +1 -1
- package/dist/prebuilt/react_agent_executor.js +8 -12
- package/dist/prebuilt/react_agent_executor.js.map +1 -1
- package/dist/prebuilt/tool_executor.cjs +4 -9
- package/dist/prebuilt/tool_executor.cjs.map +1 -1
- package/dist/prebuilt/tool_executor.d.cts +0 -2
- package/dist/prebuilt/tool_executor.d.cts.map +1 -1
- package/dist/prebuilt/tool_executor.d.ts +0 -2
- package/dist/prebuilt/tool_executor.d.ts.map +1 -1
- package/dist/prebuilt/tool_executor.js +1 -5
- package/dist/prebuilt/tool_executor.js.map +1 -1
- package/dist/prebuilt/tool_node.cjs +7 -8
- package/dist/prebuilt/tool_node.cjs.map +1 -1
- package/dist/prebuilt/tool_node.d.cts +0 -2
- package/dist/prebuilt/tool_node.d.cts.map +1 -1
- package/dist/prebuilt/tool_node.d.ts +0 -2
- package/dist/prebuilt/tool_node.d.ts.map +1 -1
- package/dist/prebuilt/tool_node.js.map +1 -1
- package/dist/pregel/algo.cjs +33 -41
- package/dist/pregel/algo.cjs.map +1 -1
- package/dist/pregel/algo.d.cts.map +1 -1
- package/dist/pregel/algo.d.ts.map +1 -1
- package/dist/pregel/algo.js +22 -29
- package/dist/pregel/algo.js.map +1 -1
- package/dist/pregel/call.cjs +11 -14
- package/dist/pregel/call.cjs.map +1 -1
- package/dist/pregel/call.js +7 -9
- package/dist/pregel/call.js.map +1 -1
- package/dist/pregel/debug.cjs +6 -9
- package/dist/pregel/debug.cjs.map +1 -1
- package/dist/pregel/debug.js +6 -9
- package/dist/pregel/debug.js.map +1 -1
- package/dist/pregel/index.cjs +28 -35
- package/dist/pregel/index.cjs.map +1 -1
- package/dist/pregel/index.d.cts +6 -54
- package/dist/pregel/index.d.cts.map +1 -1
- package/dist/pregel/index.d.ts +6 -54
- package/dist/pregel/index.d.ts.map +1 -1
- package/dist/pregel/index.js +10 -16
- package/dist/pregel/index.js.map +1 -1
- package/dist/pregel/io.cjs.map +1 -1
- package/dist/pregel/io.js.map +1 -1
- package/dist/pregel/loop.cjs +9 -12
- package/dist/pregel/loop.cjs.map +1 -1
- package/dist/pregel/loop.js +2 -4
- package/dist/pregel/loop.js.map +1 -1
- package/dist/pregel/messages.cjs +13 -14
- package/dist/pregel/messages.cjs.map +1 -1
- package/dist/pregel/messages.js.map +1 -1
- package/dist/pregel/read.cjs +7 -8
- package/dist/pregel/read.cjs.map +1 -1
- package/dist/pregel/read.d.cts +0 -6
- package/dist/pregel/read.d.cts.map +1 -1
- package/dist/pregel/read.d.ts +0 -6
- package/dist/pregel/read.d.ts.map +1 -1
- package/dist/pregel/read.js +1 -1
- package/dist/pregel/read.js.map +1 -1
- package/dist/pregel/remote.cjs +24 -32
- package/dist/pregel/remote.cjs.map +1 -1
- package/dist/pregel/remote.d.cts +1 -6
- package/dist/pregel/remote.d.cts.map +1 -1
- package/dist/pregel/remote.d.ts +1 -6
- package/dist/pregel/remote.d.ts.map +1 -1
- package/dist/pregel/remote.js +12 -19
- package/dist/pregel/remote.js.map +1 -1
- package/dist/pregel/retry.cjs +1 -2
- package/dist/pregel/retry.cjs.map +1 -1
- package/dist/pregel/retry.js +1 -2
- package/dist/pregel/retry.js.map +1 -1
- package/dist/pregel/runnable_types.d.cts +2 -8
- package/dist/pregel/runnable_types.d.cts.map +1 -1
- package/dist/pregel/runnable_types.d.ts +2 -8
- package/dist/pregel/runnable_types.d.ts.map +1 -1
- package/dist/pregel/runner.cjs +1 -1
- package/dist/pregel/runner.cjs.map +1 -1
- package/dist/pregel/runner.js +1 -1
- package/dist/pregel/runner.js.map +1 -1
- package/dist/pregel/stream.cjs +4 -6
- package/dist/pregel/stream.cjs.map +1 -1
- package/dist/pregel/stream.js +1 -2
- package/dist/pregel/stream.js.map +1 -1
- package/dist/pregel/types.d.cts +5 -18
- package/dist/pregel/types.d.cts.map +1 -1
- package/dist/pregel/types.d.ts +5 -18
- package/dist/pregel/types.d.ts.map +1 -1
- package/dist/pregel/utils/config.cjs +6 -7
- package/dist/pregel/utils/config.cjs.map +1 -1
- package/dist/pregel/utils/config.d.cts.map +1 -1
- package/dist/pregel/utils/config.d.ts.map +1 -1
- package/dist/pregel/utils/config.js.map +1 -1
- package/dist/pregel/utils/index.cjs +1 -2
- package/dist/pregel/utils/index.cjs.map +1 -1
- package/dist/pregel/utils/index.d.cts +1 -1
- package/dist/pregel/utils/index.d.cts.map +1 -1
- package/dist/pregel/utils/index.d.ts +1 -1
- package/dist/pregel/utils/index.d.ts.map +1 -1
- package/dist/pregel/utils/index.js +1 -2
- package/dist/pregel/utils/index.js.map +1 -1
- package/dist/pregel/utils/subgraph.cjs +0 -1
- package/dist/pregel/utils/subgraph.cjs.map +1 -1
- package/dist/pregel/utils/subgraph.js +0 -1
- package/dist/pregel/utils/subgraph.js.map +1 -1
- package/dist/pregel/validate.cjs.map +1 -1
- package/dist/pregel/validate.js.map +1 -1
- package/dist/pregel/write.cjs +2 -3
- package/dist/pregel/write.cjs.map +1 -1
- package/dist/pregel/write.d.cts +1 -5
- package/dist/pregel/write.d.cts.map +1 -1
- package/dist/pregel/write.d.ts +1 -5
- package/dist/pregel/write.d.ts.map +1 -1
- package/dist/pregel/write.js.map +1 -1
- package/dist/setup/async_local_storage.cjs +3 -4
- package/dist/setup/async_local_storage.cjs.map +1 -1
- package/dist/setup/async_local_storage.js.map +1 -1
- package/dist/utils.cjs +9 -11
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +1 -8
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.ts +1 -8
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -2
- package/dist/utils.js.map +1 -1
- package/dist/web.cjs +8 -9
- package/dist/writer.cjs +2 -3
- package/dist/writer.cjs.map +1 -1
- package/dist/writer.d.cts +1 -2
- package/dist/writer.d.cts.map +1 -1
- package/dist/writer.d.ts +1 -2
- package/dist/writer.d.ts.map +1 -1
- package/dist/writer.js.map +1 -1
- package/package.json +7 -7
- package/CHANGELOG.md +0 -286
- package/dist/_virtual/rolldown_runtime.cjs +0 -25
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interrupt.d.ts","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
|
|
1
|
+
{"version":3,"file":"interrupt.d.ts","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"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
1
|
const require_annotation = require('../graph/annotation.cjs');
|
|
3
2
|
const require_constants = require('../constants.cjs');
|
|
4
3
|
const require_state = require('../graph/state.cjs');
|
|
@@ -6,41 +5,40 @@ const require_message = require('../graph/message.cjs');
|
|
|
6
5
|
require('../graph/index.cjs');
|
|
7
6
|
const require_tool_node = require('./tool_node.cjs');
|
|
8
7
|
const require_agentName = require('./agentName.cjs');
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
let _langchain_core_runnables = require("@langchain/core/runnables");
|
|
9
|
+
let _langchain_core_messages = require("@langchain/core/messages");
|
|
11
10
|
|
|
12
11
|
//#region src/prebuilt/react_agent_executor.ts
|
|
13
12
|
function _convertMessageModifierToPrompt(messageModifier) {
|
|
14
|
-
if (typeof messageModifier === "string" || (0,
|
|
13
|
+
if (typeof messageModifier === "string" || (0, _langchain_core_messages.isBaseMessage)(messageModifier) && messageModifier._getType() === "system") return messageModifier;
|
|
15
14
|
if (typeof messageModifier === "function") return async (state) => messageModifier(state.messages);
|
|
16
|
-
if (
|
|
15
|
+
if (_langchain_core_runnables.Runnable.isRunnable(messageModifier)) return _langchain_core_runnables.RunnableLambda.from((state) => state.messages).pipe(messageModifier);
|
|
17
16
|
throw new Error(`Unexpected type for messageModifier: ${typeof messageModifier}`);
|
|
18
17
|
}
|
|
19
18
|
const PROMPT_RUNNABLE_NAME = "prompt";
|
|
20
19
|
function _getPromptRunnable(prompt) {
|
|
21
20
|
let promptRunnable;
|
|
22
|
-
if (prompt == null) promptRunnable =
|
|
21
|
+
if (prompt == null) promptRunnable = _langchain_core_runnables.RunnableLambda.from((state) => state.messages).withConfig({ runName: PROMPT_RUNNABLE_NAME });
|
|
23
22
|
else if (typeof prompt === "string") {
|
|
24
|
-
const systemMessage = new
|
|
25
|
-
promptRunnable =
|
|
23
|
+
const systemMessage = new _langchain_core_messages.SystemMessage(prompt);
|
|
24
|
+
promptRunnable = _langchain_core_runnables.RunnableLambda.from((state) => {
|
|
26
25
|
return [systemMessage, ...state.messages ?? []];
|
|
27
26
|
}).withConfig({ runName: PROMPT_RUNNABLE_NAME });
|
|
28
|
-
} else if ((0,
|
|
29
|
-
else if (typeof prompt === "function") promptRunnable =
|
|
30
|
-
else if (
|
|
27
|
+
} else if ((0, _langchain_core_messages.isBaseMessage)(prompt) && prompt._getType() === "system") promptRunnable = _langchain_core_runnables.RunnableLambda.from((state) => [prompt, ...state.messages]).withConfig({ runName: PROMPT_RUNNABLE_NAME });
|
|
28
|
+
else if (typeof prompt === "function") promptRunnable = _langchain_core_runnables.RunnableLambda.from(prompt).withConfig({ runName: PROMPT_RUNNABLE_NAME });
|
|
29
|
+
else if (_langchain_core_runnables.Runnable.isRunnable(prompt)) promptRunnable = prompt;
|
|
31
30
|
else throw new Error(`Got unexpected type for 'prompt': ${typeof prompt}`);
|
|
32
31
|
return promptRunnable;
|
|
33
32
|
}
|
|
34
33
|
function isClientTool(tool) {
|
|
35
|
-
return
|
|
34
|
+
return _langchain_core_runnables.Runnable.isRunnable(tool);
|
|
36
35
|
}
|
|
37
36
|
function _getPrompt(prompt, stateModifier, messageModifier) {
|
|
38
|
-
|
|
37
|
+
if ([
|
|
39
38
|
prompt,
|
|
40
39
|
stateModifier,
|
|
41
40
|
messageModifier
|
|
42
|
-
].filter((x) => x != null).length;
|
|
43
|
-
if (definedCount > 1) throw new Error("Expected only one of prompt, stateModifier, or messageModifier, got multiple values");
|
|
41
|
+
].filter((x) => x != null).length > 1) throw new Error("Expected only one of prompt, stateModifier, or messageModifier, got multiple values");
|
|
44
42
|
let finalPrompt = prompt;
|
|
45
43
|
if (stateModifier != null) finalPrompt = stateModifier;
|
|
46
44
|
else if (messageModifier != null) finalPrompt = _convertMessageModifierToPrompt(messageModifier);
|
|
@@ -58,9 +56,9 @@ function _isChatModelWithBindTools(llm) {
|
|
|
58
56
|
}
|
|
59
57
|
async function _shouldBindTools(llm, tools) {
|
|
60
58
|
let model = llm;
|
|
61
|
-
if (
|
|
59
|
+
if (_langchain_core_runnables.RunnableSequence.isRunnableSequence(model)) model = model.steps.find((step) => _langchain_core_runnables.RunnableBinding.isRunnableBinding(step) || _isBaseChatModel(step) || _isConfigurableModel(step)) || model;
|
|
62
60
|
if (_isConfigurableModel(model)) model = await model._model();
|
|
63
|
-
if (!
|
|
61
|
+
if (!_langchain_core_runnables.RunnableBinding.isRunnableBinding(model)) return true;
|
|
64
62
|
let boundTools = (() => {
|
|
65
63
|
if (model.kwargs != null && typeof model.kwargs === "object" && "tools" in model.kwargs && Array.isArray(model.kwargs.tools)) return model.kwargs.tools ?? null;
|
|
66
64
|
if (model.config != null && typeof model.config === "object" && "tools" in model.config && Array.isArray(model.config.tools)) return model.config.tools ?? null;
|
|
@@ -85,9 +83,9 @@ async function _shouldBindTools(llm, tools) {
|
|
|
85
83
|
}
|
|
86
84
|
const _simpleBindTools = (llm, toolClasses) => {
|
|
87
85
|
if (_isChatModelWithBindTools(llm)) return llm.bindTools(toolClasses);
|
|
88
|
-
if (
|
|
86
|
+
if (_langchain_core_runnables.RunnableBinding.isRunnableBinding(llm) && _isChatModelWithBindTools(llm.bound)) {
|
|
89
87
|
const newBound = llm.bound.bindTools(toolClasses);
|
|
90
|
-
if (
|
|
88
|
+
if (_langchain_core_runnables.RunnableBinding.isRunnableBinding(newBound)) return new _langchain_core_runnables.RunnableBinding({
|
|
91
89
|
bound: newBound.bound,
|
|
92
90
|
config: {
|
|
93
91
|
...llm.config,
|
|
@@ -99,7 +97,7 @@ const _simpleBindTools = (llm, toolClasses) => {
|
|
|
99
97
|
},
|
|
100
98
|
configFactories: newBound.configFactories ?? llm.configFactories
|
|
101
99
|
});
|
|
102
|
-
return new
|
|
100
|
+
return new _langchain_core_runnables.RunnableBinding({
|
|
103
101
|
bound: newBound,
|
|
104
102
|
config: llm.config,
|
|
105
103
|
kwargs: llm.kwargs,
|
|
@@ -115,14 +113,14 @@ async function _bindTools(llm, toolClasses) {
|
|
|
115
113
|
const model$1 = _simpleBindTools(await llm._model(), toolClasses);
|
|
116
114
|
if (model$1) return model$1;
|
|
117
115
|
}
|
|
118
|
-
if (
|
|
119
|
-
const modelStep = llm.steps.findIndex((step) =>
|
|
116
|
+
if (_langchain_core_runnables.RunnableSequence.isRunnableSequence(llm)) {
|
|
117
|
+
const modelStep = llm.steps.findIndex((step) => _langchain_core_runnables.RunnableBinding.isRunnableBinding(step) || _isBaseChatModel(step) || _isConfigurableModel(step));
|
|
120
118
|
if (modelStep >= 0) {
|
|
121
119
|
const model$1 = _simpleBindTools(llm.steps[modelStep], toolClasses);
|
|
122
120
|
if (model$1) {
|
|
123
121
|
const nextSteps = llm.steps.slice();
|
|
124
122
|
nextSteps.splice(modelStep, 1, model$1);
|
|
125
|
-
return
|
|
123
|
+
return _langchain_core_runnables.RunnableSequence.from(nextSteps);
|
|
126
124
|
}
|
|
127
125
|
}
|
|
128
126
|
}
|
|
@@ -130,9 +128,9 @@ async function _bindTools(llm, toolClasses) {
|
|
|
130
128
|
}
|
|
131
129
|
async function _getModel(llm) {
|
|
132
130
|
let model = llm;
|
|
133
|
-
if (
|
|
131
|
+
if (_langchain_core_runnables.RunnableSequence.isRunnableSequence(model)) model = model.steps.find((step) => _langchain_core_runnables.RunnableBinding.isRunnableBinding(step) || _isBaseChatModel(step) || _isConfigurableModel(step)) || model;
|
|
134
132
|
if (_isConfigurableModel(model)) model = await model._model();
|
|
135
|
-
if (
|
|
133
|
+
if (_langchain_core_runnables.RunnableBinding.isRunnableBinding(model)) model = model.bound;
|
|
136
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}`);
|
|
137
135
|
return model;
|
|
138
136
|
}
|
|
@@ -220,7 +218,7 @@ function createReactAgent(params) {
|
|
|
220
218
|
};
|
|
221
219
|
const shouldReturnDirect = new Set(toolClasses.filter(isClientTool).filter((tool) => "returnDirect" in tool && tool.returnDirect).map((tool) => tool.name));
|
|
222
220
|
function getModelInputState(state) {
|
|
223
|
-
const { messages, llmInputMessages
|
|
221
|
+
const { messages, llmInputMessages, ...rest } = state;
|
|
224
222
|
if (llmInputMessages != null && llmInputMessages.length > 0) return {
|
|
225
223
|
messages: llmInputMessages,
|
|
226
224
|
...rest
|
|
@@ -237,22 +235,19 @@ function createReactAgent(params) {
|
|
|
237
235
|
const model = typeof llm === "function" ? await llm(state, config) : await _getModel(llm);
|
|
238
236
|
if (!_isBaseChatModel(model)) throw new Error(`Expected \`llm\` to be a ChatModel with .withStructuredOutput() method, got ${model.constructor.name}`);
|
|
239
237
|
if (typeof responseFormat === "object" && "schema" in responseFormat) {
|
|
240
|
-
const { prompt: prompt$1, schema
|
|
241
|
-
modelWithStructuredOutput = model.withStructuredOutput(schema
|
|
242
|
-
if (prompt$1 != null) messages.unshift(new
|
|
238
|
+
const { prompt: prompt$1, schema, ...options } = responseFormat;
|
|
239
|
+
modelWithStructuredOutput = model.withStructuredOutput(schema, options);
|
|
240
|
+
if (prompt$1 != null) messages.unshift(new _langchain_core_messages.SystemMessage({ content: prompt$1 }));
|
|
243
241
|
} else modelWithStructuredOutput = model.withStructuredOutput(responseFormat);
|
|
244
|
-
|
|
245
|
-
return { structuredResponse: response };
|
|
242
|
+
return { structuredResponse: await modelWithStructuredOutput.invoke(messages, config) };
|
|
246
243
|
};
|
|
247
244
|
const callModel = async (state, config) => {
|
|
248
|
-
const
|
|
249
|
-
const response = await modelRunnable.invoke(getModelInputState(state), config);
|
|
245
|
+
const response = await (typeof llm === "function" ? await _getDynamicModel(llm, state, config) : await _getStaticModel(llm)).invoke(getModelInputState(state), config);
|
|
250
246
|
response.name = name;
|
|
251
247
|
response.lc_kwargs.name = name;
|
|
252
248
|
return { messages: [response] };
|
|
253
249
|
};
|
|
254
|
-
const
|
|
255
|
-
const workflow = new require_state.StateGraph(schema, contextSchema).addNode("tools", toolNode);
|
|
250
|
+
const workflow = new require_state.StateGraph(stateSchema ?? createReactAgentAnnotation(), contextSchema).addNode("tools", toolNode);
|
|
256
251
|
if (!("messages" in workflow._schemaDefinition)) throw new Error("Missing required `messages` key in state schema.");
|
|
257
252
|
const allNodeWorkflows = workflow;
|
|
258
253
|
const conditionalMap = (map) => {
|
|
@@ -271,11 +266,11 @@ function createReactAgent(params) {
|
|
|
271
266
|
allNodeWorkflows.addNode("agent", callModel, { input: inputSchema }).addEdge(require_constants.START, entrypoint);
|
|
272
267
|
if (postModelHook != null) allNodeWorkflows.addNode("post_model_hook", postModelHook).addEdge("agent", "post_model_hook").addConditionalEdges("post_model_hook", (state) => {
|
|
273
268
|
const { messages } = state;
|
|
274
|
-
const toolMessageIds = new Set(messages.filter(
|
|
269
|
+
const toolMessageIds = new Set(messages.filter(_langchain_core_messages.isToolMessage).map((msg) => msg.tool_call_id));
|
|
275
270
|
let lastAiMessage;
|
|
276
271
|
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
277
272
|
const message = messages[i];
|
|
278
|
-
if ((0,
|
|
273
|
+
if ((0, _langchain_core_messages.isAIMessage)(message)) {
|
|
279
274
|
lastAiMessage = message;
|
|
280
275
|
break;
|
|
281
276
|
}
|
|
@@ -289,7 +284,7 @@ function createReactAgent(params) {
|
|
|
289
284
|
}));
|
|
290
285
|
return "tools";
|
|
291
286
|
}
|
|
292
|
-
if (lastMessage && (0,
|
|
287
|
+
if (lastMessage && (0, _langchain_core_messages.isToolMessage)(lastMessage)) return entrypoint;
|
|
293
288
|
if (responseFormat != null) return "generate_structured_response";
|
|
294
289
|
return require_constants.END;
|
|
295
290
|
}, conditionalMap({
|
|
@@ -302,7 +297,7 @@ function createReactAgent(params) {
|
|
|
302
297
|
if (postModelHook == null) allNodeWorkflows.addConditionalEdges("agent", (state) => {
|
|
303
298
|
const { messages } = state;
|
|
304
299
|
const lastMessage = messages[messages.length - 1];
|
|
305
|
-
if (!(0,
|
|
300
|
+
if (!(0, _langchain_core_messages.isAIMessage)(lastMessage) || !lastMessage.tool_calls?.length) {
|
|
306
301
|
if (responseFormat != null) return "generate_structured_response";
|
|
307
302
|
return require_constants.END;
|
|
308
303
|
}
|
|
@@ -319,7 +314,7 @@ function createReactAgent(params) {
|
|
|
319
314
|
if (shouldReturnDirect.size > 0) allNodeWorkflows.addConditionalEdges("tools", (state) => {
|
|
320
315
|
for (let i = state.messages.length - 1; i >= 0; i -= 1) {
|
|
321
316
|
const message = state.messages[i];
|
|
322
|
-
if (!(0,
|
|
317
|
+
if (!(0, _langchain_core_messages.isToolMessage)(message)) break;
|
|
323
318
|
if (message.name !== void 0 && shouldReturnDirect.has(message.name)) return require_constants.END;
|
|
324
319
|
}
|
|
325
320
|
return entrypoint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react_agent_executor.cjs","names":["Runnable","RunnableLambda","promptRunnable: Runnable","SystemMessage","RunnableSequence","RunnableBinding","boundToolName: string | undefined","model","nextSteps: unknown[]","Annotation","messagesStateReducer","toolClasses: (ClientTool | ServerTool)[]","toolNode: ToolNode","ToolNode","cachedStaticModel: Runnable | null","modelWithTools: LanguageModelLike","llm","withAgentName","model: LanguageModelLike","schema","prompt","modelRunnable: Runnable","StateGraph","entrypoint: \"agent\" | \"pre_model_hook\"","inputSchema: AnnotationRoot<ToAnnotationRoot<A>[\"spec\"]> | undefined","START","toolMessageIds: Set<string>","isToolMessage","lastAiMessage: AIMessage | undefined","Send","END"],"sources":["../../src/prebuilt/react_agent_executor.ts"],"sourcesContent":["import {\n BaseChatModel,\n BindToolsInput,\n} from \"@langchain/core/language_models/chat_models\";\nimport { LanguageModelLike } from \"@langchain/core/language_models/base\";\nimport {\n BaseMessage,\n BaseMessageLike,\n isAIMessage,\n isBaseMessage,\n isToolMessage,\n SystemMessage,\n type AIMessage,\n} from \"@langchain/core/messages\";\nimport {\n Runnable,\n RunnableLambda,\n RunnableToolLike,\n RunnableSequence,\n RunnableBinding,\n type RunnableLike,\n} from \"@langchain/core/runnables\";\nimport { DynamicTool, StructuredToolInterface } from \"@langchain/core/tools\";\nimport type {\n InteropZodObject,\n InteropZodType,\n} from \"@langchain/core/utils/types\";\nimport {\n All,\n BaseCheckpointSaver,\n BaseStore,\n} from \"@langchain/langgraph-checkpoint\";\n\nimport {\n StateGraph,\n type CompiledStateGraph,\n AnnotationRoot,\n} from \"../graph/index.js\";\nimport { MessagesAnnotation } from \"../graph/messages_annotation.js\";\nimport { ToolNode } from \"./tool_node.js\";\nimport { LangGraphRunnableConfig, Runtime } from \"../pregel/runnable_types.js\";\nimport { Annotation } from \"../graph/annotation.js\";\nimport { Messages, messagesStateReducer } from \"../graph/message.js\";\nimport { END, Send, START } from \"../constants.js\";\nimport { withAgentName } from \"./agentName.js\";\nimport type { InteropZodToStateDefinition } from \"../graph/zod/meta.js\";\n\n/**\n * @deprecated `AgentState` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.\n * Update your import to `import { AgentState } from \"langchain\";`\n */\nexport interface AgentState<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n StructuredResponseType extends Record<string, any> = Record<string, any>\n> {\n messages: BaseMessage[];\n // TODO: This won't be set until we\n // implement managed values in LangGraphJS\n // Will be useful for inserting a message on\n // graph recursion end\n // is_last_step: boolean;\n structuredResponse: StructuredResponseType;\n}\n\nexport type N = typeof START | \"agent\" | \"tools\";\n\ntype StructuredResponseSchemaOptions<StructuredResponseType> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: InteropZodType<StructuredResponseType> | Record<string, any>;\n prompt?: string;\n\n strict?: boolean;\n [key: string]: unknown;\n};\n\nfunction _convertMessageModifierToPrompt(\n messageModifier: MessageModifier\n): Prompt {\n // Handle string or SystemMessage\n if (\n typeof messageModifier === \"string\" ||\n (isBaseMessage(messageModifier) && messageModifier._getType() === \"system\")\n ) {\n return messageModifier;\n }\n\n // Handle callable function\n if (typeof messageModifier === \"function\") {\n return async (state: typeof MessagesAnnotation.State) =>\n messageModifier(state.messages);\n }\n\n // Handle Runnable\n if (Runnable.isRunnable(messageModifier)) {\n return RunnableLambda.from(\n (state: typeof MessagesAnnotation.State) => state.messages\n ).pipe(messageModifier);\n }\n\n throw new Error(\n `Unexpected type for messageModifier: ${typeof messageModifier}`\n );\n}\n\nconst PROMPT_RUNNABLE_NAME = \"prompt\";\n\nfunction _getPromptRunnable(prompt?: Prompt): Runnable {\n let promptRunnable: Runnable;\n\n if (prompt == null) {\n promptRunnable = RunnableLambda.from(\n (state: typeof MessagesAnnotation.State) => state.messages\n ).withConfig({ runName: PROMPT_RUNNABLE_NAME });\n } else if (typeof prompt === \"string\") {\n const systemMessage = new SystemMessage(prompt);\n promptRunnable = RunnableLambda.from(\n (state: typeof MessagesAnnotation.State) => {\n return [systemMessage, ...(state.messages ?? [])];\n }\n ).withConfig({ runName: PROMPT_RUNNABLE_NAME });\n } else if (isBaseMessage(prompt) && prompt._getType() === \"system\") {\n promptRunnable = RunnableLambda.from(\n (state: typeof MessagesAnnotation.State) => [prompt, ...state.messages]\n ).withConfig({ runName: PROMPT_RUNNABLE_NAME });\n } else if (typeof prompt === \"function\") {\n promptRunnable = RunnableLambda.from(prompt).withConfig({\n runName: PROMPT_RUNNABLE_NAME,\n });\n } else if (Runnable.isRunnable(prompt)) {\n promptRunnable = prompt;\n } else {\n throw new Error(`Got unexpected type for 'prompt': ${typeof prompt}`);\n }\n\n return promptRunnable;\n}\n\ntype ServerTool = Record<string, unknown>;\ntype ClientTool = StructuredToolInterface | DynamicTool | RunnableToolLike;\n\nfunction isClientTool(tool: ClientTool | ServerTool): tool is ClientTool {\n return Runnable.isRunnable(tool);\n}\n\nfunction _getPrompt(\n prompt?: Prompt,\n stateModifier?: CreateReactAgentParams[\"stateModifier\"],\n messageModifier?: CreateReactAgentParams[\"messageModifier\"]\n): Runnable {\n // Check if multiple modifiers exist\n const definedCount = [prompt, stateModifier, messageModifier].filter(\n (x) => x != null\n ).length;\n if (definedCount > 1) {\n throw new Error(\n \"Expected only one of prompt, stateModifier, or messageModifier, got multiple values\"\n );\n }\n\n let finalPrompt = prompt;\n if (stateModifier != null) {\n finalPrompt = stateModifier;\n } else if (messageModifier != null) {\n finalPrompt = _convertMessageModifierToPrompt(messageModifier);\n }\n\n return _getPromptRunnable(finalPrompt);\n}\n\nfunction _isBaseChatModel(model: LanguageModelLike): model is BaseChatModel {\n return (\n \"invoke\" in model &&\n typeof model.invoke === \"function\" &&\n \"_modelType\" in model\n );\n}\n\ninterface ConfigurableModelInterface {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _queuedMethodOperations: Record<string, any>;\n _model: () => Promise<BaseChatModel>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction _isConfigurableModel(model: any): model is ConfigurableModelInterface {\n return (\n \"_queuedMethodOperations\" in model &&\n \"_model\" in model &&\n typeof model._model === \"function\"\n );\n}\n\nfunction _isChatModelWithBindTools(\n llm: LanguageModelLike\n): llm is BaseChatModel & Required<Pick<BaseChatModel, \"bindTools\">> {\n if (!_isBaseChatModel(llm)) return false;\n return \"bindTools\" in llm && typeof llm.bindTools === \"function\";\n}\n\nexport async function _shouldBindTools(\n llm: LanguageModelLike,\n tools: (ClientTool | ServerTool)[]\n): Promise<boolean> {\n // If model is a RunnableSequence, find a RunnableBinding or BaseChatModel in its steps\n let model = llm;\n if (RunnableSequence.isRunnableSequence(model)) {\n model =\n model.steps.find(\n (step) =>\n RunnableBinding.isRunnableBinding(step) ||\n _isBaseChatModel(step) ||\n _isConfigurableModel(step)\n ) || model;\n }\n\n if (_isConfigurableModel(model)) {\n model = await model._model();\n }\n\n // If not a RunnableBinding, we should bind tools\n if (!RunnableBinding.isRunnableBinding(model)) {\n return true;\n }\n\n let boundTools = (() => {\n // check if model.kwargs contain the tools key\n if (\n model.kwargs != null &&\n typeof model.kwargs === \"object\" &&\n \"tools\" in model.kwargs &&\n Array.isArray(model.kwargs.tools)\n ) {\n return (model.kwargs.tools ?? null) as BindToolsInput[] | null;\n }\n\n // Some models can bind the tools via `withConfig()` instead of `bind()`\n if (\n model.config != null &&\n typeof model.config === \"object\" &&\n \"tools\" in model.config &&\n Array.isArray(model.config.tools)\n ) {\n return (model.config.tools ?? null) as BindToolsInput[] | null;\n }\n\n return null;\n })();\n\n // google-style\n if (\n boundTools != null &&\n boundTools.length === 1 &&\n \"functionDeclarations\" in boundTools[0]\n ) {\n boundTools = boundTools[0].functionDeclarations;\n }\n\n // If no tools in kwargs, we should bind tools\n if (boundTools == null) return true;\n\n // Check if tools count matches\n if (tools.length !== boundTools.length) {\n throw new Error(\n \"Number of tools in the model.bindTools() and tools passed to createReactAgent must match\"\n );\n }\n\n const toolNames = new Set<string>(\n tools.flatMap((tool) => (isClientTool(tool) ? tool.name : []))\n );\n\n const boundToolNames = new Set<string>();\n\n for (const boundTool of boundTools) {\n let boundToolName: string | undefined;\n\n // OpenAI-style tool\n if (\"type\" in boundTool && boundTool.type === \"function\") {\n boundToolName = boundTool.function.name;\n }\n // Anthropic or Google-style tool\n else if (\"name\" in boundTool) {\n boundToolName = boundTool.name;\n }\n // Bedrock-style tool\n else if (\"toolSpec\" in boundTool && \"name\" in boundTool.toolSpec) {\n boundToolName = boundTool.toolSpec.name;\n }\n // unknown tool type so we'll ignore it\n else {\n continue;\n }\n\n if (boundToolName) {\n boundToolNames.add(boundToolName);\n }\n }\n\n const missingTools = [...toolNames].filter((x) => !boundToolNames.has(x));\n if (missingTools.length > 0) {\n throw new Error(\n `Missing tools '${missingTools}' in the model.bindTools().` +\n `Tools in the model.bindTools() must match the tools passed to createReactAgent.`\n );\n }\n\n return false;\n}\n\nconst _simpleBindTools = (\n llm: LanguageModelLike,\n toolClasses: (ClientTool | ServerTool)[]\n) => {\n if (_isChatModelWithBindTools(llm)) {\n return llm.bindTools(toolClasses);\n }\n\n if (\n RunnableBinding.isRunnableBinding(llm) &&\n _isChatModelWithBindTools(llm.bound)\n ) {\n const newBound = llm.bound.bindTools(toolClasses);\n\n if (RunnableBinding.isRunnableBinding(newBound)) {\n return new RunnableBinding({\n bound: newBound.bound,\n config: { ...llm.config, ...newBound.config },\n kwargs: { ...llm.kwargs, ...newBound.kwargs },\n configFactories: newBound.configFactories ?? llm.configFactories,\n });\n }\n\n return new RunnableBinding({\n bound: newBound,\n config: llm.config,\n kwargs: llm.kwargs,\n configFactories: llm.configFactories,\n });\n }\n\n return null;\n};\n\nexport async function _bindTools(\n llm: LanguageModelLike,\n toolClasses: (ClientTool | ServerTool)[]\n) {\n const model = _simpleBindTools(llm, toolClasses);\n if (model) return model;\n\n if (_isConfigurableModel(llm)) {\n const model = _simpleBindTools(await llm._model(), toolClasses);\n if (model) return model;\n }\n\n if (RunnableSequence.isRunnableSequence(llm)) {\n const modelStep = llm.steps.findIndex(\n (step) =>\n RunnableBinding.isRunnableBinding(step) ||\n _isBaseChatModel(step) ||\n _isConfigurableModel(step)\n );\n\n if (modelStep >= 0) {\n const model = _simpleBindTools(llm.steps[modelStep], toolClasses);\n if (model) {\n const nextSteps: unknown[] = llm.steps.slice();\n nextSteps.splice(modelStep, 1, model);\n\n return RunnableSequence.from(\n nextSteps as [RunnableLike, ...RunnableLike[], RunnableLike]\n );\n }\n }\n }\n\n throw new Error(`llm ${llm} must define bindTools method.`);\n}\n\nexport async function _getModel(\n llm: LanguageModelLike | ConfigurableModelInterface\n): Promise<LanguageModelLike> {\n // If model is a RunnableSequence, find a RunnableBinding or BaseChatModel in its steps\n let model = llm;\n if (RunnableSequence.isRunnableSequence(model)) {\n model =\n model.steps.find(\n (step) =>\n RunnableBinding.isRunnableBinding(step) ||\n _isBaseChatModel(step) ||\n _isConfigurableModel(step)\n ) || model;\n }\n\n if (_isConfigurableModel(model)) {\n model = await model._model();\n }\n\n // Get the underlying model from a RunnableBinding\n if (RunnableBinding.isRunnableBinding(model)) {\n model = model.bound;\n }\n\n if (!_isBaseChatModel(model)) {\n throw new Error(\n `Expected \\`llm\\` to be a ChatModel or RunnableBinding (e.g. llm.bind_tools(...)) with invoke() and generate() methods, got ${model.constructor.name}`\n );\n }\n\n return model;\n}\n\nexport type Prompt =\n | SystemMessage\n | string\n | ((\n state: typeof MessagesAnnotation.State,\n config: LangGraphRunnableConfig\n ) => BaseMessageLike[])\n | ((\n state: typeof MessagesAnnotation.State,\n config: LangGraphRunnableConfig\n ) => Promise<BaseMessageLike[]>)\n | Runnable;\n\n/** @deprecated Use Prompt instead. */\nexport type StateModifier = Prompt;\n\n/** @deprecated Use Prompt instead. */\nexport type MessageModifier =\n | SystemMessage\n | string\n | ((messages: BaseMessage[]) => BaseMessage[])\n | ((messages: BaseMessage[]) => Promise<BaseMessage[]>)\n | Runnable;\n\nexport const createReactAgentAnnotation = <\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>\n>() =>\n Annotation.Root({\n messages: Annotation<BaseMessage[], Messages>({\n reducer: messagesStateReducer,\n default: () => [],\n }),\n structuredResponse: Annotation<T>,\n });\n\ntype WithStateGraphNodes<K extends string, Graph> = Graph extends StateGraph<\n infer SD,\n infer S,\n infer U,\n infer N,\n infer I,\n infer O,\n infer C\n>\n ? StateGraph<SD, S, U, N | K, I, O, C>\n : never;\n\nconst PreHookAnnotation = Annotation.Root({\n llmInputMessages: Annotation<BaseMessage[], Messages>({\n reducer: (_, update) => messagesStateReducer([], update),\n default: () => [],\n }),\n});\n\ntype PreHookAnnotation = typeof PreHookAnnotation;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyAnnotationRoot = AnnotationRoot<any>;\n\ntype ToAnnotationRoot<A extends AnyAnnotationRoot | InteropZodObject> =\n A extends AnyAnnotationRoot\n ? A\n : A extends InteropZodObject\n ? AnnotationRoot<InteropZodToStateDefinition<A>>\n : never;\n\n/**\n * @deprecated `CreateReactAgentParams` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.\n * Update your import to `import { CreateAgentParams } from \"langchain\";`\n */\nexport type CreateReactAgentParams<\n A extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n StructuredResponseType extends Record<string, any> = Record<string, any>,\n C extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n> = {\n /** The chat model that can utilize OpenAI-style tool calling. */\n llm:\n | LanguageModelLike\n | ((\n state: ToAnnotationRoot<A>[\"State\"] & PreHookAnnotation[\"State\"],\n runtime: Runtime<ToAnnotationRoot<C>[\"State\"]>\n ) => Promise<LanguageModelLike> | LanguageModelLike);\n\n /** A list of tools or a ToolNode. */\n tools: ToolNode | (ServerTool | ClientTool)[];\n\n /**\n * @deprecated Use prompt instead.\n */\n messageModifier?: MessageModifier;\n\n /**\n * @deprecated Use prompt instead.\n */\n stateModifier?: StateModifier;\n\n /**\n * An optional prompt for the LLM. This takes full graph state BEFORE the LLM is called and prepares the input to LLM.\n *\n * Can take a few different forms:\n *\n * - str: This is converted to a SystemMessage and added to the beginning of the list of messages in state[\"messages\"].\n * - SystemMessage: this is added to the beginning of the list of messages in state[\"messages\"].\n * - Function: This function should take in full graph state and the output is then passed to the language model.\n * - Runnable: This runnable should take in full graph state and the output is then passed to the language model.\n *\n * Note:\n * Prior to `v0.2.46`, the prompt was set using `stateModifier` / `messagesModifier` parameters.\n * This is now deprecated and will be removed in a future release.\n */\n prompt?: Prompt;\n\n /**\n * Additional state schema for the agent.\n */\n stateSchema?: A;\n\n /**\n * An optional schema for the context.\n */\n contextSchema?: C;\n /** An optional checkpoint saver to persist the agent's state. */\n checkpointSaver?: BaseCheckpointSaver | boolean;\n /** An optional checkpoint saver to persist the agent's state. Alias of \"checkpointSaver\". */\n checkpointer?: BaseCheckpointSaver | boolean;\n /** An optional list of node names to interrupt before running. */\n interruptBefore?: N[] | All;\n /** An optional list of node names to interrupt after running. */\n interruptAfter?: N[] | All;\n store?: BaseStore;\n /**\n * An optional schema for the final agent output.\n *\n * If provided, output will be formatted to match the given schema and returned in the 'structuredResponse' state key.\n * If not provided, `structuredResponse` will not be present in the output state.\n *\n * Can be passed in as:\n * - Zod schema\n * - JSON schema\n * - { prompt, schema }, where schema is one of the above.\n * The prompt will be used together with the model that is being used to generate the structured response.\n *\n * @remarks\n * **Important**: `responseFormat` requires the model to support `.withStructuredOutput()`.\n *\n * **Note**: The graph will make a separate call to the LLM to generate the structured response after the agent loop is finished.\n * This is not the only strategy to get structured responses, see more options in [this guide](https://langchain-ai.github.io/langgraph/how-tos/react-agent-structured-output/).\n */\n responseFormat?:\n | InteropZodType<StructuredResponseType>\n | StructuredResponseSchemaOptions<StructuredResponseType>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>;\n\n /**\n * An optional name for the agent.\n */\n name?: string;\n\n /**\n * An optional description for the agent.\n * This can be used to describe the agent to the underlying supervisor LLM.\n */\n description?: string | undefined;\n\n /**\n * Use to specify how to expose the agent name to the underlying supervisor LLM.\n\n - undefined: Relies on the LLM provider {@link AIMessage#name}. Currently, only OpenAI supports this.\n - `\"inline\"`: Add the agent name directly into the content field of the {@link AIMessage} using XML-style tags.\n Example: `\"How can I help you\"` -> `\"<name>agent_name</name><content>How can I help you?</content>\"`\n */\n includeAgentName?: \"inline\" | undefined;\n\n /**\n * An optional node to add before the `agent` node (i.e., the node that calls the LLM).\n * Useful for managing long message histories (e.g., message trimming, summarization, etc.).\n */\n preModelHook?: RunnableLike<\n ToAnnotationRoot<A>[\"State\"] & PreHookAnnotation[\"State\"],\n ToAnnotationRoot<A>[\"Update\"] & PreHookAnnotation[\"Update\"],\n LangGraphRunnableConfig\n >;\n\n /**\n * An optional node to add after the `agent` node (i.e., the node that calls the LLM).\n * Useful for implementing human-in-the-loop, guardrails, validation, or other post-processing.\n */\n postModelHook?: RunnableLike<\n ToAnnotationRoot<A>[\"State\"],\n ToAnnotationRoot<A>[\"Update\"],\n LangGraphRunnableConfig\n >;\n\n /**\n * Determines the version of the graph to create.\n *\n * Can be one of\n * - `\"v1\"`: The tool node processes a single message. All tool calls in the message are\n * executed in parallel within the tool node.\n * - `\"v2\"`: The tool node processes a single tool call. Tool calls are distributed across\n * multiple instances of the tool node using the Send API.\n *\n * @default `\"v1\"`\n */\n version?: \"v1\" | \"v2\";\n};\n\n/**\n * @deprecated `createReactAgent` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.\n * Update your import to `import { createAgent } from \"langchain\";`\n *\n * Creates a StateGraph agent that relies on a chat model utilizing tool calling.\n *\n * @example\n * ```ts\n * import { ChatOpenAI } from \"@langchain/openai\";\n * import { tool } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n * import { createReactAgent } from \"@langchain/langgraph/prebuilt\";\n *\n * const model = new ChatOpenAI({\n * model: \"gpt-4o\",\n * });\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * })\n * })\n *\n * const agent = createReactAgent({ llm: model, tools: [getWeather] });\n *\n * const inputs = {\n * messages: [{ role: \"user\", content: \"what is the weather in SF?\" }],\n * };\n *\n * const stream = await agent.stream(inputs, { streamMode: \"values\" });\n *\n * for await (const { messages } of stream) {\n * console.log(messages);\n * }\n * // Returns the messages in the state at each step of execution\n * ```\n */\nexport function createReactAgent<\n A extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n C extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateReactAgentParams<A, StructuredResponseFormat, C>\n): CompiledStateGraph<\n ToAnnotationRoot<A>[\"State\"],\n ToAnnotationRoot<A>[\"Update\"],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any,\n typeof MessagesAnnotation.spec & ToAnnotationRoot<A>[\"spec\"],\n ReturnType<\n typeof createReactAgentAnnotation<StructuredResponseFormat>\n >[\"spec\"] &\n ToAnnotationRoot<A>[\"spec\"]\n> {\n const {\n llm,\n tools,\n messageModifier,\n stateModifier,\n prompt,\n stateSchema,\n contextSchema,\n checkpointSaver,\n checkpointer,\n interruptBefore,\n interruptAfter,\n store,\n responseFormat,\n preModelHook,\n postModelHook,\n name,\n description,\n version = \"v1\",\n includeAgentName,\n } = params;\n\n let toolClasses: (ClientTool | ServerTool)[];\n\n let toolNode: ToolNode;\n if (!Array.isArray(tools)) {\n toolClasses = tools.tools;\n toolNode = tools;\n } else {\n toolClasses = tools;\n toolNode = new ToolNode(toolClasses.filter(isClientTool));\n }\n\n let cachedStaticModel: Runnable | null = null;\n\n const _getStaticModel = async (llm: LanguageModelLike): Promise<Runnable> => {\n if (cachedStaticModel) return cachedStaticModel;\n\n let modelWithTools: LanguageModelLike;\n if (await _shouldBindTools(llm, toolClasses)) {\n modelWithTools = await _bindTools(llm, toolClasses);\n } else {\n modelWithTools = llm;\n }\n\n const promptRunnable = _getPrompt(prompt, stateModifier, messageModifier);\n const modelRunnable =\n includeAgentName === \"inline\"\n ? withAgentName(modelWithTools, includeAgentName)\n : modelWithTools;\n\n cachedStaticModel = promptRunnable.pipe(modelRunnable);\n return cachedStaticModel;\n };\n\n const _getDynamicModel = async (\n llm: (\n state: AgentState<StructuredResponseFormat> & PreHookAnnotation[\"State\"],\n runtime: Runtime<ToAnnotationRoot<C>[\"State\"]>\n ) => Promise<LanguageModelLike> | LanguageModelLike,\n state: AgentState<StructuredResponseFormat> & PreHookAnnotation[\"State\"],\n config: Runtime<ToAnnotationRoot<C>[\"State\"]>\n ) => {\n const model = await llm(state, config);\n\n return _getPrompt(prompt, stateModifier, messageModifier).pipe(\n includeAgentName === \"inline\"\n ? withAgentName(model, includeAgentName)\n : model\n );\n };\n\n // If any of the tools are configured to return_directly after running,\n // our graph needs to check if these were called\n const shouldReturnDirect = new Set(\n toolClasses\n .filter(isClientTool)\n .filter((tool) => \"returnDirect\" in tool && tool.returnDirect)\n .map((tool) => tool.name)\n );\n\n function getModelInputState(\n state: AgentState<StructuredResponseFormat> & PreHookAnnotation[\"State\"]\n ): Omit<AgentState<StructuredResponseFormat>, \"llmInputMessages\"> {\n const { messages, llmInputMessages, ...rest } = state;\n if (llmInputMessages != null && llmInputMessages.length > 0) {\n return { messages: llmInputMessages, ...rest };\n }\n return { messages, ...rest };\n }\n\n const generateStructuredResponse = async (\n state: AgentState<StructuredResponseFormat> & PreHookAnnotation[\"State\"],\n config: Runtime<ToAnnotationRoot<C>[\"State\"]>\n ) => {\n if (responseFormat == null) {\n throw new Error(\n \"Attempted to generate structured output with no passed response schema. Please contact us for help.\"\n );\n }\n const messages = [...state.messages];\n let modelWithStructuredOutput;\n\n const model: LanguageModelLike =\n typeof llm === \"function\"\n ? await llm(state, config)\n : await _getModel(llm);\n\n if (!_isBaseChatModel(model)) {\n throw new Error(\n `Expected \\`llm\\` to be a ChatModel with .withStructuredOutput() method, got ${model.constructor.name}`\n );\n }\n\n if (typeof responseFormat === \"object\" && \"schema\" in responseFormat) {\n const { prompt, schema, ...options } =\n responseFormat as StructuredResponseSchemaOptions<StructuredResponseFormat>;\n\n modelWithStructuredOutput = model.withStructuredOutput(schema, options);\n if (prompt != null) {\n messages.unshift(new SystemMessage({ content: prompt }));\n }\n } else {\n modelWithStructuredOutput = model.withStructuredOutput(responseFormat);\n }\n\n const response = await modelWithStructuredOutput.invoke(messages, config);\n return { structuredResponse: response };\n };\n\n const callModel = async (\n state: AgentState<StructuredResponseFormat> & PreHookAnnotation[\"State\"],\n config: Runtime<ToAnnotationRoot<C>[\"State\"]>\n ) => {\n // NOTE: we're dynamically creating the model runnable here\n // to ensure that we can validate ConfigurableModel properly\n const modelRunnable: Runnable =\n typeof llm === \"function\"\n ? await _getDynamicModel(llm, state, config)\n : await _getStaticModel(llm);\n\n // TODO: Auto-promote streaming.\n const response = (await modelRunnable.invoke(\n getModelInputState(state),\n config\n )) as BaseMessage;\n // add agent name to the AIMessage\n // TODO: figure out if we can avoid mutating the message directly\n response.name = name;\n response.lc_kwargs.name = name;\n return { messages: [response] };\n };\n\n const schema =\n stateSchema ?? createReactAgentAnnotation<StructuredResponseFormat>();\n\n const workflow = new StateGraph(\n schema as AnyAnnotationRoot,\n contextSchema\n ).addNode(\"tools\", toolNode);\n\n if (!(\"messages\" in workflow._schemaDefinition)) {\n throw new Error(\"Missing required `messages` key in state schema.\");\n }\n\n const allNodeWorkflows = workflow as WithStateGraphNodes<\n | \"pre_model_hook\"\n | \"post_model_hook\"\n | \"generate_structured_response\"\n | \"agent\",\n typeof workflow\n >;\n\n const conditionalMap = <T extends string>(map: Record<string, T | null>) => {\n return Object.fromEntries(\n Object.entries(map).filter(([_, v]) => v != null) as [string, T][]\n );\n };\n\n let entrypoint: \"agent\" | \"pre_model_hook\" = \"agent\";\n let inputSchema: AnnotationRoot<ToAnnotationRoot<A>[\"spec\"]> | undefined;\n if (preModelHook != null) {\n allNodeWorkflows\n .addNode(\"pre_model_hook\", preModelHook)\n .addEdge(\"pre_model_hook\", \"agent\");\n entrypoint = \"pre_model_hook\";\n\n inputSchema = Annotation.Root({\n ...workflow._schemaDefinition,\n ...PreHookAnnotation.spec,\n });\n } else {\n entrypoint = \"agent\";\n }\n\n allNodeWorkflows\n .addNode(\"agent\", callModel, { input: inputSchema })\n .addEdge(START, entrypoint);\n\n if (postModelHook != null) {\n allNodeWorkflows\n .addNode(\"post_model_hook\", postModelHook)\n .addEdge(\"agent\", \"post_model_hook\")\n .addConditionalEdges(\n \"post_model_hook\",\n (state: AgentState<StructuredResponseFormat>) => {\n const { messages } = state;\n\n const toolMessageIds: Set<string> = new Set(\n messages.filter(isToolMessage).map((msg) => msg.tool_call_id)\n );\n\n let lastAiMessage: AIMessage | undefined;\n for (let i = messages.length - 1; i >= 0; i -= 1) {\n const message = messages[i];\n if (isAIMessage(message)) {\n lastAiMessage = message;\n break;\n }\n }\n\n const pendingToolCalls =\n lastAiMessage?.tool_calls?.filter(\n (i) => i.id == null || !toolMessageIds.has(i.id)\n ) ?? [];\n\n const lastMessage = messages.at(-1);\n if (pendingToolCalls.length > 0) {\n if (version === \"v2\") {\n return pendingToolCalls.map(\n (toolCall) =>\n new Send(\"tools\", { ...state, lg_tool_call: toolCall })\n );\n }\n return \"tools\";\n }\n\n if (lastMessage && isToolMessage(lastMessage)) return entrypoint;\n if (responseFormat != null) return \"generate_structured_response\";\n return END;\n },\n conditionalMap({\n tools: \"tools\",\n [entrypoint]: entrypoint,\n generate_structured_response:\n responseFormat != null ? \"generate_structured_response\" : null,\n [END]: responseFormat != null ? null : END,\n })\n );\n }\n\n if (responseFormat !== undefined) {\n workflow\n .addNode(\"generate_structured_response\", generateStructuredResponse)\n .addEdge(\"generate_structured_response\", END);\n }\n\n if (postModelHook == null) {\n allNodeWorkflows.addConditionalEdges(\n \"agent\",\n (state: AgentState<StructuredResponseFormat>) => {\n const { messages } = state;\n const lastMessage = messages[messages.length - 1];\n\n // if there's no function call, we finish\n if (!isAIMessage(lastMessage) || !lastMessage.tool_calls?.length) {\n if (responseFormat != null) return \"generate_structured_response\";\n return END;\n }\n\n // there are function calls, we continue\n if (version === \"v2\") {\n return lastMessage.tool_calls.map(\n (toolCall) =>\n new Send(\"tools\", { ...state, lg_tool_call: toolCall })\n );\n }\n\n return \"tools\";\n },\n conditionalMap({\n tools: \"tools\",\n generate_structured_response:\n responseFormat != null ? \"generate_structured_response\" : null,\n [END]: responseFormat != null ? null : END,\n })\n );\n }\n\n if (shouldReturnDirect.size > 0) {\n allNodeWorkflows.addConditionalEdges(\n \"tools\",\n (state: AgentState<StructuredResponseFormat>) => {\n // Check the last consecutive tool calls\n for (let i = state.messages.length - 1; i >= 0; i -= 1) {\n const message = state.messages[i];\n if (!isToolMessage(message)) break;\n\n // Check if this tool is configured to return directly\n if (\n message.name !== undefined &&\n shouldReturnDirect.has(message.name)\n ) {\n return END;\n }\n }\n\n return entrypoint;\n },\n conditionalMap({ [entrypoint]: entrypoint, [END]: END })\n );\n } else {\n allNodeWorkflows.addEdge(\"tools\", entrypoint);\n }\n\n return allNodeWorkflows.compile({\n checkpointer: checkpointer ?? checkpointSaver,\n interruptBefore,\n interruptAfter,\n store,\n name,\n description,\n });\n}\n"],"mappings":";;;;;;;;;;;;AA2EA,SAAS,gCACP,iBACQ;AAER,KACE,OAAO,oBAAoB,yDACZ,oBAAoB,gBAAgB,eAAe,SA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BACE,kBAAkB,OAAO,iCAAiC;GAC3DA,wBAAM,kBAAkB,OAAO,OAAOA;;AAK/C,KAAI,mBAAmB,OACrB,UACG,QAAQ,gCAAgC,4BACxC,QAAQ,gCAAgCA;AAG7C,KAAI,iBAAiB,KACnB,kBAAiB,oBACf,UACC,UAAgD;EAC/C,MAAM,EAAE,aAAa;EACrB,MAAM,cAAc,SAAS,SAAS,SAAS;AAG/C,MAAI,4CAAa,gBAAgB,CAAC,YAAY,YAAY,QAAQ;AAChE,OAAI,kBAAkB,KAAM,QAAO;AACnC,UAAOA;;AAIT,MAAI,YAAY,KACd,QAAO,YAAY,WAAW,KAC3B,aACC,IAAID,uBAAK,SAAS;GAAE,GAAG;GAAO,cAAc;;AAIlD,SAAO;IAET,eAAe;EACb,OAAO;EACP,8BACE,kBAAkB,OAAO,iCAAiC;GAC3DC,wBAAM,kBAAkB,OAAO,OAAOA;;AAK7C,KAAI,mBAAmB,OAAO,EAC5B,kBAAiB,oBACf,UACC,UAAgD;AAE/C,OAAK,IAAI,IAAI,MAAM,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG;GACtD,MAAM,UAAU,MAAM,SAAS;AAC/B,OAAI,8CAAe,SAAU;AAG7B,OACE,QAAQ,SAAS,UACjB,mBAAmB,IAAI,QAAQ,MAE/B,QAAOA;;AAIX,SAAO;IAET,eAAe;GAAG,aAAa;GAAaA,wBAAMA;;KAGpD,kBAAiB,QAAQ,SAAS;AAGpC,QAAO,iBAAiB,QAAQ;EAC9B,cAAc,gBAAgB;EAC9B;EACA;EACA;EACA;EACA"}
|
|
1
|
+
{"version":3,"file":"react_agent_executor.cjs","names":["Runnable","RunnableLambda","SystemMessage","RunnableSequence","RunnableBinding","model","Annotation","messagesStateReducer","ToolNode","llm","withAgentName","prompt","StateGraph","START","isToolMessage","Send","END"],"sources":["../../src/prebuilt/react_agent_executor.ts"],"sourcesContent":["import {\n BaseChatModel,\n BindToolsInput,\n} from \"@langchain/core/language_models/chat_models\";\nimport { LanguageModelLike } from \"@langchain/core/language_models/base\";\nimport {\n BaseMessage,\n BaseMessageLike,\n isAIMessage,\n isBaseMessage,\n isToolMessage,\n SystemMessage,\n type AIMessage,\n} from \"@langchain/core/messages\";\nimport {\n Runnable,\n RunnableLambda,\n RunnableToolLike,\n RunnableSequence,\n RunnableBinding,\n type RunnableLike,\n} from \"@langchain/core/runnables\";\nimport { DynamicTool, StructuredToolInterface } from \"@langchain/core/tools\";\nimport type {\n InteropZodObject,\n InteropZodType,\n} from \"@langchain/core/utils/types\";\nimport {\n All,\n BaseCheckpointSaver,\n BaseStore,\n} from \"@langchain/langgraph-checkpoint\";\n\nimport {\n StateGraph,\n type CompiledStateGraph,\n AnnotationRoot,\n} from \"../graph/index.js\";\nimport { MessagesAnnotation } from \"../graph/messages_annotation.js\";\nimport { ToolNode } from \"./tool_node.js\";\nimport { LangGraphRunnableConfig, Runtime } from \"../pregel/runnable_types.js\";\nimport { Annotation } from \"../graph/annotation.js\";\nimport { Messages, messagesStateReducer } from \"../graph/message.js\";\nimport { END, Send, START } from \"../constants.js\";\nimport { withAgentName } from \"./agentName.js\";\nimport type { InteropZodToStateDefinition } from \"../graph/zod/meta.js\";\n\n/**\n * @deprecated `AgentState` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.\n * Update your import to `import { AgentState } from \"langchain\";`\n */\nexport interface AgentState<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n StructuredResponseType extends Record<string, any> = Record<string, any>\n> {\n messages: BaseMessage[];\n // TODO: This won't be set until we\n // implement managed values in LangGraphJS\n // Will be useful for inserting a message on\n // graph recursion end\n // is_last_step: boolean;\n structuredResponse: StructuredResponseType;\n}\n\nexport type N = typeof START | \"agent\" | \"tools\";\n\ntype StructuredResponseSchemaOptions<StructuredResponseType> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schema: InteropZodType<StructuredResponseType> | Record<string, any>;\n prompt?: string;\n\n strict?: boolean;\n [key: string]: unknown;\n};\n\nfunction _convertMessageModifierToPrompt(\n messageModifier: MessageModifier\n): Prompt {\n // Handle string or SystemMessage\n if (\n typeof messageModifier === \"string\" ||\n (isBaseMessage(messageModifier) && messageModifier._getType() === \"system\")\n ) {\n return messageModifier;\n }\n\n // Handle callable function\n if (typeof messageModifier === \"function\") {\n return async (state: typeof MessagesAnnotation.State) =>\n messageModifier(state.messages);\n }\n\n // Handle Runnable\n if (Runnable.isRunnable(messageModifier)) {\n return RunnableLambda.from(\n (state: typeof MessagesAnnotation.State) => state.messages\n ).pipe(messageModifier);\n }\n\n throw new Error(\n `Unexpected type for messageModifier: ${typeof messageModifier}`\n );\n}\n\nconst PROMPT_RUNNABLE_NAME = \"prompt\";\n\nfunction _getPromptRunnable(prompt?: Prompt): Runnable {\n let promptRunnable: Runnable;\n\n if (prompt == null) {\n promptRunnable = RunnableLambda.from(\n (state: typeof MessagesAnnotation.State) => state.messages\n ).withConfig({ runName: PROMPT_RUNNABLE_NAME });\n } else if (typeof prompt === \"string\") {\n const systemMessage = new SystemMessage(prompt);\n promptRunnable = RunnableLambda.from(\n (state: typeof MessagesAnnotation.State) => {\n return [systemMessage, ...(state.messages ?? [])];\n }\n ).withConfig({ runName: PROMPT_RUNNABLE_NAME });\n } else if (isBaseMessage(prompt) && prompt._getType() === \"system\") {\n promptRunnable = RunnableLambda.from(\n (state: typeof MessagesAnnotation.State) => [prompt, ...state.messages]\n ).withConfig({ runName: PROMPT_RUNNABLE_NAME });\n } else if (typeof prompt === \"function\") {\n promptRunnable = RunnableLambda.from(prompt).withConfig({\n runName: PROMPT_RUNNABLE_NAME,\n });\n } else if (Runnable.isRunnable(prompt)) {\n promptRunnable = prompt;\n } else {\n throw new Error(`Got unexpected type for 'prompt': ${typeof prompt}`);\n }\n\n return promptRunnable;\n}\n\ntype ServerTool = Record<string, unknown>;\ntype ClientTool = StructuredToolInterface | DynamicTool | RunnableToolLike;\n\nfunction isClientTool(tool: ClientTool | ServerTool): tool is ClientTool {\n return Runnable.isRunnable(tool);\n}\n\nfunction _getPrompt(\n prompt?: Prompt,\n stateModifier?: CreateReactAgentParams[\"stateModifier\"],\n messageModifier?: CreateReactAgentParams[\"messageModifier\"]\n): Runnable {\n // Check if multiple modifiers exist\n const definedCount = [prompt, stateModifier, messageModifier].filter(\n (x) => x != null\n ).length;\n if (definedCount > 1) {\n throw new Error(\n \"Expected only one of prompt, stateModifier, or messageModifier, got multiple values\"\n );\n }\n\n let finalPrompt = prompt;\n if (stateModifier != null) {\n finalPrompt = stateModifier;\n } else if (messageModifier != null) {\n finalPrompt = _convertMessageModifierToPrompt(messageModifier);\n }\n\n return _getPromptRunnable(finalPrompt);\n}\n\nfunction _isBaseChatModel(model: LanguageModelLike): model is BaseChatModel {\n return (\n \"invoke\" in model &&\n typeof model.invoke === \"function\" &&\n \"_modelType\" in model\n );\n}\n\ninterface ConfigurableModelInterface {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n _queuedMethodOperations: Record<string, any>;\n _model: () => Promise<BaseChatModel>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction _isConfigurableModel(model: any): model is ConfigurableModelInterface {\n return (\n \"_queuedMethodOperations\" in model &&\n \"_model\" in model &&\n typeof model._model === \"function\"\n );\n}\n\nfunction _isChatModelWithBindTools(\n llm: LanguageModelLike\n): llm is BaseChatModel & Required<Pick<BaseChatModel, \"bindTools\">> {\n if (!_isBaseChatModel(llm)) return false;\n return \"bindTools\" in llm && typeof llm.bindTools === \"function\";\n}\n\nexport async function _shouldBindTools(\n llm: LanguageModelLike,\n tools: (ClientTool | ServerTool)[]\n): Promise<boolean> {\n // If model is a RunnableSequence, find a RunnableBinding or BaseChatModel in its steps\n let model = llm;\n if (RunnableSequence.isRunnableSequence(model)) {\n model =\n model.steps.find(\n (step) =>\n RunnableBinding.isRunnableBinding(step) ||\n _isBaseChatModel(step) ||\n _isConfigurableModel(step)\n ) || model;\n }\n\n if (_isConfigurableModel(model)) {\n model = await model._model();\n }\n\n // If not a RunnableBinding, we should bind tools\n if (!RunnableBinding.isRunnableBinding(model)) {\n return true;\n }\n\n let boundTools = (() => {\n // check if model.kwargs contain the tools key\n if (\n model.kwargs != null &&\n typeof model.kwargs === \"object\" &&\n \"tools\" in model.kwargs &&\n Array.isArray(model.kwargs.tools)\n ) {\n return (model.kwargs.tools ?? null) as BindToolsInput[] | null;\n }\n\n // Some models can bind the tools via `withConfig()` instead of `bind()`\n if (\n model.config != null &&\n typeof model.config === \"object\" &&\n \"tools\" in model.config &&\n Array.isArray(model.config.tools)\n ) {\n return (model.config.tools ?? null) as BindToolsInput[] | null;\n }\n\n return null;\n })();\n\n // google-style\n if (\n boundTools != null &&\n boundTools.length === 1 &&\n \"functionDeclarations\" in boundTools[0]\n ) {\n boundTools = boundTools[0].functionDeclarations;\n }\n\n // If no tools in kwargs, we should bind tools\n if (boundTools == null) return true;\n\n // Check if tools count matches\n if (tools.length !== boundTools.length) {\n throw new Error(\n \"Number of tools in the model.bindTools() and tools passed to createReactAgent must match\"\n );\n }\n\n const toolNames = new Set<string>(\n tools.flatMap((tool) => (isClientTool(tool) ? tool.name : []))\n );\n\n const boundToolNames = new Set<string>();\n\n for (const boundTool of boundTools) {\n let boundToolName: string | undefined;\n\n // OpenAI-style tool\n if (\"type\" in boundTool && boundTool.type === \"function\") {\n boundToolName = boundTool.function.name;\n }\n // Anthropic or Google-style tool\n else if (\"name\" in boundTool) {\n boundToolName = boundTool.name;\n }\n // Bedrock-style tool\n else if (\"toolSpec\" in boundTool && \"name\" in boundTool.toolSpec) {\n boundToolName = boundTool.toolSpec.name;\n }\n // unknown tool type so we'll ignore it\n else {\n continue;\n }\n\n if (boundToolName) {\n boundToolNames.add(boundToolName);\n }\n }\n\n const missingTools = [...toolNames].filter((x) => !boundToolNames.has(x));\n if (missingTools.length > 0) {\n throw new Error(\n `Missing tools '${missingTools}' in the model.bindTools().` +\n `Tools in the model.bindTools() must match the tools passed to createReactAgent.`\n );\n }\n\n return false;\n}\n\nconst _simpleBindTools = (\n llm: LanguageModelLike,\n toolClasses: (ClientTool | ServerTool)[]\n) => {\n if (_isChatModelWithBindTools(llm)) {\n return llm.bindTools(toolClasses);\n }\n\n if (\n RunnableBinding.isRunnableBinding(llm) &&\n _isChatModelWithBindTools(llm.bound)\n ) {\n const newBound = llm.bound.bindTools(toolClasses);\n\n if (RunnableBinding.isRunnableBinding(newBound)) {\n return new RunnableBinding({\n bound: newBound.bound,\n config: { ...llm.config, ...newBound.config },\n kwargs: { ...llm.kwargs, ...newBound.kwargs },\n configFactories: newBound.configFactories ?? llm.configFactories,\n });\n }\n\n return new RunnableBinding({\n bound: newBound,\n config: llm.config,\n kwargs: llm.kwargs,\n configFactories: llm.configFactories,\n });\n }\n\n return null;\n};\n\nexport async function _bindTools(\n llm: LanguageModelLike,\n toolClasses: (ClientTool | ServerTool)[]\n) {\n const model = _simpleBindTools(llm, toolClasses);\n if (model) return model;\n\n if (_isConfigurableModel(llm)) {\n const model = _simpleBindTools(await llm._model(), toolClasses);\n if (model) return model;\n }\n\n if (RunnableSequence.isRunnableSequence(llm)) {\n const modelStep = llm.steps.findIndex(\n (step) =>\n RunnableBinding.isRunnableBinding(step) ||\n _isBaseChatModel(step) ||\n _isConfigurableModel(step)\n );\n\n if (modelStep >= 0) {\n const model = _simpleBindTools(llm.steps[modelStep], toolClasses);\n if (model) {\n const nextSteps: unknown[] = llm.steps.slice();\n nextSteps.splice(modelStep, 1, model);\n\n return RunnableSequence.from(\n nextSteps as [RunnableLike, ...RunnableLike[], RunnableLike]\n );\n }\n }\n }\n\n throw new Error(`llm ${llm} must define bindTools method.`);\n}\n\nexport async function _getModel(\n llm: LanguageModelLike | ConfigurableModelInterface\n): Promise<LanguageModelLike> {\n // If model is a RunnableSequence, find a RunnableBinding or BaseChatModel in its steps\n let model = llm;\n if (RunnableSequence.isRunnableSequence(model)) {\n model =\n model.steps.find(\n (step) =>\n RunnableBinding.isRunnableBinding(step) ||\n _isBaseChatModel(step) ||\n _isConfigurableModel(step)\n ) || model;\n }\n\n if (_isConfigurableModel(model)) {\n model = await model._model();\n }\n\n // Get the underlying model from a RunnableBinding\n if (RunnableBinding.isRunnableBinding(model)) {\n model = model.bound;\n }\n\n if (!_isBaseChatModel(model)) {\n throw new Error(\n `Expected \\`llm\\` to be a ChatModel or RunnableBinding (e.g. llm.bind_tools(...)) with invoke() and generate() methods, got ${model.constructor.name}`\n );\n }\n\n return model;\n}\n\nexport type Prompt =\n | SystemMessage\n | string\n | ((\n state: typeof MessagesAnnotation.State,\n config: LangGraphRunnableConfig\n ) => BaseMessageLike[])\n | ((\n state: typeof MessagesAnnotation.State,\n config: LangGraphRunnableConfig\n ) => Promise<BaseMessageLike[]>)\n | Runnable;\n\n/** @deprecated Use Prompt instead. */\nexport type StateModifier = Prompt;\n\n/** @deprecated Use Prompt instead. */\nexport type MessageModifier =\n | SystemMessage\n | string\n | ((messages: BaseMessage[]) => BaseMessage[])\n | ((messages: BaseMessage[]) => Promise<BaseMessage[]>)\n | Runnable;\n\nexport const createReactAgentAnnotation = <\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>\n>() =>\n Annotation.Root({\n messages: Annotation<BaseMessage[], Messages>({\n reducer: messagesStateReducer,\n default: () => [],\n }),\n structuredResponse: Annotation<T>,\n });\n\ntype WithStateGraphNodes<K extends string, Graph> = Graph extends StateGraph<\n infer SD,\n infer S,\n infer U,\n infer N,\n infer I,\n infer O,\n infer C\n>\n ? StateGraph<SD, S, U, N | K, I, O, C>\n : never;\n\nconst PreHookAnnotation = Annotation.Root({\n llmInputMessages: Annotation<BaseMessage[], Messages>({\n reducer: (_, update) => messagesStateReducer([], update),\n default: () => [],\n }),\n});\n\ntype PreHookAnnotation = typeof PreHookAnnotation;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyAnnotationRoot = AnnotationRoot<any>;\n\ntype ToAnnotationRoot<A extends AnyAnnotationRoot | InteropZodObject> =\n A extends AnyAnnotationRoot\n ? A\n : A extends InteropZodObject\n ? AnnotationRoot<InteropZodToStateDefinition<A>>\n : never;\n\n/**\n * @deprecated `CreateReactAgentParams` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.\n * Update your import to `import { CreateAgentParams } from \"langchain\";`\n */\nexport type CreateReactAgentParams<\n A extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n StructuredResponseType extends Record<string, any> = Record<string, any>,\n C extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n> = {\n /** The chat model that can utilize OpenAI-style tool calling. */\n llm:\n | LanguageModelLike\n | ((\n state: ToAnnotationRoot<A>[\"State\"] & PreHookAnnotation[\"State\"],\n runtime: Runtime<ToAnnotationRoot<C>[\"State\"]>\n ) => Promise<LanguageModelLike> | LanguageModelLike);\n\n /** A list of tools or a ToolNode. */\n tools: ToolNode | (ServerTool | ClientTool)[];\n\n /**\n * @deprecated Use prompt instead.\n */\n messageModifier?: MessageModifier;\n\n /**\n * @deprecated Use prompt instead.\n */\n stateModifier?: StateModifier;\n\n /**\n * An optional prompt for the LLM. This takes full graph state BEFORE the LLM is called and prepares the input to LLM.\n *\n * Can take a few different forms:\n *\n * - str: This is converted to a SystemMessage and added to the beginning of the list of messages in state[\"messages\"].\n * - SystemMessage: this is added to the beginning of the list of messages in state[\"messages\"].\n * - Function: This function should take in full graph state and the output is then passed to the language model.\n * - Runnable: This runnable should take in full graph state and the output is then passed to the language model.\n *\n * Note:\n * Prior to `v0.2.46`, the prompt was set using `stateModifier` / `messagesModifier` parameters.\n * This is now deprecated and will be removed in a future release.\n */\n prompt?: Prompt;\n\n /**\n * Additional state schema for the agent.\n */\n stateSchema?: A;\n\n /**\n * An optional schema for the context.\n */\n contextSchema?: C;\n /** An optional checkpoint saver to persist the agent's state. */\n checkpointSaver?: BaseCheckpointSaver | boolean;\n /** An optional checkpoint saver to persist the agent's state. Alias of \"checkpointSaver\". */\n checkpointer?: BaseCheckpointSaver | boolean;\n /** An optional list of node names to interrupt before running. */\n interruptBefore?: N[] | All;\n /** An optional list of node names to interrupt after running. */\n interruptAfter?: N[] | All;\n store?: BaseStore;\n /**\n * An optional schema for the final agent output.\n *\n * If provided, output will be formatted to match the given schema and returned in the 'structuredResponse' state key.\n * If not provided, `structuredResponse` will not be present in the output state.\n *\n * Can be passed in as:\n * - Zod schema\n * - JSON schema\n * - { prompt, schema }, where schema is one of the above.\n * The prompt will be used together with the model that is being used to generate the structured response.\n *\n * @remarks\n * **Important**: `responseFormat` requires the model to support `.withStructuredOutput()`.\n *\n * **Note**: The graph will make a separate call to the LLM to generate the structured response after the agent loop is finished.\n * This is not the only strategy to get structured responses, see more options in [this guide](https://langchain-ai.github.io/langgraph/how-tos/react-agent-structured-output/).\n */\n responseFormat?:\n | InteropZodType<StructuredResponseType>\n | StructuredResponseSchemaOptions<StructuredResponseType>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | Record<string, any>;\n\n /**\n * An optional name for the agent.\n */\n name?: string;\n\n /**\n * An optional description for the agent.\n * This can be used to describe the agent to the underlying supervisor LLM.\n */\n description?: string | undefined;\n\n /**\n * Use to specify how to expose the agent name to the underlying supervisor LLM.\n\n - undefined: Relies on the LLM provider {@link AIMessage#name}. Currently, only OpenAI supports this.\n - `\"inline\"`: Add the agent name directly into the content field of the {@link AIMessage} using XML-style tags.\n Example: `\"How can I help you\"` -> `\"<name>agent_name</name><content>How can I help you?</content>\"`\n */\n includeAgentName?: \"inline\" | undefined;\n\n /**\n * An optional node to add before the `agent` node (i.e., the node that calls the LLM).\n * Useful for managing long message histories (e.g., message trimming, summarization, etc.).\n */\n preModelHook?: RunnableLike<\n ToAnnotationRoot<A>[\"State\"] & PreHookAnnotation[\"State\"],\n ToAnnotationRoot<A>[\"Update\"] & PreHookAnnotation[\"Update\"],\n LangGraphRunnableConfig\n >;\n\n /**\n * An optional node to add after the `agent` node (i.e., the node that calls the LLM).\n * Useful for implementing human-in-the-loop, guardrails, validation, or other post-processing.\n */\n postModelHook?: RunnableLike<\n ToAnnotationRoot<A>[\"State\"],\n ToAnnotationRoot<A>[\"Update\"],\n LangGraphRunnableConfig\n >;\n\n /**\n * Determines the version of the graph to create.\n *\n * Can be one of\n * - `\"v1\"`: The tool node processes a single message. All tool calls in the message are\n * executed in parallel within the tool node.\n * - `\"v2\"`: The tool node processes a single tool call. Tool calls are distributed across\n * multiple instances of the tool node using the Send API.\n *\n * @default `\"v1\"`\n */\n version?: \"v1\" | \"v2\";\n};\n\n/**\n * @deprecated `createReactAgent` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.\n * Update your import to `import { createAgent } from \"langchain\";`\n *\n * Creates a StateGraph agent that relies on a chat model utilizing tool calling.\n *\n * @example\n * ```ts\n * import { ChatOpenAI } from \"@langchain/openai\";\n * import { tool } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n * import { createReactAgent } from \"@langchain/langgraph/prebuilt\";\n *\n * const model = new ChatOpenAI({\n * model: \"gpt-4o\",\n * });\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * })\n * })\n *\n * const agent = createReactAgent({ llm: model, tools: [getWeather] });\n *\n * const inputs = {\n * messages: [{ role: \"user\", content: \"what is the weather in SF?\" }],\n * };\n *\n * const stream = await agent.stream(inputs, { streamMode: \"values\" });\n *\n * for await (const { messages } of stream) {\n * console.log(messages);\n * }\n * // Returns the messages in the state at each step of execution\n * ```\n */\nexport function createReactAgent<\n A extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n StructuredResponseFormat extends Record<string, any> = Record<string, any>,\n C extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot\n>(\n params: CreateReactAgentParams<A, StructuredResponseFormat, C>\n): CompiledStateGraph<\n ToAnnotationRoot<A>[\"State\"],\n ToAnnotationRoot<A>[\"Update\"],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any,\n typeof MessagesAnnotation.spec & ToAnnotationRoot<A>[\"spec\"],\n ReturnType<\n typeof createReactAgentAnnotation<StructuredResponseFormat>\n >[\"spec\"] &\n ToAnnotationRoot<A>[\"spec\"]\n> {\n const {\n llm,\n tools,\n messageModifier,\n stateModifier,\n prompt,\n stateSchema,\n contextSchema,\n checkpointSaver,\n checkpointer,\n interruptBefore,\n interruptAfter,\n store,\n responseFormat,\n preModelHook,\n postModelHook,\n name,\n description,\n version = \"v1\",\n includeAgentName,\n } = params;\n\n let toolClasses: (ClientTool | ServerTool)[];\n\n let toolNode: ToolNode;\n if (!Array.isArray(tools)) {\n toolClasses = tools.tools;\n toolNode = tools;\n } else {\n toolClasses = tools;\n toolNode = new ToolNode(toolClasses.filter(isClientTool));\n }\n\n let cachedStaticModel: Runnable | null = null;\n\n const _getStaticModel = async (llm: LanguageModelLike): Promise<Runnable> => {\n if (cachedStaticModel) return cachedStaticModel;\n\n let modelWithTools: LanguageModelLike;\n if (await _shouldBindTools(llm, toolClasses)) {\n modelWithTools = await _bindTools(llm, toolClasses);\n } else {\n modelWithTools = llm;\n }\n\n const promptRunnable = _getPrompt(prompt, stateModifier, messageModifier);\n const modelRunnable =\n includeAgentName === \"inline\"\n ? withAgentName(modelWithTools, includeAgentName)\n : modelWithTools;\n\n cachedStaticModel = promptRunnable.pipe(modelRunnable);\n return cachedStaticModel;\n };\n\n const _getDynamicModel = async (\n llm: (\n state: AgentState<StructuredResponseFormat> & PreHookAnnotation[\"State\"],\n runtime: Runtime<ToAnnotationRoot<C>[\"State\"]>\n ) => Promise<LanguageModelLike> | LanguageModelLike,\n state: AgentState<StructuredResponseFormat> & PreHookAnnotation[\"State\"],\n config: Runtime<ToAnnotationRoot<C>[\"State\"]>\n ) => {\n const model = await llm(state, config);\n\n return _getPrompt(prompt, stateModifier, messageModifier).pipe(\n includeAgentName === \"inline\"\n ? withAgentName(model, includeAgentName)\n : model\n );\n };\n\n // If any of the tools are configured to return_directly after running,\n // our graph needs to check if these were called\n const shouldReturnDirect = new Set(\n toolClasses\n .filter(isClientTool)\n .filter((tool) => \"returnDirect\" in tool && tool.returnDirect)\n .map((tool) => tool.name)\n );\n\n function getModelInputState(\n state: AgentState<StructuredResponseFormat> & PreHookAnnotation[\"State\"]\n ): Omit<AgentState<StructuredResponseFormat>, \"llmInputMessages\"> {\n const { messages, llmInputMessages, ...rest } = state;\n if (llmInputMessages != null && llmInputMessages.length > 0) {\n return { messages: llmInputMessages, ...rest };\n }\n return { messages, ...rest };\n }\n\n const generateStructuredResponse = async (\n state: AgentState<StructuredResponseFormat> & PreHookAnnotation[\"State\"],\n config: Runtime<ToAnnotationRoot<C>[\"State\"]>\n ) => {\n if (responseFormat == null) {\n throw new Error(\n \"Attempted to generate structured output with no passed response schema. Please contact us for help.\"\n );\n }\n const messages = [...state.messages];\n let modelWithStructuredOutput;\n\n const model: LanguageModelLike =\n typeof llm === \"function\"\n ? await llm(state, config)\n : await _getModel(llm);\n\n if (!_isBaseChatModel(model)) {\n throw new Error(\n `Expected \\`llm\\` to be a ChatModel with .withStructuredOutput() method, got ${model.constructor.name}`\n );\n }\n\n if (typeof responseFormat === \"object\" && \"schema\" in responseFormat) {\n const { prompt, schema, ...options } =\n responseFormat as StructuredResponseSchemaOptions<StructuredResponseFormat>;\n\n modelWithStructuredOutput = model.withStructuredOutput(schema, options);\n if (prompt != null) {\n messages.unshift(new SystemMessage({ content: prompt }));\n }\n } else {\n modelWithStructuredOutput = model.withStructuredOutput(responseFormat);\n }\n\n const response = await modelWithStructuredOutput.invoke(messages, config);\n return { structuredResponse: response };\n };\n\n const callModel = async (\n state: AgentState<StructuredResponseFormat> & PreHookAnnotation[\"State\"],\n config: Runtime<ToAnnotationRoot<C>[\"State\"]>\n ) => {\n // NOTE: we're dynamically creating the model runnable here\n // to ensure that we can validate ConfigurableModel properly\n const modelRunnable: Runnable =\n typeof llm === \"function\"\n ? await _getDynamicModel(llm, state, config)\n : await _getStaticModel(llm);\n\n // TODO: Auto-promote streaming.\n const response = (await modelRunnable.invoke(\n getModelInputState(state),\n config\n )) as BaseMessage;\n // add agent name to the AIMessage\n // TODO: figure out if we can avoid mutating the message directly\n response.name = name;\n response.lc_kwargs.name = name;\n return { messages: [response] };\n };\n\n const schema =\n stateSchema ?? createReactAgentAnnotation<StructuredResponseFormat>();\n\n const workflow = new StateGraph(\n schema as AnyAnnotationRoot,\n contextSchema\n ).addNode(\"tools\", toolNode);\n\n if (!(\"messages\" in workflow._schemaDefinition)) {\n throw new Error(\"Missing required `messages` key in state schema.\");\n }\n\n const allNodeWorkflows = workflow as WithStateGraphNodes<\n | \"pre_model_hook\"\n | \"post_model_hook\"\n | \"generate_structured_response\"\n | \"agent\",\n typeof workflow\n >;\n\n const conditionalMap = <T extends string>(map: Record<string, T | null>) => {\n return Object.fromEntries(\n Object.entries(map).filter(([_, v]) => v != null) as [string, T][]\n );\n };\n\n let entrypoint: \"agent\" | \"pre_model_hook\" = \"agent\";\n let inputSchema: AnnotationRoot<ToAnnotationRoot<A>[\"spec\"]> | undefined;\n if (preModelHook != null) {\n allNodeWorkflows\n .addNode(\"pre_model_hook\", preModelHook)\n .addEdge(\"pre_model_hook\", \"agent\");\n entrypoint = \"pre_model_hook\";\n\n inputSchema = Annotation.Root({\n ...workflow._schemaDefinition,\n ...PreHookAnnotation.spec,\n });\n } else {\n entrypoint = \"agent\";\n }\n\n allNodeWorkflows\n .addNode(\"agent\", callModel, { input: inputSchema })\n .addEdge(START, entrypoint);\n\n if (postModelHook != null) {\n allNodeWorkflows\n .addNode(\"post_model_hook\", postModelHook)\n .addEdge(\"agent\", \"post_model_hook\")\n .addConditionalEdges(\n \"post_model_hook\",\n (state: AgentState<StructuredResponseFormat>) => {\n const { messages } = state;\n\n const toolMessageIds: Set<string> = new Set(\n messages.filter(isToolMessage).map((msg) => msg.tool_call_id)\n );\n\n let lastAiMessage: AIMessage | undefined;\n for (let i = messages.length - 1; i >= 0; i -= 1) {\n const message = messages[i];\n if (isAIMessage(message)) {\n lastAiMessage = message;\n break;\n }\n }\n\n const pendingToolCalls =\n lastAiMessage?.tool_calls?.filter(\n (i) => i.id == null || !toolMessageIds.has(i.id)\n ) ?? [];\n\n const lastMessage = messages.at(-1);\n if (pendingToolCalls.length > 0) {\n if (version === \"v2\") {\n return pendingToolCalls.map(\n (toolCall) =>\n new Send(\"tools\", { ...state, lg_tool_call: toolCall })\n );\n }\n return \"tools\";\n }\n\n if (lastMessage && isToolMessage(lastMessage)) return entrypoint;\n if (responseFormat != null) return \"generate_structured_response\";\n return END;\n },\n conditionalMap({\n tools: \"tools\",\n [entrypoint]: entrypoint,\n generate_structured_response:\n responseFormat != null ? \"generate_structured_response\" : null,\n [END]: responseFormat != null ? null : END,\n })\n );\n }\n\n if (responseFormat !== undefined) {\n workflow\n .addNode(\"generate_structured_response\", generateStructuredResponse)\n .addEdge(\"generate_structured_response\", END);\n }\n\n if (postModelHook == null) {\n allNodeWorkflows.addConditionalEdges(\n \"agent\",\n (state: AgentState<StructuredResponseFormat>) => {\n const { messages } = state;\n const lastMessage = messages[messages.length - 1];\n\n // if there's no function call, we finish\n if (!isAIMessage(lastMessage) || !lastMessage.tool_calls?.length) {\n if (responseFormat != null) return \"generate_structured_response\";\n return END;\n }\n\n // there are function calls, we continue\n if (version === \"v2\") {\n return lastMessage.tool_calls.map(\n (toolCall) =>\n new Send(\"tools\", { ...state, lg_tool_call: toolCall })\n );\n }\n\n return \"tools\";\n },\n conditionalMap({\n tools: \"tools\",\n generate_structured_response:\n responseFormat != null ? \"generate_structured_response\" : null,\n [END]: responseFormat != null ? null : END,\n })\n );\n }\n\n if (shouldReturnDirect.size > 0) {\n allNodeWorkflows.addConditionalEdges(\n \"tools\",\n (state: AgentState<StructuredResponseFormat>) => {\n // Check the last consecutive tool calls\n for (let i = state.messages.length - 1; i >= 0; i -= 1) {\n const message = state.messages[i];\n if (!isToolMessage(message)) break;\n\n // Check if this tool is configured to return directly\n if (\n message.name !== undefined &&\n shouldReturnDirect.has(message.name)\n ) {\n return END;\n }\n }\n\n return entrypoint;\n },\n conditionalMap({ [entrypoint]: entrypoint, [END]: END })\n );\n } else {\n allNodeWorkflows.addEdge(\"tools\", entrypoint);\n }\n\n return allNodeWorkflows.compile({\n checkpointer: checkpointer ?? checkpointSaver,\n interruptBefore,\n interruptAfter,\n store,\n name,\n description,\n });\n}\n"],"mappings":";;;;;;;;;;;AA2EA,SAAS,gCACP,iBACQ;AAER,KACE,OAAO,oBAAoB,wDACZ,gBAAgB,IAAI,gBAAgB,UAAU,KAAK,SAElE,QAAO;AAIT,KAAI,OAAO,oBAAoB,WAC7B,QAAO,OAAO,UACZ,gBAAgB,MAAM,SAAS;AAInC,KAAIA,mCAAS,WAAW,gBAAgB,CACtC,QAAOC,yCAAe,MACnB,UAA2C,MAAM,SACnD,CAAC,KAAK,gBAAgB;AAGzB,OAAM,IAAI,MACR,wCAAwC,OAAO,kBAChD;;AAGH,MAAM,uBAAuB;AAE7B,SAAS,mBAAmB,QAA2B;CACrD,IAAI;AAEJ,KAAI,UAAU,KACZ,kBAAiBA,yCAAe,MAC7B,UAA2C,MAAM,SACnD,CAAC,WAAW,EAAE,SAAS,sBAAsB,CAAC;UACtC,OAAO,WAAW,UAAU;EACrC,MAAM,gBAAgB,IAAIC,uCAAc,OAAO;AAC/C,mBAAiBD,yCAAe,MAC7B,UAA2C;AAC1C,UAAO,CAAC,eAAe,GAAI,MAAM,YAAY,EAAE,CAAE;IAEpD,CAAC,WAAW,EAAE,SAAS,sBAAsB,CAAC;wDACxB,OAAO,IAAI,OAAO,UAAU,KAAK,SACxD,kBAAiBA,yCAAe,MAC7B,UAA2C,CAAC,QAAQ,GAAG,MAAM,SAAS,CACxE,CAAC,WAAW,EAAE,SAAS,s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AAgB;EAC9B;EACA;EACA;EACA;EACA;EACD,CAAC"}
|
|
@@ -11,7 +11,7 @@ import { ToolNode } from "./tool_node.cjs";
|
|
|
11
11
|
import { All, BaseCheckpointSaver, BaseStore } from "@langchain/langgraph-checkpoint";
|
|
12
12
|
import { InteropZodObject, InteropZodType } from "@langchain/core/utils/types";
|
|
13
13
|
import { Runnable, RunnableBinding, RunnableLike, RunnableToolLike } from "@langchain/core/runnables";
|
|
14
|
-
import * as
|
|
14
|
+
import * as _langchain_core_messages17 from "@langchain/core/messages";
|
|
15
15
|
import { BaseMessage, BaseMessageLike, SystemMessage } from "@langchain/core/messages";
|
|
16
16
|
import { DynamicTool, StructuredToolInterface } from "@langchain/core/tools";
|
|
17
17
|
import { LanguageModelLike } from "@langchain/core/language_models/base";
|
|
@@ -21,20 +21,12 @@ import { LanguageModelLike } from "@langchain/core/language_models/base";
|
|
|
21
21
|
* @deprecated `AgentState` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.
|
|
22
22
|
* Update your import to `import { AgentState } from "langchain";`
|
|
23
23
|
*/
|
|
24
|
-
interface AgentState<
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
-
StructuredResponseType extends Record<string, any> = Record<string, any>> {
|
|
24
|
+
interface AgentState<StructuredResponseType extends Record<string, any> = Record<string, any>> {
|
|
27
25
|
messages: BaseMessage[];
|
|
28
|
-
// TODO: This won't be set until we
|
|
29
|
-
// implement managed values in LangGraphJS
|
|
30
|
-
// Will be useful for inserting a message on
|
|
31
|
-
// graph recursion end
|
|
32
|
-
// is_last_step: boolean;
|
|
33
26
|
structuredResponse: StructuredResponseType;
|
|
34
27
|
}
|
|
35
28
|
type N = typeof START | "agent" | "tools";
|
|
36
29
|
type StructuredResponseSchemaOptions<StructuredResponseType> = {
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
30
|
schema: InteropZodType<StructuredResponseType> | Record<string, any>;
|
|
39
31
|
prompt?: string;
|
|
40
32
|
strict?: boolean;
|
|
@@ -47,10 +39,8 @@ type Prompt = SystemMessage | string | ((state: typeof MessagesAnnotation.State,
|
|
|
47
39
|
type StateModifier = Prompt;
|
|
48
40
|
/** @deprecated Use Prompt instead. */
|
|
49
41
|
type MessageModifier = SystemMessage | string | ((messages: BaseMessage[]) => BaseMessage[]) | ((messages: BaseMessage[]) => Promise<BaseMessage[]>) | Runnable;
|
|
50
|
-
declare const createReactAgentAnnotation: <
|
|
51
|
-
|
|
52
|
-
T extends Record<string, any> = Record<string, any>>() => AnnotationRoot<{
|
|
53
|
-
messages: BinaryOperatorAggregate<BaseMessage<_langchain_core_messages13.MessageStructure, _langchain_core_messages13.MessageType>[], Messages>;
|
|
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>;
|
|
54
44
|
structuredResponse: {
|
|
55
45
|
(): LastValue<T>;
|
|
56
46
|
(annotation: SingleReducer<T, T>): BinaryOperatorAggregate<T, T>;
|
|
@@ -58,19 +48,16 @@ T extends Record<string, any> = Record<string, any>>() => AnnotationRoot<{
|
|
|
58
48
|
};
|
|
59
49
|
}>;
|
|
60
50
|
declare const PreHookAnnotation: AnnotationRoot<{
|
|
61
|
-
llmInputMessages: BinaryOperatorAggregate<BaseMessage<
|
|
51
|
+
llmInputMessages: BinaryOperatorAggregate<BaseMessage<_langchain_core_messages17.MessageStructure<_langchain_core_messages17.MessageToolSet>, _langchain_core_messages17.MessageType>[], Messages>;
|
|
62
52
|
}>;
|
|
63
53
|
type PreHookAnnotation = typeof PreHookAnnotation;
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
54
|
type AnyAnnotationRoot = AnnotationRoot<any>;
|
|
66
55
|
type ToAnnotationRoot<A extends AnyAnnotationRoot | InteropZodObject> = A extends AnyAnnotationRoot ? A : A extends InteropZodObject ? AnnotationRoot<InteropZodToStateDefinition<A>> : never;
|
|
67
56
|
/**
|
|
68
57
|
* @deprecated `CreateReactAgentParams` has been moved to {@link https://www.npmjs.com/package/langchain langchain} package.
|
|
69
58
|
* Update your import to `import { CreateAgentParams } from "langchain";`
|
|
70
59
|
*/
|
|
71
|
-
type CreateReactAgentParams<A extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot,
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
-
StructuredResponseType extends Record<string, any> = Record<string, any>, C extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot> = {
|
|
60
|
+
type CreateReactAgentParams<A extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, StructuredResponseType extends Record<string, any> = Record<string, any>, C extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot> = {
|
|
74
61
|
/** The chat model that can utilize OpenAI-style tool calling. */
|
|
75
62
|
llm: LanguageModelLike | ((state: ToAnnotationRoot<A>["State"] & PreHookAnnotation["State"], runtime: Runtime<ToAnnotationRoot<C>["State"]>) => Promise<LanguageModelLike> | LanguageModelLike);
|
|
76
63
|
/** A list of tools or a ToolNode. */
|
|
@@ -133,9 +120,7 @@ StructuredResponseType extends Record<string, any> = Record<string, any>, C exte
|
|
|
133
120
|
* **Note**: The graph will make a separate call to the LLM to generate the structured response after the agent loop is finished.
|
|
134
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/).
|
|
135
122
|
*/
|
|
136
|
-
responseFormat?: InteropZodType<StructuredResponseType> | StructuredResponseSchemaOptions<StructuredResponseType>
|
|
137
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
138
|
-
| Record<string, any>;
|
|
123
|
+
responseFormat?: InteropZodType<StructuredResponseType> | StructuredResponseSchemaOptions<StructuredResponseType> | Record<string, any>;
|
|
139
124
|
/**
|
|
140
125
|
* An optional name for the agent.
|
|
141
126
|
*/
|
|
@@ -220,11 +205,7 @@ StructuredResponseType extends Record<string, any> = Record<string, any>, C exte
|
|
|
220
205
|
* // Returns the messages in the state at each step of execution
|
|
221
206
|
* ```
|
|
222
207
|
*/
|
|
223
|
-
declare function createReactAgent<A extends AnyAnnotationRoot | InteropZodObject = typeof MessagesAnnotation,
|
|
224
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
225
|
-
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"],
|
|
226
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
227
|
-
any, typeof MessagesAnnotation.spec & ToAnnotationRoot<A>["spec"], ReturnType<typeof createReactAgentAnnotation<StructuredResponseFormat>>["spec"] & ToAnnotationRoot<A>["spec"]>;
|
|
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"]>;
|
|
228
209
|
//#endregion
|
|
229
210
|
export { AgentState, CreateReactAgentParams, createReactAgent, createReactAgentAnnotation };
|
|
230
211
|
//# sourceMappingURL=react_agent_executor.d.cts.map
|