@langchain/langgraph 1.2.2 → 1.2.3
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 +3 -4
- package/dist/channels/any_value.cjs.map +1 -1
- package/dist/channels/any_value.js +1 -2
- 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.js +1 -2
- package/dist/channels/base.js.map +1 -1
- package/dist/channels/binop.cjs +4 -5
- package/dist/channels/binop.cjs.map +1 -1
- package/dist/channels/binop.js +1 -2
- package/dist/channels/binop.js.map +1 -1
- package/dist/channels/dynamic_barrier_value.cjs +4 -5
- package/dist/channels/dynamic_barrier_value.cjs.map +1 -1
- package/dist/channels/dynamic_barrier_value.js +1 -2
- package/dist/channels/dynamic_barrier_value.js.map +1 -1
- package/dist/channels/ephemeral_value.cjs +3 -4
- package/dist/channels/ephemeral_value.cjs.map +1 -1
- package/dist/channels/ephemeral_value.js +1 -2
- package/dist/channels/ephemeral_value.js.map +1 -1
- package/dist/channels/index.cjs +11 -12
- package/dist/channels/index.js +1 -2
- package/dist/channels/last_value.cjs +3 -4
- package/dist/channels/last_value.cjs.map +1 -1
- package/dist/channels/last_value.js +1 -2
- package/dist/channels/last_value.js.map +1 -1
- package/dist/channels/named_barrier_value.cjs +3 -4
- package/dist/channels/named_barrier_value.cjs.map +1 -1
- package/dist/channels/named_barrier_value.js +1 -2
- package/dist/channels/named_barrier_value.js.map +1 -1
- package/dist/channels/topic.cjs +3 -4
- package/dist/channels/topic.cjs.map +1 -1
- package/dist/channels/topic.js +1 -2
- package/dist/channels/topic.js.map +1 -1
- package/dist/channels/untracked_value.cjs +3 -4
- package/dist/channels/untracked_value.cjs.map +1 -1
- package/dist/channels/untracked_value.js +1 -2
- package/dist/channels/untracked_value.js.map +1 -1
- package/dist/constants.cjs +4 -9
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.js +5 -7
- package/dist/constants.js.map +1 -1
- package/dist/errors.cjs +1 -2
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/func/index.cjs +9 -10
- package/dist/func/index.cjs.map +1 -1
- package/dist/func/index.js +1 -2
- package/dist/func/index.js.map +1 -1
- package/dist/graph/annotation.cjs +3 -4
- package/dist/graph/annotation.cjs.map +1 -1
- package/dist/graph/annotation.js +1 -2
- package/dist/graph/annotation.js.map +1 -1
- package/dist/graph/graph.cjs +23 -24
- package/dist/graph/graph.cjs.map +1 -1
- package/dist/graph/graph.js +16 -17
- package/dist/graph/graph.js.map +1 -1
- package/dist/graph/index.cjs +6 -6
- package/dist/graph/index.js +7 -8
- package/dist/graph/message.cjs +4 -5
- package/dist/graph/message.cjs.map +1 -1
- package/dist/graph/message.js +1 -2
- package/dist/graph/message.js.map +1 -1
- package/dist/graph/messages_annotation.cjs +4 -5
- package/dist/graph/messages_annotation.cjs.map +1 -1
- package/dist/graph/messages_annotation.js +1 -2
- package/dist/graph/messages_annotation.js.map +1 -1
- package/dist/graph/messages_reducer.cjs +2 -3
- package/dist/graph/messages_reducer.cjs.map +1 -1
- package/dist/graph/messages_reducer.js +2 -3
- package/dist/graph/messages_reducer.js.map +1 -1
- package/dist/graph/state.cjs +24 -25
- package/dist/graph/state.cjs.map +1 -1
- package/dist/graph/state.js +10 -11
- package/dist/graph/state.js.map +1 -1
- package/dist/graph/types.cjs +4 -5
- package/dist/graph/types.cjs.map +1 -1
- package/dist/graph/types.js +2 -3
- package/dist/graph/types.js.map +1 -1
- package/dist/graph/zod/index.cjs +5 -6
- package/dist/graph/zod/index.js +1 -2
- package/dist/graph/zod/meta.cjs +4 -5
- package/dist/graph/zod/meta.cjs.map +1 -1
- package/dist/graph/zod/meta.js +2 -3
- package/dist/graph/zod/meta.js.map +1 -1
- package/dist/graph/zod/plugin.cjs +2 -3
- package/dist/graph/zod/plugin.cjs.map +1 -1
- package/dist/graph/zod/plugin.js +2 -3
- package/dist/graph/zod/plugin.js.map +1 -1
- package/dist/graph/zod/schema.cjs +5 -6
- package/dist/graph/zod/schema.cjs.map +1 -1
- package/dist/graph/zod/schema.js +4 -5
- package/dist/graph/zod/schema.js.map +1 -1
- package/dist/graph/zod/zod-registry.cjs +2 -3
- package/dist/graph/zod/zod-registry.cjs.map +1 -1
- package/dist/graph/zod/zod-registry.js +1 -2
- package/dist/graph/zod/zod-registry.js.map +1 -1
- package/dist/hash.cjs +1 -2
- package/dist/hash.cjs.map +1 -1
- package/dist/hash.js +1 -1
- package/dist/index.cjs +60 -61
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/interrupt.cjs +7 -8
- package/dist/interrupt.cjs.map +1 -1
- package/dist/interrupt.js +5 -6
- package/dist/interrupt.js.map +1 -1
- package/dist/prebuilt/agentName.cjs +1 -2
- package/dist/prebuilt/agentName.cjs.map +1 -1
- package/dist/prebuilt/agentName.js +1 -2
- package/dist/prebuilt/agentName.js.map +1 -1
- package/dist/prebuilt/agent_executor.cjs +4 -5
- package/dist/prebuilt/agent_executor.cjs.map +1 -1
- package/dist/prebuilt/agent_executor.js +1 -2
- package/dist/prebuilt/agent_executor.js.map +1 -1
- package/dist/prebuilt/chat_agent_executor.cjs +4 -5
- package/dist/prebuilt/chat_agent_executor.cjs.map +1 -1
- package/dist/prebuilt/chat_agent_executor.js +1 -2
- package/dist/prebuilt/chat_agent_executor.js.map +1 -1
- package/dist/prebuilt/index.cjs +8 -9
- package/dist/prebuilt/index.js +1 -2
- package/dist/prebuilt/react_agent_executor.cjs +8 -9
- package/dist/prebuilt/react_agent_executor.cjs.map +1 -1
- package/dist/prebuilt/react_agent_executor.js +1 -2
- package/dist/prebuilt/react_agent_executor.js.map +1 -1
- package/dist/prebuilt/tool_executor.cjs +1 -2
- package/dist/prebuilt/tool_executor.cjs.map +1 -1
- package/dist/prebuilt/tool_executor.js +1 -2
- package/dist/prebuilt/tool_executor.js.map +1 -1
- package/dist/prebuilt/tool_node.cjs +4 -5
- package/dist/prebuilt/tool_node.cjs.map +1 -1
- package/dist/prebuilt/tool_node.js +1 -2
- package/dist/prebuilt/tool_node.js.map +1 -1
- package/dist/pregel/algo.cjs +30 -31
- package/dist/pregel/algo.cjs.map +1 -1
- package/dist/pregel/algo.js +23 -24
- package/dist/pregel/algo.js.map +1 -1
- package/dist/pregel/call.cjs +5 -6
- package/dist/pregel/call.cjs.map +1 -1
- package/dist/pregel/call.js +2 -3
- package/dist/pregel/call.js.map +1 -1
- package/dist/pregel/debug.cjs +10 -11
- package/dist/pregel/debug.cjs.map +1 -1
- package/dist/pregel/debug.js +8 -9
- package/dist/pregel/debug.js.map +1 -1
- package/dist/pregel/index.cjs +47 -48
- package/dist/pregel/index.cjs.map +1 -1
- package/dist/pregel/index.js +28 -29
- package/dist/pregel/index.js.map +1 -1
- package/dist/pregel/io.cjs +7 -8
- package/dist/pregel/io.cjs.map +1 -1
- package/dist/pregel/io.js +5 -6
- package/dist/pregel/io.js.map +1 -1
- package/dist/pregel/loop.cjs +29 -30
- package/dist/pregel/loop.cjs.map +1 -1
- package/dist/pregel/loop.js +20 -21
- package/dist/pregel/loop.js.map +1 -1
- package/dist/pregel/messages.cjs +4 -5
- package/dist/pregel/messages.cjs.map +1 -1
- package/dist/pregel/messages.js +4 -5
- package/dist/pregel/messages.js.map +1 -1
- package/dist/pregel/read.cjs +4 -5
- package/dist/pregel/read.cjs.map +1 -1
- package/dist/pregel/read.js +1 -2
- package/dist/pregel/read.js.map +1 -1
- package/dist/pregel/remote.cjs +9 -10
- package/dist/pregel/remote.cjs.map +1 -1
- package/dist/pregel/remote.js +7 -8
- package/dist/pregel/remote.js.map +1 -1
- package/dist/pregel/retry.cjs +8 -14
- package/dist/pregel/retry.cjs.map +1 -1
- package/dist/pregel/retry.js +4 -10
- package/dist/pregel/retry.js.map +1 -1
- package/dist/pregel/runner.cjs +8 -9
- package/dist/pregel/runner.cjs.map +1 -1
- package/dist/pregel/runner.js +4 -5
- package/dist/pregel/runner.js.map +1 -1
- package/dist/pregel/stream.cjs +3 -4
- package/dist/pregel/stream.cjs.map +1 -1
- package/dist/pregel/stream.js +3 -4
- package/dist/pregel/stream.js.map +1 -1
- package/dist/pregel/types.cjs +1 -2
- package/dist/pregel/types.cjs.map +1 -1
- package/dist/pregel/types.js +1 -1
- package/dist/pregel/types.js.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.js +6 -7
- package/dist/pregel/utils/config.js.map +1 -1
- package/dist/pregel/utils/index.cjs +2 -3
- package/dist/pregel/utils/index.cjs.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 +1 -2
- package/dist/pregel/utils/subgraph.cjs.map +1 -1
- package/dist/pregel/utils/subgraph.js +1 -1
- package/dist/pregel/validate.cjs +4 -5
- package/dist/pregel/validate.cjs.map +1 -1
- package/dist/pregel/validate.js +2 -3
- package/dist/pregel/validate.js.map +1 -1
- package/dist/pregel/write.cjs +5 -8
- package/dist/pregel/write.cjs.map +1 -1
- package/dist/pregel/write.js +2 -5
- package/dist/pregel/write.js.map +1 -1
- package/dist/remote.cjs +3 -4
- package/dist/remote.js +1 -2
- package/dist/setup/async_local_storage.cjs +1 -2
- package/dist/setup/async_local_storage.cjs.map +1 -1
- package/dist/setup/async_local_storage.js +1 -2
- package/dist/setup/async_local_storage.js.map +1 -1
- package/dist/state/adapter.cjs +2 -3
- package/dist/state/adapter.cjs.map +1 -1
- package/dist/state/adapter.js +1 -2
- package/dist/state/adapter.js.map +1 -1
- package/dist/state/index.cjs +8 -8
- package/dist/state/index.js +7 -8
- package/dist/state/prebuilt/index.cjs +1 -1
- package/dist/state/prebuilt/index.js +2 -3
- package/dist/state/prebuilt/messages.cjs +3 -4
- package/dist/state/prebuilt/messages.cjs.map +1 -1
- package/dist/state/prebuilt/messages.js +3 -7
- package/dist/state/prebuilt/messages.js.map +1 -1
- package/dist/state/schema.cjs +16 -12
- package/dist/state/schema.cjs.map +1 -1
- package/dist/state/schema.d.cts.map +1 -1
- package/dist/state/schema.d.ts.map +1 -1
- package/dist/state/schema.js +8 -4
- package/dist/state/schema.js.map +1 -1
- package/dist/state/types.cjs +1 -2
- package/dist/state/types.cjs.map +1 -1
- package/dist/state/types.js +1 -1
- package/dist/state/values/index.cjs +2 -2
- package/dist/state/values/index.js +3 -4
- package/dist/state/values/reduced.cjs +1 -2
- package/dist/state/values/reduced.cjs.map +1 -1
- package/dist/state/values/reduced.js +1 -1
- package/dist/state/values/reduced.js.map +1 -1
- package/dist/state/values/untracked.cjs +1 -2
- package/dist/state/values/untracked.cjs.map +1 -1
- package/dist/state/values/untracked.js +1 -1
- package/dist/state/values/untracked.js.map +1 -1
- package/dist/utils.cjs +2 -3
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.js +1 -2
- package/dist/utils.js.map +1 -1
- package/dist/web.cjs +58 -59
- package/dist/web.js +1 -2
- package/dist/writer.cjs +1 -2
- package/dist/writer.cjs.map +1 -1
- package/dist/writer.js +1 -2
- package/dist/writer.js.map +1 -1
- package/package.json +3 -3
package/dist/hash.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,53 +1,51 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value:
|
|
2
|
-
const require_async_local_storage = require(
|
|
3
|
-
const require_constants = require(
|
|
4
|
-
const require_errors = require(
|
|
5
|
-
const require_base = require(
|
|
6
|
-
const require_binop = require(
|
|
7
|
-
const require_annotation = require(
|
|
8
|
-
const require_config = require(
|
|
9
|
-
const require_interrupt = require(
|
|
10
|
-
const require_graph = require(
|
|
11
|
-
const require_types = require(
|
|
12
|
-
const require_adapter = require(
|
|
13
|
-
const require_untracked_value = require(
|
|
14
|
-
const require_reduced = require(
|
|
15
|
-
const require_untracked = require(
|
|
16
|
-
const require_schema = require(
|
|
17
|
-
const require_messages_reducer = require(
|
|
18
|
-
const require_messages = require(
|
|
19
|
-
const require_state = require(
|
|
20
|
-
const require_message = require(
|
|
21
|
-
const require_index = require(
|
|
22
|
-
const require_messages_annotation = require(
|
|
23
|
-
require(
|
|
24
|
-
const require_writer = require(
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_async_local_storage = require("./setup/async_local_storage.cjs");
|
|
3
|
+
const require_constants = require("./constants.cjs");
|
|
4
|
+
const require_errors = require("./errors.cjs");
|
|
5
|
+
const require_base = require("./channels/base.cjs");
|
|
6
|
+
const require_binop = require("./channels/binop.cjs");
|
|
7
|
+
const require_annotation = require("./graph/annotation.cjs");
|
|
8
|
+
const require_config = require("./pregel/utils/config.cjs");
|
|
9
|
+
const require_interrupt = require("./interrupt.cjs");
|
|
10
|
+
const require_graph = require("./graph/graph.cjs");
|
|
11
|
+
const require_types = require("./state/types.cjs");
|
|
12
|
+
const require_adapter = require("./state/adapter.cjs");
|
|
13
|
+
const require_untracked_value = require("./channels/untracked_value.cjs");
|
|
14
|
+
const require_reduced = require("./state/values/reduced.cjs");
|
|
15
|
+
const require_untracked = require("./state/values/untracked.cjs");
|
|
16
|
+
const require_schema = require("./state/schema.cjs");
|
|
17
|
+
const require_messages_reducer = require("./graph/messages_reducer.cjs");
|
|
18
|
+
const require_messages = require("./state/prebuilt/messages.cjs");
|
|
19
|
+
const require_state = require("./graph/state.cjs");
|
|
20
|
+
const require_message = require("./graph/message.cjs");
|
|
21
|
+
const require_index = require("./func/index.cjs");
|
|
22
|
+
const require_messages_annotation = require("./graph/messages_annotation.cjs");
|
|
23
|
+
require("./web.cjs");
|
|
24
|
+
const require_writer = require("./writer.cjs");
|
|
25
25
|
let _langchain_langgraph_checkpoint = require("@langchain/langgraph-checkpoint");
|
|
26
|
-
|
|
27
26
|
//#region src/index.ts
|
|
28
27
|
require_async_local_storage.initializeAsyncLocalStorageSingleton();
|
|
29
|
-
|
|
30
28
|
//#endregion
|
|
31
29
|
exports.Annotation = require_annotation.Annotation;
|
|
32
|
-
Object.defineProperty(exports,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
Object.defineProperty(exports, "AsyncBatchedStore", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function() {
|
|
33
|
+
return _langchain_langgraph_checkpoint.AsyncBatchedStore;
|
|
34
|
+
}
|
|
37
35
|
});
|
|
38
36
|
exports.BaseChannel = require_base.BaseChannel;
|
|
39
|
-
Object.defineProperty(exports,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
Object.defineProperty(exports, "BaseCheckpointSaver", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function() {
|
|
40
|
+
return _langchain_langgraph_checkpoint.BaseCheckpointSaver;
|
|
41
|
+
}
|
|
44
42
|
});
|
|
45
43
|
exports.BaseLangGraphError = require_errors.BaseLangGraphError;
|
|
46
|
-
Object.defineProperty(exports,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
Object.defineProperty(exports, "BaseStore", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function() {
|
|
47
|
+
return _langchain_langgraph_checkpoint.BaseStore;
|
|
48
|
+
}
|
|
51
49
|
});
|
|
52
50
|
exports.BinaryOperatorAggregate = require_binop.BinaryOperatorAggregate;
|
|
53
51
|
exports.COMMAND_SYMBOL = require_constants.COMMAND_SYMBOL;
|
|
@@ -63,18 +61,18 @@ exports.GraphInterrupt = require_errors.GraphInterrupt;
|
|
|
63
61
|
exports.GraphRecursionError = require_errors.GraphRecursionError;
|
|
64
62
|
exports.GraphValueError = require_errors.GraphValueError;
|
|
65
63
|
exports.INTERRUPT = require_constants.INTERRUPT;
|
|
66
|
-
Object.defineProperty(exports,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
Object.defineProperty(exports, "InMemoryStore", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function() {
|
|
67
|
+
return _langchain_langgraph_checkpoint.InMemoryStore;
|
|
68
|
+
}
|
|
71
69
|
});
|
|
72
70
|
exports.InvalidUpdateError = require_errors.InvalidUpdateError;
|
|
73
|
-
Object.defineProperty(exports,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
Object.defineProperty(exports, "MemorySaver", {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
get: function() {
|
|
74
|
+
return _langchain_langgraph_checkpoint.MemorySaver;
|
|
75
|
+
}
|
|
78
76
|
});
|
|
79
77
|
exports.MessageGraph = require_message.MessageGraph;
|
|
80
78
|
exports.MessagesAnnotation = require_messages_annotation.MessagesAnnotation;
|
|
@@ -97,17 +95,17 @@ exports.UnreachableNodeError = require_errors.UnreachableNodeError;
|
|
|
97
95
|
exports.UntrackedValue = require_untracked.UntrackedValue;
|
|
98
96
|
exports.UntrackedValueChannel = require_untracked_value.UntrackedValueChannel;
|
|
99
97
|
exports.addMessages = require_messages_reducer.messagesStateReducer;
|
|
100
|
-
Object.defineProperty(exports,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
98
|
+
Object.defineProperty(exports, "copyCheckpoint", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function() {
|
|
101
|
+
return _langchain_langgraph_checkpoint.copyCheckpoint;
|
|
102
|
+
}
|
|
105
103
|
});
|
|
106
|
-
Object.defineProperty(exports,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
Object.defineProperty(exports, "emptyCheckpoint", {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
get: function() {
|
|
107
|
+
return _langchain_langgraph_checkpoint.emptyCheckpoint;
|
|
108
|
+
}
|
|
111
109
|
});
|
|
112
110
|
exports.entrypoint = require_index.entrypoint;
|
|
113
111
|
exports.getConfig = require_config.getConfig;
|
|
@@ -130,4 +128,5 @@ exports.messagesStateReducer = require_messages_reducer.messagesStateReducer;
|
|
|
130
128
|
exports.pushMessage = require_message.pushMessage;
|
|
131
129
|
exports.task = require_index.task;
|
|
132
130
|
exports.writer = require_writer.writer;
|
|
131
|
+
|
|
133
132
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["initializeAsyncLocalStorageSingleton"],"sources":["../src/index.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\nimport { initializeAsyncLocalStorageSingleton } from \"./setup/async_local_storage.js\";\n\n// Initialize global async local storage instance for tracing\ninitializeAsyncLocalStorageSingleton();\n\nexport * from \"./web.js\";\n\nexport { interrupt } from \"./interrupt.js\";\nexport { writer } from \"./writer.js\";\nexport { pushMessage } from \"./graph/message.js\";\nexport { getStore, getWriter, getConfig } from \"./pregel/utils/config.js\";\nexport { getPreviousState } from \"./func/index.js\";\nexport { getCurrentTaskInput } from \"./pregel/utils/config.js\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["initializeAsyncLocalStorageSingleton"],"sources":["../src/index.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\nimport { initializeAsyncLocalStorageSingleton } from \"./setup/async_local_storage.js\";\n\n// Initialize global async local storage instance for tracing\ninitializeAsyncLocalStorageSingleton();\n\nexport * from \"./web.js\";\n\nexport { interrupt } from \"./interrupt.js\";\nexport { writer } from \"./writer.js\";\nexport { pushMessage } from \"./graph/message.js\";\nexport { getStore, getWriter, getConfig } from \"./pregel/utils/config.js\";\nexport { getPreviousState } from \"./func/index.js\";\nexport { getCurrentTaskInput } from \"./pregel/utils/config.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAKAA,4BAAAA,sCAAsC"}
|
package/dist/index.js
CHANGED
|
@@ -21,10 +21,9 @@ import { entrypoint, getPreviousState, task } from "./func/index.js";
|
|
|
21
21
|
import { MessagesAnnotation, MessagesZodMeta, MessagesZodState } from "./graph/messages_annotation.js";
|
|
22
22
|
import { AsyncBatchedStore, BaseCheckpointSaver, BaseStore, InMemoryStore, MemorySaver, copyCheckpoint, emptyCheckpoint } from "./web.js";
|
|
23
23
|
import { writer } from "./writer.js";
|
|
24
|
-
|
|
25
24
|
//#region src/index.ts
|
|
26
25
|
initializeAsyncLocalStorageSingleton();
|
|
27
|
-
|
|
28
26
|
//#endregion
|
|
29
27
|
export { Annotation, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseStore, BinaryOperatorAggregate, COMMAND_SYMBOL, Command, CommandInstance, CompiledStateGraph, END, EmptyChannelError, EmptyInputError, Graph, GraphBubbleUp, GraphInterrupt, GraphRecursionError, GraphValueError, INTERRUPT, InMemoryStore, InvalidUpdateError, MemorySaver, MessageGraph, MessagesAnnotation, MessagesValue, MessagesZodMeta, MessagesZodState, MultipleSubgraphsError, NodeInterrupt, Overwrite, ParentCommand, REMOVE_ALL_MESSAGES, ReducedValue, RemoteException, START, Send, StateGraph, StateGraphInputError, StateSchema, UnreachableNodeError, UntrackedValue, UntrackedValueChannel, messagesStateReducer as addMessages, copyCheckpoint, emptyCheckpoint, entrypoint, getConfig, getCurrentTaskInput, getJsonSchemaFromSchema, getPreviousState, getSchemaDefaultGetter, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCommand, isGraphBubbleUp, isGraphInterrupt, isInterrupted, isParentCommand, isSerializableSchema, isStandardSchema, messagesStateReducer, pushMessage, task, writer };
|
|
28
|
+
|
|
30
29
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\nimport { initializeAsyncLocalStorageSingleton } from \"./setup/async_local_storage.js\";\n\n// Initialize global async local storage instance for tracing\ninitializeAsyncLocalStorageSingleton();\n\nexport * from \"./web.js\";\n\nexport { interrupt } from \"./interrupt.js\";\nexport { writer } from \"./writer.js\";\nexport { pushMessage } from \"./graph/message.js\";\nexport { getStore, getWriter, getConfig } from \"./pregel/utils/config.js\";\nexport { getPreviousState } from \"./func/index.js\";\nexport { getCurrentTaskInput } from \"./pregel/utils/config.js\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\nimport { initializeAsyncLocalStorageSingleton } from \"./setup/async_local_storage.js\";\n\n// Initialize global async local storage instance for tracing\ninitializeAsyncLocalStorageSingleton();\n\nexport * from \"./web.js\";\n\nexport { interrupt } from \"./interrupt.js\";\nexport { writer } from \"./writer.js\";\nexport { pushMessage } from \"./graph/message.js\";\nexport { getStore, getWriter, getConfig } from \"./pregel/utils/config.js\";\nexport { getPreviousState } from \"./func/index.js\";\nexport { getCurrentTaskInput } from \"./pregel/utils/config.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAKA,sCAAsC"}
|
package/dist/interrupt.cjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
const require_constants = require(
|
|
2
|
-
const require_errors = require(
|
|
3
|
-
const require_hash = require(
|
|
1
|
+
const require_constants = require("./constants.cjs");
|
|
2
|
+
const require_errors = require("./errors.cjs");
|
|
3
|
+
const require_hash = require("./hash.cjs");
|
|
4
4
|
let _langchain_core_singletons = require("@langchain/core/singletons");
|
|
5
|
-
|
|
6
5
|
//#region src/interrupt.ts
|
|
7
6
|
/**
|
|
8
7
|
* Interrupts the execution of a graph node.
|
|
@@ -52,7 +51,7 @@ function interrupt(value) {
|
|
|
52
51
|
if (!config) throw new Error("Called interrupt() outside the context of a graph.");
|
|
53
52
|
const conf = config.configurable;
|
|
54
53
|
if (!conf) throw new Error("No configurable found in config");
|
|
55
|
-
if (!conf[
|
|
54
|
+
if (!conf["__pregel_checkpointer"]) throw new require_errors.GraphValueError("No checkpointer set", { lc_error_code: "MISSING_CHECKPOINTER" });
|
|
56
55
|
const scratchpad = conf[require_constants.CONFIG_KEY_SCRATCHPAD];
|
|
57
56
|
scratchpad.interruptCounter += 1;
|
|
58
57
|
const idx = scratchpad.interruptCounter;
|
|
@@ -67,13 +66,13 @@ function interrupt(value) {
|
|
|
67
66
|
conf[require_constants.CONFIG_KEY_SEND]?.([[require_constants.RESUME, scratchpad.resume]]);
|
|
68
67
|
return v;
|
|
69
68
|
}
|
|
70
|
-
const ns = conf[require_constants.CONFIG_KEY_CHECKPOINT_NS]?.split(
|
|
69
|
+
const ns = conf[require_constants.CONFIG_KEY_CHECKPOINT_NS]?.split("|");
|
|
71
70
|
throw new require_errors.GraphInterrupt([{
|
|
72
|
-
id: ns ? require_hash.XXH3(ns.join(
|
|
71
|
+
id: ns ? require_hash.XXH3(ns.join("|")) : void 0,
|
|
73
72
|
value
|
|
74
73
|
}]);
|
|
75
74
|
}
|
|
76
|
-
|
|
77
75
|
//#endregion
|
|
78
76
|
exports.interrupt = interrupt;
|
|
77
|
+
|
|
79
78
|
//# sourceMappingURL=interrupt.cjs.map
|
package/dist/interrupt.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interrupt.cjs","names":["AsyncLocalStorageProviderSingleton","
|
|
1
|
+
{"version":3,"file":"interrupt.cjs","names":["AsyncLocalStorageProviderSingleton","GraphValueError","CONFIG_KEY_SCRATCHPAD","CONFIG_KEY_SEND","RESUME","CONFIG_KEY_CHECKPOINT_NS","GraphInterrupt","XXH3"],"sources":["../src/interrupt.ts"],"sourcesContent":["import { AsyncLocalStorageProviderSingleton } from \"@langchain/core/singletons\";\nimport { RunnableConfig } from \"@langchain/core/runnables\";\nimport {\n BaseCheckpointSaver,\n type PendingWrite,\n} from \"@langchain/langgraph-checkpoint\";\nimport { GraphInterrupt, GraphValueError } from \"./errors.js\";\nimport {\n CONFIG_KEY_CHECKPOINT_NS,\n CONFIG_KEY_SCRATCHPAD,\n CONFIG_KEY_SEND,\n CONFIG_KEY_CHECKPOINTER,\n CHECKPOINT_NAMESPACE_SEPARATOR,\n RESUME,\n} from \"./constants.js\";\nimport { PregelScratchpad } from \"./pregel/types.js\";\nimport { XXH3 } from \"./hash.js\";\n\n/**\n * Interrupts the execution of a graph node.\n * This function can be used to pause execution of a node, and return the value of the `resume`\n * input when the graph is re-invoked using `Command`.\n * Multiple interrupts can be called within a single node, and each will be handled sequentially.\n *\n * When an interrupt is called:\n * 1. If there's a `resume` value available (from a previous `Command`), it returns that value.\n * 2. Otherwise, it throws a `GraphInterrupt` with the provided value\n * 3. The graph can be resumed by passing a `Command` with a `resume` value\n *\n * Because the `interrupt` function propagates by throwing a special `GraphInterrupt` error,\n * you should avoid using `try/catch` blocks around the `interrupt` function,\n * or if you do, ensure that the `GraphInterrupt` error is thrown again within your `catch` block.\n *\n * @param value - The value to include in the interrupt. This will be available in task.interrupts[].value\n * @returns The `resume` value provided when the graph is re-invoked with a Command\n *\n * @example\n * ```typescript\n * // Define a node that uses multiple interrupts\n * const nodeWithInterrupts = () => {\n * // First interrupt - will pause execution and include {value: 1} in task values\n * const answer1 = interrupt({ value: 1 });\n *\n * // Second interrupt - only called after first interrupt is resumed\n * const answer2 = interrupt({ value: 2 });\n *\n * // Use the resume values\n * return { myKey: answer1 + \" \" + answer2 };\n * };\n *\n * // Resume the graph after first interrupt\n * await graph.stream(new Command({ resume: \"answer 1\" }));\n *\n * // Resume the graph after second interrupt\n * await graph.stream(new Command({ resume: \"answer 2\" }));\n * // Final result: { myKey: \"answer 1 answer 2\" }\n * ```\n *\n * @throws {Error} If called outside the context of a graph\n * @throws {GraphInterrupt} When no resume value is available\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function interrupt<I = unknown, R = any>(value: I): R {\n const config: RunnableConfig | undefined =\n AsyncLocalStorageProviderSingleton.getRunnableConfig();\n if (!config) {\n throw new Error(\"Called interrupt() outside the context of a graph.\");\n }\n\n const conf = config.configurable;\n if (!conf) {\n throw new Error(\"No configurable found in config\");\n }\n\n const checkpointer: BaseCheckpointSaver = conf[CONFIG_KEY_CHECKPOINTER];\n if (!checkpointer) {\n throw new GraphValueError(\"No checkpointer set\", {\n lc_error_code: \"MISSING_CHECKPOINTER\",\n });\n }\n\n // Track interrupt index\n const scratchpad: PregelScratchpad = conf[CONFIG_KEY_SCRATCHPAD];\n scratchpad.interruptCounter += 1;\n const idx = scratchpad.interruptCounter;\n\n // Find previous resume values\n if (scratchpad.resume.length > 0 && idx < scratchpad.resume.length) {\n conf[CONFIG_KEY_SEND]?.([[RESUME, scratchpad.resume] as PendingWrite]);\n return scratchpad.resume[idx] as R;\n }\n\n // Find current resume value\n if (scratchpad.nullResume !== undefined) {\n if (scratchpad.resume.length !== idx) {\n throw new Error(\n `Resume length mismatch: ${scratchpad.resume.length} !== ${idx}`\n );\n }\n const v = scratchpad.consumeNullResume();\n scratchpad.resume.push(v);\n conf[CONFIG_KEY_SEND]?.([[RESUME, scratchpad.resume] as PendingWrite]);\n return v as R;\n }\n\n // No resume value found\n const ns: string[] | undefined = conf[CONFIG_KEY_CHECKPOINT_NS]?.split(\n CHECKPOINT_NAMESPACE_SEPARATOR\n );\n\n const id = ns ? XXH3(ns.join(CHECKPOINT_NAMESPACE_SEPARATOR)) : undefined;\n throw new GraphInterrupt([{ id, value }]);\n}\n\ntype FilterAny<X> = (<T>() => T extends X ? 1 : 2) extends <\n T\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n>() => T extends any ? 1 : 2\n ? never\n : X;\n\nexport type InferInterruptInputType<T> = T extends typeof interrupt<\n infer I,\n unknown\n>\n ? I\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends { [key: string]: typeof interrupt<any, any> }\n ? { [K in keyof T]: InferInterruptInputType<T[K]> }[keyof T]\n : unknown;\n\nexport type InferInterruptResumeType<\n T,\n TInner = false\n> = T extends typeof interrupt<never, infer R>\n ? TInner extends true\n ? FilterAny<R>\n : R\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends { [key: string]: typeof interrupt<any, any> }\n ? { [K in keyof T]: InferInterruptResumeType<T[K], true> }[keyof T]\n : unknown;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,SAAgB,UAAgC,OAAa;CAC3D,MAAM,SACJA,2BAAAA,mCAAmC,mBAAmB;AACxD,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,qDAAqD;CAGvE,MAAM,OAAO,OAAO;AACpB,KAAI,CAAC,KACH,OAAM,IAAI,MAAM,kCAAkC;AAIpD,KAAI,CADsC,KAAA,yBAExC,OAAM,IAAIC,eAAAA,gBAAgB,uBAAuB,EAC/C,eAAe,wBAChB,CAAC;CAIJ,MAAM,aAA+B,KAAKC,kBAAAA;AAC1C,YAAW,oBAAoB;CAC/B,MAAM,MAAM,WAAW;AAGvB,KAAI,WAAW,OAAO,SAAS,KAAK,MAAM,WAAW,OAAO,QAAQ;AAClE,OAAKC,kBAAAA,mBAAmB,CAAC,CAACC,kBAAAA,QAAQ,WAAW,OAAO,CAAiB,CAAC;AACtE,SAAO,WAAW,OAAO;;AAI3B,KAAI,WAAW,eAAe,KAAA,GAAW;AACvC,MAAI,WAAW,OAAO,WAAW,IAC/B,OAAM,IAAI,MACR,2BAA2B,WAAW,OAAO,OAAO,OAAO,MAC5D;EAEH,MAAM,IAAI,WAAW,mBAAmB;AACxC,aAAW,OAAO,KAAK,EAAE;AACzB,OAAKD,kBAAAA,mBAAmB,CAAC,CAACC,kBAAAA,QAAQ,WAAW,OAAO,CAAiB,CAAC;AACtE,SAAO;;CAIT,MAAM,KAA2B,KAAKC,kBAAAA,2BAA2B,MAAA,IAEhE;AAGD,OAAM,IAAIC,eAAAA,eAAe,CAAC;EAAE,IADjB,KAAKC,aAAAA,KAAK,GAAG,KAAA,IAAoC,CAAC,GAAG,KAAA;EAChC;EAAO,CAAC,CAAC"}
|
package/dist/interrupt.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CONFIG_KEY_CHECKPOINT_NS, CONFIG_KEY_SCRATCHPAD, CONFIG_KEY_SEND, RESUME } from "./constants.js";
|
|
2
2
|
import { GraphInterrupt, GraphValueError } from "./errors.js";
|
|
3
3
|
import { XXH3 } from "./hash.js";
|
|
4
4
|
import { AsyncLocalStorageProviderSingleton } from "@langchain/core/singletons";
|
|
5
|
-
|
|
6
5
|
//#region src/interrupt.ts
|
|
7
6
|
/**
|
|
8
7
|
* Interrupts the execution of a graph node.
|
|
@@ -52,7 +51,7 @@ function interrupt(value) {
|
|
|
52
51
|
if (!config) throw new Error("Called interrupt() outside the context of a graph.");
|
|
53
52
|
const conf = config.configurable;
|
|
54
53
|
if (!conf) throw new Error("No configurable found in config");
|
|
55
|
-
if (!conf[
|
|
54
|
+
if (!conf["__pregel_checkpointer"]) throw new GraphValueError("No checkpointer set", { lc_error_code: "MISSING_CHECKPOINTER" });
|
|
56
55
|
const scratchpad = conf[CONFIG_KEY_SCRATCHPAD];
|
|
57
56
|
scratchpad.interruptCounter += 1;
|
|
58
57
|
const idx = scratchpad.interruptCounter;
|
|
@@ -67,13 +66,13 @@ function interrupt(value) {
|
|
|
67
66
|
conf[CONFIG_KEY_SEND]?.([[RESUME, scratchpad.resume]]);
|
|
68
67
|
return v;
|
|
69
68
|
}
|
|
70
|
-
const ns = conf[CONFIG_KEY_CHECKPOINT_NS]?.split(
|
|
69
|
+
const ns = conf[CONFIG_KEY_CHECKPOINT_NS]?.split("|");
|
|
71
70
|
throw new GraphInterrupt([{
|
|
72
|
-
id: ns ? XXH3(ns.join(
|
|
71
|
+
id: ns ? XXH3(ns.join("|")) : void 0,
|
|
73
72
|
value
|
|
74
73
|
}]);
|
|
75
74
|
}
|
|
76
|
-
|
|
77
75
|
//#endregion
|
|
78
76
|
export { interrupt };
|
|
77
|
+
|
|
79
78
|
//# sourceMappingURL=interrupt.js.map
|
package/dist/interrupt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interrupt.js","names":[],"sources":["../src/interrupt.ts"],"sourcesContent":["import { AsyncLocalStorageProviderSingleton } from \"@langchain/core/singletons\";\nimport { RunnableConfig } from \"@langchain/core/runnables\";\nimport {\n BaseCheckpointSaver,\n type PendingWrite,\n} from \"@langchain/langgraph-checkpoint\";\nimport { GraphInterrupt, GraphValueError } from \"./errors.js\";\nimport {\n CONFIG_KEY_CHECKPOINT_NS,\n CONFIG_KEY_SCRATCHPAD,\n CONFIG_KEY_SEND,\n CONFIG_KEY_CHECKPOINTER,\n CHECKPOINT_NAMESPACE_SEPARATOR,\n RESUME,\n} from \"./constants.js\";\nimport { PregelScratchpad } from \"./pregel/types.js\";\nimport { XXH3 } from \"./hash.js\";\n\n/**\n * Interrupts the execution of a graph node.\n * This function can be used to pause execution of a node, and return the value of the `resume`\n * input when the graph is re-invoked using `Command`.\n * Multiple interrupts can be called within a single node, and each will be handled sequentially.\n *\n * When an interrupt is called:\n * 1. If there's a `resume` value available (from a previous `Command`), it returns that value.\n * 2. Otherwise, it throws a `GraphInterrupt` with the provided value\n * 3. The graph can be resumed by passing a `Command` with a `resume` value\n *\n * Because the `interrupt` function propagates by throwing a special `GraphInterrupt` error,\n * you should avoid using `try/catch` blocks around the `interrupt` function,\n * or if you do, ensure that the `GraphInterrupt` error is thrown again within your `catch` block.\n *\n * @param value - The value to include in the interrupt. This will be available in task.interrupts[].value\n * @returns The `resume` value provided when the graph is re-invoked with a Command\n *\n * @example\n * ```typescript\n * // Define a node that uses multiple interrupts\n * const nodeWithInterrupts = () => {\n * // First interrupt - will pause execution and include {value: 1} in task values\n * const answer1 = interrupt({ value: 1 });\n *\n * // Second interrupt - only called after first interrupt is resumed\n * const answer2 = interrupt({ value: 2 });\n *\n * // Use the resume values\n * return { myKey: answer1 + \" \" + answer2 };\n * };\n *\n * // Resume the graph after first interrupt\n * await graph.stream(new Command({ resume: \"answer 1\" }));\n *\n * // Resume the graph after second interrupt\n * await graph.stream(new Command({ resume: \"answer 2\" }));\n * // Final result: { myKey: \"answer 1 answer 2\" }\n * ```\n *\n * @throws {Error} If called outside the context of a graph\n * @throws {GraphInterrupt} When no resume value is available\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function interrupt<I = unknown, R = any>(value: I): R {\n const config: RunnableConfig | undefined =\n AsyncLocalStorageProviderSingleton.getRunnableConfig();\n if (!config) {\n throw new Error(\"Called interrupt() outside the context of a graph.\");\n }\n\n const conf = config.configurable;\n if (!conf) {\n throw new Error(\"No configurable found in config\");\n }\n\n const checkpointer: BaseCheckpointSaver = conf[CONFIG_KEY_CHECKPOINTER];\n if (!checkpointer) {\n throw new GraphValueError(\"No checkpointer set\", {\n lc_error_code: \"MISSING_CHECKPOINTER\",\n });\n }\n\n // Track interrupt index\n const scratchpad: PregelScratchpad = conf[CONFIG_KEY_SCRATCHPAD];\n scratchpad.interruptCounter += 1;\n const idx = scratchpad.interruptCounter;\n\n // Find previous resume values\n if (scratchpad.resume.length > 0 && idx < scratchpad.resume.length) {\n conf[CONFIG_KEY_SEND]?.([[RESUME, scratchpad.resume] as PendingWrite]);\n return scratchpad.resume[idx] as R;\n }\n\n // Find current resume value\n if (scratchpad.nullResume !== undefined) {\n if (scratchpad.resume.length !== idx) {\n throw new Error(\n `Resume length mismatch: ${scratchpad.resume.length} !== ${idx}`\n );\n }\n const v = scratchpad.consumeNullResume();\n scratchpad.resume.push(v);\n conf[CONFIG_KEY_SEND]?.([[RESUME, scratchpad.resume] as PendingWrite]);\n return v as R;\n }\n\n // No resume value found\n const ns: string[] | undefined = conf[CONFIG_KEY_CHECKPOINT_NS]?.split(\n CHECKPOINT_NAMESPACE_SEPARATOR\n );\n\n const id = ns ? XXH3(ns.join(CHECKPOINT_NAMESPACE_SEPARATOR)) : undefined;\n throw new GraphInterrupt([{ id, value }]);\n}\n\ntype FilterAny<X> = (<T>() => T extends X ? 1 : 2) extends <\n T\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n>() => T extends any ? 1 : 2\n ? never\n : X;\n\nexport type InferInterruptInputType<T> = T extends typeof interrupt<\n infer I,\n unknown\n>\n ? I\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends { [key: string]: typeof interrupt<any, any> }\n ? { [K in keyof T]: InferInterruptInputType<T[K]> }[keyof T]\n : unknown;\n\nexport type InferInterruptResumeType<\n T,\n TInner = false\n> = T extends typeof interrupt<never, infer R>\n ? TInner extends true\n ? FilterAny<R>\n : R\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends { [key: string]: typeof interrupt<any, any> }\n ? { [K in keyof T]: InferInterruptResumeType<T[K], true> }[keyof T]\n : unknown;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"interrupt.js","names":[],"sources":["../src/interrupt.ts"],"sourcesContent":["import { AsyncLocalStorageProviderSingleton } from \"@langchain/core/singletons\";\nimport { RunnableConfig } from \"@langchain/core/runnables\";\nimport {\n BaseCheckpointSaver,\n type PendingWrite,\n} from \"@langchain/langgraph-checkpoint\";\nimport { GraphInterrupt, GraphValueError } from \"./errors.js\";\nimport {\n CONFIG_KEY_CHECKPOINT_NS,\n CONFIG_KEY_SCRATCHPAD,\n CONFIG_KEY_SEND,\n CONFIG_KEY_CHECKPOINTER,\n CHECKPOINT_NAMESPACE_SEPARATOR,\n RESUME,\n} from \"./constants.js\";\nimport { PregelScratchpad } from \"./pregel/types.js\";\nimport { XXH3 } from \"./hash.js\";\n\n/**\n * Interrupts the execution of a graph node.\n * This function can be used to pause execution of a node, and return the value of the `resume`\n * input when the graph is re-invoked using `Command`.\n * Multiple interrupts can be called within a single node, and each will be handled sequentially.\n *\n * When an interrupt is called:\n * 1. If there's a `resume` value available (from a previous `Command`), it returns that value.\n * 2. Otherwise, it throws a `GraphInterrupt` with the provided value\n * 3. The graph can be resumed by passing a `Command` with a `resume` value\n *\n * Because the `interrupt` function propagates by throwing a special `GraphInterrupt` error,\n * you should avoid using `try/catch` blocks around the `interrupt` function,\n * or if you do, ensure that the `GraphInterrupt` error is thrown again within your `catch` block.\n *\n * @param value - The value to include in the interrupt. This will be available in task.interrupts[].value\n * @returns The `resume` value provided when the graph is re-invoked with a Command\n *\n * @example\n * ```typescript\n * // Define a node that uses multiple interrupts\n * const nodeWithInterrupts = () => {\n * // First interrupt - will pause execution and include {value: 1} in task values\n * const answer1 = interrupt({ value: 1 });\n *\n * // Second interrupt - only called after first interrupt is resumed\n * const answer2 = interrupt({ value: 2 });\n *\n * // Use the resume values\n * return { myKey: answer1 + \" \" + answer2 };\n * };\n *\n * // Resume the graph after first interrupt\n * await graph.stream(new Command({ resume: \"answer 1\" }));\n *\n * // Resume the graph after second interrupt\n * await graph.stream(new Command({ resume: \"answer 2\" }));\n * // Final result: { myKey: \"answer 1 answer 2\" }\n * ```\n *\n * @throws {Error} If called outside the context of a graph\n * @throws {GraphInterrupt} When no resume value is available\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function interrupt<I = unknown, R = any>(value: I): R {\n const config: RunnableConfig | undefined =\n AsyncLocalStorageProviderSingleton.getRunnableConfig();\n if (!config) {\n throw new Error(\"Called interrupt() outside the context of a graph.\");\n }\n\n const conf = config.configurable;\n if (!conf) {\n throw new Error(\"No configurable found in config\");\n }\n\n const checkpointer: BaseCheckpointSaver = conf[CONFIG_KEY_CHECKPOINTER];\n if (!checkpointer) {\n throw new GraphValueError(\"No checkpointer set\", {\n lc_error_code: \"MISSING_CHECKPOINTER\",\n });\n }\n\n // Track interrupt index\n const scratchpad: PregelScratchpad = conf[CONFIG_KEY_SCRATCHPAD];\n scratchpad.interruptCounter += 1;\n const idx = scratchpad.interruptCounter;\n\n // Find previous resume values\n if (scratchpad.resume.length > 0 && idx < scratchpad.resume.length) {\n conf[CONFIG_KEY_SEND]?.([[RESUME, scratchpad.resume] as PendingWrite]);\n return scratchpad.resume[idx] as R;\n }\n\n // Find current resume value\n if (scratchpad.nullResume !== undefined) {\n if (scratchpad.resume.length !== idx) {\n throw new Error(\n `Resume length mismatch: ${scratchpad.resume.length} !== ${idx}`\n );\n }\n const v = scratchpad.consumeNullResume();\n scratchpad.resume.push(v);\n conf[CONFIG_KEY_SEND]?.([[RESUME, scratchpad.resume] as PendingWrite]);\n return v as R;\n }\n\n // No resume value found\n const ns: string[] | undefined = conf[CONFIG_KEY_CHECKPOINT_NS]?.split(\n CHECKPOINT_NAMESPACE_SEPARATOR\n );\n\n const id = ns ? XXH3(ns.join(CHECKPOINT_NAMESPACE_SEPARATOR)) : undefined;\n throw new GraphInterrupt([{ id, value }]);\n}\n\ntype FilterAny<X> = (<T>() => T extends X ? 1 : 2) extends <\n T\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n>() => T extends any ? 1 : 2\n ? never\n : X;\n\nexport type InferInterruptInputType<T> = T extends typeof interrupt<\n infer I,\n unknown\n>\n ? I\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends { [key: string]: typeof interrupt<any, any> }\n ? { [K in keyof T]: InferInterruptInputType<T[K]> }[keyof T]\n : unknown;\n\nexport type InferInterruptResumeType<\n T,\n TInner = false\n> = T extends typeof interrupt<never, infer R>\n ? TInner extends true\n ? FilterAny<R>\n : R\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends { [key: string]: typeof interrupt<any, any> }\n ? { [K in keyof T]: InferInterruptResumeType<T[K], true> }[keyof T]\n : unknown;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,SAAgB,UAAgC,OAAa;CAC3D,MAAM,SACJ,mCAAmC,mBAAmB;AACxD,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,qDAAqD;CAGvE,MAAM,OAAO,OAAO;AACpB,KAAI,CAAC,KACH,OAAM,IAAI,MAAM,kCAAkC;AAIpD,KAAI,CADsC,KAAA,yBAExC,OAAM,IAAI,gBAAgB,uBAAuB,EAC/C,eAAe,wBAChB,CAAC;CAIJ,MAAM,aAA+B,KAAK;AAC1C,YAAW,oBAAoB;CAC/B,MAAM,MAAM,WAAW;AAGvB,KAAI,WAAW,OAAO,SAAS,KAAK,MAAM,WAAW,OAAO,QAAQ;AAClE,OAAK,mBAAmB,CAAC,CAAC,QAAQ,WAAW,OAAO,CAAiB,CAAC;AACtE,SAAO,WAAW,OAAO;;AAI3B,KAAI,WAAW,eAAe,KAAA,GAAW;AACvC,MAAI,WAAW,OAAO,WAAW,IAC/B,OAAM,IAAI,MACR,2BAA2B,WAAW,OAAO,OAAO,OAAO,MAC5D;EAEH,MAAM,IAAI,WAAW,mBAAmB;AACxC,aAAW,OAAO,KAAK,EAAE;AACzB,OAAK,mBAAmB,CAAC,CAAC,QAAQ,WAAW,OAAO,CAAiB,CAAC;AACtE,SAAO;;CAIT,MAAM,KAA2B,KAAK,2BAA2B,MAAA,IAEhE;AAGD,OAAM,IAAI,eAAe,CAAC;EAAE,IADjB,KAAK,KAAK,GAAG,KAAA,IAAoC,CAAC,GAAG,KAAA;EAChC;EAAO,CAAC,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
let _langchain_core_runnables = require("@langchain/core/runnables");
|
|
2
2
|
let _langchain_core_messages = require("@langchain/core/messages");
|
|
3
|
-
|
|
4
3
|
//#region src/prebuilt/agentName.ts
|
|
5
4
|
const NAME_PATTERN = /<name>(.*?)<\/name>/s;
|
|
6
5
|
const CONTENT_PATTERN = /<content>(.*?)<\/content>/s;
|
|
@@ -142,7 +141,7 @@ function withAgentName(model, agentNameMode) {
|
|
|
142
141
|
_langchain_core_runnables.RunnableLambda.from(processOutputMessage)
|
|
143
142
|
]);
|
|
144
143
|
}
|
|
145
|
-
|
|
146
144
|
//#endregion
|
|
147
145
|
exports.withAgentName = withAgentName;
|
|
146
|
+
|
|
148
147
|
//# sourceMappingURL=agentName.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentName.cjs","names":["AIMessage","RunnableSequence","RunnableLambda"],"sources":["../../src/prebuilt/agentName.ts"],"sourcesContent":["import { LanguageModelLike } from \"@langchain/core/language_models/base\";\nimport {\n AIMessage,\n AIMessageFields,\n BaseMessage,\n BaseMessageLike,\n isAIMessage,\n isAIMessageChunk,\n isBaseMessage,\n isBaseMessageChunk,\n MessageContent,\n} from \"@langchain/core/messages\";\nimport { RunnableLambda, RunnableSequence } from \"@langchain/core/runnables\";\n\nconst NAME_PATTERN = /<name>(.*?)<\\/name>/s;\nconst CONTENT_PATTERN = /<content>(.*?)<\\/content>/s;\n\nexport type AgentNameMode = \"inline\";\n\n/**\n * Attach formatted agent names to the messages passed to and from a language model.\n *\n * This is useful for making a message history with multiple agents more coherent.\n *\n * NOTE: agent name is consumed from the message.name field.\n * If you're using an agent built with createReactAgent, name is automatically set.\n * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.\n *\n * @deprecated migrated to `langchain` package.\n *\n * @param message - Message to add agent name formatting to\n * @returns Message with agent name formatting\n *\n * @internal\n */\nexport function _addInlineAgentName<T extends BaseMessageLike>(\n message: T\n): T | AIMessage {\n const isAI =\n isBaseMessage(message) &&\n (isAIMessage(message) ||\n (isBaseMessageChunk(message) && isAIMessageChunk(message)));\n\n if (!isAI || !message.name) {\n return message;\n }\n\n const { name } = message;\n\n if (typeof message.content === \"string\") {\n const fields = (\n Object.keys(message.lc_kwargs ?? {}).length > 0\n ? message.lc_kwargs\n : message\n ) as AIMessageFields;\n\n return new AIMessage({\n ...fields,\n content: `<name>${name}</name><content>${message.content}</content>`,\n name: undefined,\n });\n }\n\n const updatedContent = [];\n let textBlockCount = 0;\n\n for (const contentBlock of message.content) {\n if (typeof contentBlock === \"string\") {\n textBlockCount += 1;\n updatedContent.push(\n `<name>${name}</name><content>${contentBlock}</content>`\n );\n } else if (\n typeof contentBlock === \"object\" &&\n \"type\" in contentBlock &&\n contentBlock.type === \"text\"\n ) {\n textBlockCount += 1;\n updatedContent.push({\n ...contentBlock,\n text: `<name>${name}</name><content>${contentBlock.text}</content>`,\n });\n } else {\n updatedContent.push(contentBlock);\n }\n }\n\n if (!textBlockCount) {\n updatedContent.unshift({\n type: \"text\",\n text: `<name>${name}</name><content></content>`,\n });\n }\n return new AIMessage({\n ...message.lc_kwargs,\n content: updatedContent as MessageContent,\n name: undefined,\n });\n}\n\n/**\n * Remove explicit name and content XML tags from the AI message content.\n *\n * @deprecated migrated to `langchain` package.\n *\n * Examples:\n *\n * @example\n * ```typescript\n * removeInlineAgentName(new AIMessage({ content: \"<name>assistant</name><content>Hello</content>\", name: \"assistant\" }))\n * // AIMessage with content: \"Hello\"\n *\n * removeInlineAgentName(new AIMessage({ content: [{type: \"text\", text: \"<name>assistant</name><content>Hello</content>\"}], name: \"assistant\" }))\n * // AIMessage with content: [{type: \"text\", text: \"Hello\"}]\n * ```\n *\n * @internal\n */\nexport function _removeInlineAgentName<T extends BaseMessage>(message: T): T {\n if (!isAIMessage(message) || !message.content) {\n return message;\n }\n\n let updatedContent: MessageContent = [];\n let updatedName: string | undefined;\n\n if (Array.isArray(message.content)) {\n updatedContent = message.content\n .filter((block) => {\n if (block.type === \"text\" && typeof block.text === \"string\") {\n const nameMatch = block.text.match(NAME_PATTERN);\n const contentMatch = block.text.match(CONTENT_PATTERN);\n // don't include empty content blocks that were added because there was no text block to modify\n if (nameMatch && (!contentMatch || contentMatch[1] === \"\")) {\n // capture name from text block\n // eslint-disable-next-line prefer-destructuring\n updatedName = nameMatch[1];\n return false;\n }\n return true;\n }\n return true;\n })\n .map((block) => {\n if (block.type === \"text\" && typeof block.text === \"string\") {\n const nameMatch = block.text.match(NAME_PATTERN);\n const contentMatch = block.text.match(CONTENT_PATTERN);\n\n if (!nameMatch || !contentMatch) {\n return block;\n }\n\n // capture name from text block\n // eslint-disable-next-line prefer-destructuring\n updatedName = nameMatch[1];\n\n return {\n ...block,\n text: contentMatch[1],\n };\n }\n return block;\n });\n } else {\n const content = message.content as string;\n const nameMatch = content.match(NAME_PATTERN);\n const contentMatch = content.match(CONTENT_PATTERN);\n\n if (!nameMatch || !contentMatch) {\n return message;\n }\n\n // eslint-disable-next-line prefer-destructuring\n updatedName = nameMatch[1];\n // eslint-disable-next-line prefer-destructuring\n updatedContent = contentMatch[1];\n }\n\n return new AIMessage({\n ...(Object.keys(message.lc_kwargs ?? {}).length > 0\n ? message.lc_kwargs\n : message),\n content: updatedContent,\n name: updatedName,\n }) as T;\n}\n\n/**\n * Attach formatted agent names to the messages passed to and from a language model.\n *\n * This is useful for making a message history with multiple agents more coherent.\n *\n * * @deprecated migrated to `langchain` package.\n *\n * NOTE: agent name is consumed from the message.name field.\n * If you're using an agent built with createReactAgent, name is automatically set.\n * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.\n *\n * @param model - Language model to add agent name formatting to\n * @param agentNameMode - How to expose the agent name to the LLM\n * - \"inline\": Add the agent name directly into the content field of the AI message using XML-style tags.\n * Example: \"How can I help you\" -> \"<name>agent_name</name><content>How can I help you?</content>\".\n */\nexport function withAgentName(\n model: LanguageModelLike,\n agentNameMode: AgentNameMode\n): LanguageModelLike {\n let processInputMessage: (message: BaseMessageLike) => BaseMessageLike;\n let processOutputMessage: (message: BaseMessage) => BaseMessage;\n\n if (agentNameMode === \"inline\") {\n processInputMessage = _addInlineAgentName;\n processOutputMessage = _removeInlineAgentName;\n } else {\n throw new Error(\n `Invalid agent name mode: ${agentNameMode}. Needs to be one of: \"inline\"`\n );\n }\n\n function processInputMessages(\n messages: BaseMessageLike[]\n ): BaseMessageLike[] {\n return messages.map(processInputMessage);\n }\n\n return RunnableSequence.from([\n RunnableLambda.from(processInputMessages),\n model,\n RunnableLambda.from(processOutputMessage),\n ]);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"agentName.cjs","names":["AIMessage","RunnableSequence","RunnableLambda"],"sources":["../../src/prebuilt/agentName.ts"],"sourcesContent":["import { LanguageModelLike } from \"@langchain/core/language_models/base\";\nimport {\n AIMessage,\n AIMessageFields,\n BaseMessage,\n BaseMessageLike,\n isAIMessage,\n isAIMessageChunk,\n isBaseMessage,\n isBaseMessageChunk,\n MessageContent,\n} from \"@langchain/core/messages\";\nimport { RunnableLambda, RunnableSequence } from \"@langchain/core/runnables\";\n\nconst NAME_PATTERN = /<name>(.*?)<\\/name>/s;\nconst CONTENT_PATTERN = /<content>(.*?)<\\/content>/s;\n\nexport type AgentNameMode = \"inline\";\n\n/**\n * Attach formatted agent names to the messages passed to and from a language model.\n *\n * This is useful for making a message history with multiple agents more coherent.\n *\n * NOTE: agent name is consumed from the message.name field.\n * If you're using an agent built with createReactAgent, name is automatically set.\n * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.\n *\n * @deprecated migrated to `langchain` package.\n *\n * @param message - Message to add agent name formatting to\n * @returns Message with agent name formatting\n *\n * @internal\n */\nexport function _addInlineAgentName<T extends BaseMessageLike>(\n message: T\n): T | AIMessage {\n const isAI =\n isBaseMessage(message) &&\n (isAIMessage(message) ||\n (isBaseMessageChunk(message) && isAIMessageChunk(message)));\n\n if (!isAI || !message.name) {\n return message;\n }\n\n const { name } = message;\n\n if (typeof message.content === \"string\") {\n const fields = (\n Object.keys(message.lc_kwargs ?? {}).length > 0\n ? message.lc_kwargs\n : message\n ) as AIMessageFields;\n\n return new AIMessage({\n ...fields,\n content: `<name>${name}</name><content>${message.content}</content>`,\n name: undefined,\n });\n }\n\n const updatedContent = [];\n let textBlockCount = 0;\n\n for (const contentBlock of message.content) {\n if (typeof contentBlock === \"string\") {\n textBlockCount += 1;\n updatedContent.push(\n `<name>${name}</name><content>${contentBlock}</content>`\n );\n } else if (\n typeof contentBlock === \"object\" &&\n \"type\" in contentBlock &&\n contentBlock.type === \"text\"\n ) {\n textBlockCount += 1;\n updatedContent.push({\n ...contentBlock,\n text: `<name>${name}</name><content>${contentBlock.text}</content>`,\n });\n } else {\n updatedContent.push(contentBlock);\n }\n }\n\n if (!textBlockCount) {\n updatedContent.unshift({\n type: \"text\",\n text: `<name>${name}</name><content></content>`,\n });\n }\n return new AIMessage({\n ...message.lc_kwargs,\n content: updatedContent as MessageContent,\n name: undefined,\n });\n}\n\n/**\n * Remove explicit name and content XML tags from the AI message content.\n *\n * @deprecated migrated to `langchain` package.\n *\n * Examples:\n *\n * @example\n * ```typescript\n * removeInlineAgentName(new AIMessage({ content: \"<name>assistant</name><content>Hello</content>\", name: \"assistant\" }))\n * // AIMessage with content: \"Hello\"\n *\n * removeInlineAgentName(new AIMessage({ content: [{type: \"text\", text: \"<name>assistant</name><content>Hello</content>\"}], name: \"assistant\" }))\n * // AIMessage with content: [{type: \"text\", text: \"Hello\"}]\n * ```\n *\n * @internal\n */\nexport function _removeInlineAgentName<T extends BaseMessage>(message: T): T {\n if (!isAIMessage(message) || !message.content) {\n return message;\n }\n\n let updatedContent: MessageContent = [];\n let updatedName: string | undefined;\n\n if (Array.isArray(message.content)) {\n updatedContent = message.content\n .filter((block) => {\n if (block.type === \"text\" && typeof block.text === \"string\") {\n const nameMatch = block.text.match(NAME_PATTERN);\n const contentMatch = block.text.match(CONTENT_PATTERN);\n // don't include empty content blocks that were added because there was no text block to modify\n if (nameMatch && (!contentMatch || contentMatch[1] === \"\")) {\n // capture name from text block\n // eslint-disable-next-line prefer-destructuring\n updatedName = nameMatch[1];\n return false;\n }\n return true;\n }\n return true;\n })\n .map((block) => {\n if (block.type === \"text\" && typeof block.text === \"string\") {\n const nameMatch = block.text.match(NAME_PATTERN);\n const contentMatch = block.text.match(CONTENT_PATTERN);\n\n if (!nameMatch || !contentMatch) {\n return block;\n }\n\n // capture name from text block\n // eslint-disable-next-line prefer-destructuring\n updatedName = nameMatch[1];\n\n return {\n ...block,\n text: contentMatch[1],\n };\n }\n return block;\n });\n } else {\n const content = message.content as string;\n const nameMatch = content.match(NAME_PATTERN);\n const contentMatch = content.match(CONTENT_PATTERN);\n\n if (!nameMatch || !contentMatch) {\n return message;\n }\n\n // eslint-disable-next-line prefer-destructuring\n updatedName = nameMatch[1];\n // eslint-disable-next-line prefer-destructuring\n updatedContent = contentMatch[1];\n }\n\n return new AIMessage({\n ...(Object.keys(message.lc_kwargs ?? {}).length > 0\n ? message.lc_kwargs\n : message),\n content: updatedContent,\n name: updatedName,\n }) as T;\n}\n\n/**\n * Attach formatted agent names to the messages passed to and from a language model.\n *\n * This is useful for making a message history with multiple agents more coherent.\n *\n * * @deprecated migrated to `langchain` package.\n *\n * NOTE: agent name is consumed from the message.name field.\n * If you're using an agent built with createReactAgent, name is automatically set.\n * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.\n *\n * @param model - Language model to add agent name formatting to\n * @param agentNameMode - How to expose the agent name to the LLM\n * - \"inline\": Add the agent name directly into the content field of the AI message using XML-style tags.\n * Example: \"How can I help you\" -> \"<name>agent_name</name><content>How can I help you?</content>\".\n */\nexport function withAgentName(\n model: LanguageModelLike,\n agentNameMode: AgentNameMode\n): LanguageModelLike {\n let processInputMessage: (message: BaseMessageLike) => BaseMessageLike;\n let processOutputMessage: (message: BaseMessage) => BaseMessage;\n\n if (agentNameMode === \"inline\") {\n processInputMessage = _addInlineAgentName;\n processOutputMessage = _removeInlineAgentName;\n } else {\n throw new Error(\n `Invalid agent name mode: ${agentNameMode}. Needs to be one of: \"inline\"`\n );\n }\n\n function processInputMessages(\n messages: BaseMessageLike[]\n ): BaseMessageLike[] {\n return messages.map(processInputMessage);\n }\n\n return RunnableSequence.from([\n RunnableLambda.from(processInputMessages),\n model,\n RunnableLambda.from(processOutputMessage),\n ]);\n}\n"],"mappings":"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"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { RunnableLambda, RunnableSequence } from "@langchain/core/runnables";
|
|
2
2
|
import { AIMessage, isAIMessage, isAIMessageChunk, isBaseMessage, isBaseMessageChunk } from "@langchain/core/messages";
|
|
3
|
-
|
|
4
3
|
//#region src/prebuilt/agentName.ts
|
|
5
4
|
const NAME_PATTERN = /<name>(.*?)<\/name>/s;
|
|
6
5
|
const CONTENT_PATTERN = /<content>(.*?)<\/content>/s;
|
|
@@ -142,7 +141,7 @@ function withAgentName(model, agentNameMode) {
|
|
|
142
141
|
RunnableLambda.from(processOutputMessage)
|
|
143
142
|
]);
|
|
144
143
|
}
|
|
145
|
-
|
|
146
144
|
//#endregion
|
|
147
145
|
export { withAgentName };
|
|
146
|
+
|
|
148
147
|
//# sourceMappingURL=agentName.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentName.js","names":[],"sources":["../../src/prebuilt/agentName.ts"],"sourcesContent":["import { LanguageModelLike } from \"@langchain/core/language_models/base\";\nimport {\n AIMessage,\n AIMessageFields,\n BaseMessage,\n BaseMessageLike,\n isAIMessage,\n isAIMessageChunk,\n isBaseMessage,\n isBaseMessageChunk,\n MessageContent,\n} from \"@langchain/core/messages\";\nimport { RunnableLambda, RunnableSequence } from \"@langchain/core/runnables\";\n\nconst NAME_PATTERN = /<name>(.*?)<\\/name>/s;\nconst CONTENT_PATTERN = /<content>(.*?)<\\/content>/s;\n\nexport type AgentNameMode = \"inline\";\n\n/**\n * Attach formatted agent names to the messages passed to and from a language model.\n *\n * This is useful for making a message history with multiple agents more coherent.\n *\n * NOTE: agent name is consumed from the message.name field.\n * If you're using an agent built with createReactAgent, name is automatically set.\n * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.\n *\n * @deprecated migrated to `langchain` package.\n *\n * @param message - Message to add agent name formatting to\n * @returns Message with agent name formatting\n *\n * @internal\n */\nexport function _addInlineAgentName<T extends BaseMessageLike>(\n message: T\n): T | AIMessage {\n const isAI =\n isBaseMessage(message) &&\n (isAIMessage(message) ||\n (isBaseMessageChunk(message) && isAIMessageChunk(message)));\n\n if (!isAI || !message.name) {\n return message;\n }\n\n const { name } = message;\n\n if (typeof message.content === \"string\") {\n const fields = (\n Object.keys(message.lc_kwargs ?? {}).length > 0\n ? message.lc_kwargs\n : message\n ) as AIMessageFields;\n\n return new AIMessage({\n ...fields,\n content: `<name>${name}</name><content>${message.content}</content>`,\n name: undefined,\n });\n }\n\n const updatedContent = [];\n let textBlockCount = 0;\n\n for (const contentBlock of message.content) {\n if (typeof contentBlock === \"string\") {\n textBlockCount += 1;\n updatedContent.push(\n `<name>${name}</name><content>${contentBlock}</content>`\n );\n } else if (\n typeof contentBlock === \"object\" &&\n \"type\" in contentBlock &&\n contentBlock.type === \"text\"\n ) {\n textBlockCount += 1;\n updatedContent.push({\n ...contentBlock,\n text: `<name>${name}</name><content>${contentBlock.text}</content>`,\n });\n } else {\n updatedContent.push(contentBlock);\n }\n }\n\n if (!textBlockCount) {\n updatedContent.unshift({\n type: \"text\",\n text: `<name>${name}</name><content></content>`,\n });\n }\n return new AIMessage({\n ...message.lc_kwargs,\n content: updatedContent as MessageContent,\n name: undefined,\n });\n}\n\n/**\n * Remove explicit name and content XML tags from the AI message content.\n *\n * @deprecated migrated to `langchain` package.\n *\n * Examples:\n *\n * @example\n * ```typescript\n * removeInlineAgentName(new AIMessage({ content: \"<name>assistant</name><content>Hello</content>\", name: \"assistant\" }))\n * // AIMessage with content: \"Hello\"\n *\n * removeInlineAgentName(new AIMessage({ content: [{type: \"text\", text: \"<name>assistant</name><content>Hello</content>\"}], name: \"assistant\" }))\n * // AIMessage with content: [{type: \"text\", text: \"Hello\"}]\n * ```\n *\n * @internal\n */\nexport function _removeInlineAgentName<T extends BaseMessage>(message: T): T {\n if (!isAIMessage(message) || !message.content) {\n return message;\n }\n\n let updatedContent: MessageContent = [];\n let updatedName: string | undefined;\n\n if (Array.isArray(message.content)) {\n updatedContent = message.content\n .filter((block) => {\n if (block.type === \"text\" && typeof block.text === \"string\") {\n const nameMatch = block.text.match(NAME_PATTERN);\n const contentMatch = block.text.match(CONTENT_PATTERN);\n // don't include empty content blocks that were added because there was no text block to modify\n if (nameMatch && (!contentMatch || contentMatch[1] === \"\")) {\n // capture name from text block\n // eslint-disable-next-line prefer-destructuring\n updatedName = nameMatch[1];\n return false;\n }\n return true;\n }\n return true;\n })\n .map((block) => {\n if (block.type === \"text\" && typeof block.text === \"string\") {\n const nameMatch = block.text.match(NAME_PATTERN);\n const contentMatch = block.text.match(CONTENT_PATTERN);\n\n if (!nameMatch || !contentMatch) {\n return block;\n }\n\n // capture name from text block\n // eslint-disable-next-line prefer-destructuring\n updatedName = nameMatch[1];\n\n return {\n ...block,\n text: contentMatch[1],\n };\n }\n return block;\n });\n } else {\n const content = message.content as string;\n const nameMatch = content.match(NAME_PATTERN);\n const contentMatch = content.match(CONTENT_PATTERN);\n\n if (!nameMatch || !contentMatch) {\n return message;\n }\n\n // eslint-disable-next-line prefer-destructuring\n updatedName = nameMatch[1];\n // eslint-disable-next-line prefer-destructuring\n updatedContent = contentMatch[1];\n }\n\n return new AIMessage({\n ...(Object.keys(message.lc_kwargs ?? {}).length > 0\n ? message.lc_kwargs\n : message),\n content: updatedContent,\n name: updatedName,\n }) as T;\n}\n\n/**\n * Attach formatted agent names to the messages passed to and from a language model.\n *\n * This is useful for making a message history with multiple agents more coherent.\n *\n * * @deprecated migrated to `langchain` package.\n *\n * NOTE: agent name is consumed from the message.name field.\n * If you're using an agent built with createReactAgent, name is automatically set.\n * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.\n *\n * @param model - Language model to add agent name formatting to\n * @param agentNameMode - How to expose the agent name to the LLM\n * - \"inline\": Add the agent name directly into the content field of the AI message using XML-style tags.\n * Example: \"How can I help you\" -> \"<name>agent_name</name><content>How can I help you?</content>\".\n */\nexport function withAgentName(\n model: LanguageModelLike,\n agentNameMode: AgentNameMode\n): LanguageModelLike {\n let processInputMessage: (message: BaseMessageLike) => BaseMessageLike;\n let processOutputMessage: (message: BaseMessage) => BaseMessage;\n\n if (agentNameMode === \"inline\") {\n processInputMessage = _addInlineAgentName;\n processOutputMessage = _removeInlineAgentName;\n } else {\n throw new Error(\n `Invalid agent name mode: ${agentNameMode}. Needs to be one of: \"inline\"`\n );\n }\n\n function processInputMessages(\n messages: BaseMessageLike[]\n ): BaseMessageLike[] {\n return messages.map(processInputMessage);\n }\n\n return RunnableSequence.from([\n RunnableLambda.from(processInputMessages),\n model,\n RunnableLambda.from(processOutputMessage),\n ]);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"agentName.js","names":[],"sources":["../../src/prebuilt/agentName.ts"],"sourcesContent":["import { LanguageModelLike } from \"@langchain/core/language_models/base\";\nimport {\n AIMessage,\n AIMessageFields,\n BaseMessage,\n BaseMessageLike,\n isAIMessage,\n isAIMessageChunk,\n isBaseMessage,\n isBaseMessageChunk,\n MessageContent,\n} from \"@langchain/core/messages\";\nimport { RunnableLambda, RunnableSequence } from \"@langchain/core/runnables\";\n\nconst NAME_PATTERN = /<name>(.*?)<\\/name>/s;\nconst CONTENT_PATTERN = /<content>(.*?)<\\/content>/s;\n\nexport type AgentNameMode = \"inline\";\n\n/**\n * Attach formatted agent names to the messages passed to and from a language model.\n *\n * This is useful for making a message history with multiple agents more coherent.\n *\n * NOTE: agent name is consumed from the message.name field.\n * If you're using an agent built with createReactAgent, name is automatically set.\n * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.\n *\n * @deprecated migrated to `langchain` package.\n *\n * @param message - Message to add agent name formatting to\n * @returns Message with agent name formatting\n *\n * @internal\n */\nexport function _addInlineAgentName<T extends BaseMessageLike>(\n message: T\n): T | AIMessage {\n const isAI =\n isBaseMessage(message) &&\n (isAIMessage(message) ||\n (isBaseMessageChunk(message) && isAIMessageChunk(message)));\n\n if (!isAI || !message.name) {\n return message;\n }\n\n const { name } = message;\n\n if (typeof message.content === \"string\") {\n const fields = (\n Object.keys(message.lc_kwargs ?? {}).length > 0\n ? message.lc_kwargs\n : message\n ) as AIMessageFields;\n\n return new AIMessage({\n ...fields,\n content: `<name>${name}</name><content>${message.content}</content>`,\n name: undefined,\n });\n }\n\n const updatedContent = [];\n let textBlockCount = 0;\n\n for (const contentBlock of message.content) {\n if (typeof contentBlock === \"string\") {\n textBlockCount += 1;\n updatedContent.push(\n `<name>${name}</name><content>${contentBlock}</content>`\n );\n } else if (\n typeof contentBlock === \"object\" &&\n \"type\" in contentBlock &&\n contentBlock.type === \"text\"\n ) {\n textBlockCount += 1;\n updatedContent.push({\n ...contentBlock,\n text: `<name>${name}</name><content>${contentBlock.text}</content>`,\n });\n } else {\n updatedContent.push(contentBlock);\n }\n }\n\n if (!textBlockCount) {\n updatedContent.unshift({\n type: \"text\",\n text: `<name>${name}</name><content></content>`,\n });\n }\n return new AIMessage({\n ...message.lc_kwargs,\n content: updatedContent as MessageContent,\n name: undefined,\n });\n}\n\n/**\n * Remove explicit name and content XML tags from the AI message content.\n *\n * @deprecated migrated to `langchain` package.\n *\n * Examples:\n *\n * @example\n * ```typescript\n * removeInlineAgentName(new AIMessage({ content: \"<name>assistant</name><content>Hello</content>\", name: \"assistant\" }))\n * // AIMessage with content: \"Hello\"\n *\n * removeInlineAgentName(new AIMessage({ content: [{type: \"text\", text: \"<name>assistant</name><content>Hello</content>\"}], name: \"assistant\" }))\n * // AIMessage with content: [{type: \"text\", text: \"Hello\"}]\n * ```\n *\n * @internal\n */\nexport function _removeInlineAgentName<T extends BaseMessage>(message: T): T {\n if (!isAIMessage(message) || !message.content) {\n return message;\n }\n\n let updatedContent: MessageContent = [];\n let updatedName: string | undefined;\n\n if (Array.isArray(message.content)) {\n updatedContent = message.content\n .filter((block) => {\n if (block.type === \"text\" && typeof block.text === \"string\") {\n const nameMatch = block.text.match(NAME_PATTERN);\n const contentMatch = block.text.match(CONTENT_PATTERN);\n // don't include empty content blocks that were added because there was no text block to modify\n if (nameMatch && (!contentMatch || contentMatch[1] === \"\")) {\n // capture name from text block\n // eslint-disable-next-line prefer-destructuring\n updatedName = nameMatch[1];\n return false;\n }\n return true;\n }\n return true;\n })\n .map((block) => {\n if (block.type === \"text\" && typeof block.text === \"string\") {\n const nameMatch = block.text.match(NAME_PATTERN);\n const contentMatch = block.text.match(CONTENT_PATTERN);\n\n if (!nameMatch || !contentMatch) {\n return block;\n }\n\n // capture name from text block\n // eslint-disable-next-line prefer-destructuring\n updatedName = nameMatch[1];\n\n return {\n ...block,\n text: contentMatch[1],\n };\n }\n return block;\n });\n } else {\n const content = message.content as string;\n const nameMatch = content.match(NAME_PATTERN);\n const contentMatch = content.match(CONTENT_PATTERN);\n\n if (!nameMatch || !contentMatch) {\n return message;\n }\n\n // eslint-disable-next-line prefer-destructuring\n updatedName = nameMatch[1];\n // eslint-disable-next-line prefer-destructuring\n updatedContent = contentMatch[1];\n }\n\n return new AIMessage({\n ...(Object.keys(message.lc_kwargs ?? {}).length > 0\n ? message.lc_kwargs\n : message),\n content: updatedContent,\n name: updatedName,\n }) as T;\n}\n\n/**\n * Attach formatted agent names to the messages passed to and from a language model.\n *\n * This is useful for making a message history with multiple agents more coherent.\n *\n * * @deprecated migrated to `langchain` package.\n *\n * NOTE: agent name is consumed from the message.name field.\n * If you're using an agent built with createReactAgent, name is automatically set.\n * If you're building a custom agent, make sure to set the name on the AI message returned by the LLM.\n *\n * @param model - Language model to add agent name formatting to\n * @param agentNameMode - How to expose the agent name to the LLM\n * - \"inline\": Add the agent name directly into the content field of the AI message using XML-style tags.\n * Example: \"How can I help you\" -> \"<name>agent_name</name><content>How can I help you?</content>\".\n */\nexport function withAgentName(\n model: LanguageModelLike,\n agentNameMode: AgentNameMode\n): LanguageModelLike {\n let processInputMessage: (message: BaseMessageLike) => BaseMessageLike;\n let processOutputMessage: (message: BaseMessage) => BaseMessage;\n\n if (agentNameMode === \"inline\") {\n processInputMessage = _addInlineAgentName;\n processOutputMessage = _removeInlineAgentName;\n } else {\n throw new Error(\n `Invalid agent name mode: ${agentNameMode}. Needs to be one of: \"inline\"`\n );\n }\n\n function processInputMessages(\n messages: BaseMessageLike[]\n ): BaseMessageLike[] {\n return messages.map(processInputMessage);\n }\n\n return RunnableSequence.from([\n RunnableLambda.from(processInputMessages),\n model,\n RunnableLambda.from(processOutputMessage),\n ]);\n}\n"],"mappings":"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"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
const require_constants = require(
|
|
2
|
-
const require_state = require(
|
|
3
|
-
const require_tool_executor = require(
|
|
4
|
-
|
|
1
|
+
const require_constants = require("../constants.cjs");
|
|
2
|
+
const require_state = require("../graph/state.cjs");
|
|
3
|
+
const require_tool_executor = require("./tool_executor.cjs");
|
|
5
4
|
//#region src/prebuilt/agent_executor.ts
|
|
6
5
|
/** @ignore */
|
|
7
6
|
function createAgentExecutor({ agentRunnable, tools }) {
|
|
@@ -35,7 +34,7 @@ function createAgentExecutor({ agentRunnable, tools }) {
|
|
|
35
34
|
end: require_constants.END
|
|
36
35
|
}).addEdge("action", "agent").compile();
|
|
37
36
|
}
|
|
38
|
-
|
|
39
37
|
//#endregion
|
|
40
38
|
exports.createAgentExecutor = createAgentExecutor;
|
|
39
|
+
|
|
41
40
|
//# sourceMappingURL=agent_executor.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent_executor.cjs","names":["ToolExecutor","StateGraph","START","END"],"sources":["../../src/prebuilt/agent_executor.ts"],"sourcesContent":["import { AgentAction, AgentFinish } from \"@langchain/core/agents\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { Runnable, type RunnableConfig } from \"@langchain/core/runnables\";\nimport { Tool } from \"@langchain/core/tools\";\nimport { ToolExecutor } from \"./tool_executor.js\";\nimport { StateGraph } from \"../graph/state.js\";\nimport { END, START } from \"../constants.js\";\nimport type { BaseChannel } from \"../channels/base.js\";\n\ninterface Step {\n action: AgentAction | AgentFinish;\n observation: unknown;\n}\n\n/** @ignore */\nexport interface AgentExecutorState {\n agentOutcome?: AgentAction | AgentFinish;\n steps: Array<Step>;\n input: string;\n chatHistory?: BaseMessage[];\n}\n\n/** @ignore */\nexport function createAgentExecutor({\n agentRunnable,\n tools,\n}: {\n agentRunnable: Runnable;\n tools: Array<Tool> | ToolExecutor;\n}) {\n let toolExecutor: ToolExecutor;\n if (!Array.isArray(tools)) {\n toolExecutor = tools;\n } else {\n toolExecutor = new ToolExecutor({\n tools,\n });\n }\n\n // Define logic that will be used to determine which conditional edge to go down\n const shouldContinue = (data: AgentExecutorState) => {\n if (data.agentOutcome && \"returnValues\" in data.agentOutcome) {\n return \"end\";\n }\n return \"continue\";\n };\n\n const runAgent = async (\n data: AgentExecutorState,\n config?: RunnableConfig\n ) => {\n const agentOutcome = await agentRunnable.invoke(data, config);\n return {\n agentOutcome,\n };\n };\n\n const executeTools = async (\n data: AgentExecutorState,\n config?: RunnableConfig\n ): Promise<Partial<AgentExecutorState>> => {\n const agentAction = data.agentOutcome;\n if (!agentAction || \"returnValues\" in agentAction) {\n throw new Error(\"Agent has not been run yet\");\n }\n const output = await toolExecutor.invoke(agentAction, config);\n return {\n steps: [{ action: agentAction, observation: output }],\n };\n };\n\n // Define a new graph\n const workflow = new StateGraph<{\n [K in keyof AgentExecutorState]: BaseChannel<\n AgentExecutorState[K],\n AgentExecutorState[K]\n >;\n }>({\n channels: {\n input: null,\n agentOutcome: null,\n steps: {\n reducer: (x: Step[], y: Step[]) => x.concat(y),\n default: () => [] as Step[],\n },\n },\n })\n // Define the two nodes we will cycle between\n .addNode(\"agent\", runAgent)\n .addNode(\"action\", executeTools)\n // Set the entrypoint as `agent`\n // This means that this node is the first one called\n .addEdge(START, \"agent\")\n // We now add a conditional edge\n .addConditionalEdges(\n // First, we define the start node. We use `agent`.\n // This means these are the edges taken after the `agent` node is called.\n \"agent\",\n // Next, we pass in the function that will determine which node is called next.\n shouldContinue,\n // Finally we pass in a mapping.\n // The keys are strings, and the values are other nodes.\n // END is a special node marking that the graph should finish.\n // What will happen is we will call `should_continue`, and then the output of that\n // will be matched against the keys in this mapping.\n // Based on which one it matches, that node will then be called.\n {\n // If `tools`, then we call the tool node.\n continue: \"action\",\n // Otherwise we finish.\n end: END,\n }\n )\n // We now add a normal edge from `tools` to `agent`.\n // This means that after `tools` is called, `agent` node is called next.\n .addEdge(\"action\", \"agent\");\n\n return workflow.compile();\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent_executor.cjs","names":["ToolExecutor","StateGraph","START","END"],"sources":["../../src/prebuilt/agent_executor.ts"],"sourcesContent":["import { AgentAction, AgentFinish } from \"@langchain/core/agents\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { Runnable, type RunnableConfig } from \"@langchain/core/runnables\";\nimport { Tool } from \"@langchain/core/tools\";\nimport { ToolExecutor } from \"./tool_executor.js\";\nimport { StateGraph } from \"../graph/state.js\";\nimport { END, START } from \"../constants.js\";\nimport type { BaseChannel } from \"../channels/base.js\";\n\ninterface Step {\n action: AgentAction | AgentFinish;\n observation: unknown;\n}\n\n/** @ignore */\nexport interface AgentExecutorState {\n agentOutcome?: AgentAction | AgentFinish;\n steps: Array<Step>;\n input: string;\n chatHistory?: BaseMessage[];\n}\n\n/** @ignore */\nexport function createAgentExecutor({\n agentRunnable,\n tools,\n}: {\n agentRunnable: Runnable;\n tools: Array<Tool> | ToolExecutor;\n}) {\n let toolExecutor: ToolExecutor;\n if (!Array.isArray(tools)) {\n toolExecutor = tools;\n } else {\n toolExecutor = new ToolExecutor({\n tools,\n });\n }\n\n // Define logic that will be used to determine which conditional edge to go down\n const shouldContinue = (data: AgentExecutorState) => {\n if (data.agentOutcome && \"returnValues\" in data.agentOutcome) {\n return \"end\";\n }\n return \"continue\";\n };\n\n const runAgent = async (\n data: AgentExecutorState,\n config?: RunnableConfig\n ) => {\n const agentOutcome = await agentRunnable.invoke(data, config);\n return {\n agentOutcome,\n };\n };\n\n const executeTools = async (\n data: AgentExecutorState,\n config?: RunnableConfig\n ): Promise<Partial<AgentExecutorState>> => {\n const agentAction = data.agentOutcome;\n if (!agentAction || \"returnValues\" in agentAction) {\n throw new Error(\"Agent has not been run yet\");\n }\n const output = await toolExecutor.invoke(agentAction, config);\n return {\n steps: [{ action: agentAction, observation: output }],\n };\n };\n\n // Define a new graph\n const workflow = new StateGraph<{\n [K in keyof AgentExecutorState]: BaseChannel<\n AgentExecutorState[K],\n AgentExecutorState[K]\n >;\n }>({\n channels: {\n input: null,\n agentOutcome: null,\n steps: {\n reducer: (x: Step[], y: Step[]) => x.concat(y),\n default: () => [] as Step[],\n },\n },\n })\n // Define the two nodes we will cycle between\n .addNode(\"agent\", runAgent)\n .addNode(\"action\", executeTools)\n // Set the entrypoint as `agent`\n // This means that this node is the first one called\n .addEdge(START, \"agent\")\n // We now add a conditional edge\n .addConditionalEdges(\n // First, we define the start node. We use `agent`.\n // This means these are the edges taken after the `agent` node is called.\n \"agent\",\n // Next, we pass in the function that will determine which node is called next.\n shouldContinue,\n // Finally we pass in a mapping.\n // The keys are strings, and the values are other nodes.\n // END is a special node marking that the graph should finish.\n // What will happen is we will call `should_continue`, and then the output of that\n // will be matched against the keys in this mapping.\n // Based on which one it matches, that node will then be called.\n {\n // If `tools`, then we call the tool node.\n continue: \"action\",\n // Otherwise we finish.\n end: END,\n }\n )\n // We now add a normal edge from `tools` to `agent`.\n // This means that after `tools` is called, `agent` node is called next.\n .addEdge(\"action\", \"agent\");\n\n return workflow.compile();\n}\n"],"mappings":";;;;;AAuBA,SAAgB,oBAAoB,EAClC,eACA,SAIC;CACD,IAAI;AACJ,KAAI,CAAC,MAAM,QAAQ,MAAM,CACvB,gBAAe;KAEf,gBAAe,IAAIA,sBAAAA,aAAa,EAC9B,OACD,CAAC;CAIJ,MAAM,kBAAkB,SAA6B;AACnD,MAAI,KAAK,gBAAgB,kBAAkB,KAAK,aAC9C,QAAO;AAET,SAAO;;CAGT,MAAM,WAAW,OACf,MACA,WACG;AAEH,SAAO,EACL,cAFmB,MAAM,cAAc,OAAO,MAAM,OAAO,EAG5D;;CAGH,MAAM,eAAe,OACnB,MACA,WACyC;EACzC,MAAM,cAAc,KAAK;AACzB,MAAI,CAAC,eAAe,kBAAkB,YACpC,OAAM,IAAI,MAAM,6BAA6B;AAG/C,SAAO,EACL,OAAO,CAAC;GAAE,QAAQ;GAAa,aAFlB,MAAM,aAAa,OAAO,aAAa,OAAO;GAEP,CAAC,EACtD;;AAiDH,QA7CiB,IAAIC,cAAAA,WAKlB,EACD,UAAU;EACR,OAAO;EACP,cAAc;EACd,OAAO;GACL,UAAU,GAAW,MAAc,EAAE,OAAO,EAAE;GAC9C,eAAe,EAAE;GAClB;EACF,EACF,CAAC,CAEC,QAAQ,SAAS,SAAS,CAC1B,QAAQ,UAAU,aAAa,CAG/B,QAAQC,kBAAAA,OAAO,QAAQ,CAEvB,oBAGC,SAEA,gBAOA;EAEE,UAAU;EAEV,KAAKC,kBAAAA;EACN,CACF,CAGA,QAAQ,UAAU,QAAQ,CAEb,SAAS"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { END, START } from "../constants.js";
|
|
2
2
|
import { StateGraph } from "../graph/state.js";
|
|
3
3
|
import { ToolExecutor } from "./tool_executor.js";
|
|
4
|
-
|
|
5
4
|
//#region src/prebuilt/agent_executor.ts
|
|
6
5
|
/** @ignore */
|
|
7
6
|
function createAgentExecutor({ agentRunnable, tools }) {
|
|
@@ -35,7 +34,7 @@ function createAgentExecutor({ agentRunnable, tools }) {
|
|
|
35
34
|
end: END
|
|
36
35
|
}).addEdge("action", "agent").compile();
|
|
37
36
|
}
|
|
38
|
-
|
|
39
37
|
//#endregion
|
|
40
38
|
export { createAgentExecutor };
|
|
39
|
+
|
|
41
40
|
//# sourceMappingURL=agent_executor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent_executor.js","names":[],"sources":["../../src/prebuilt/agent_executor.ts"],"sourcesContent":["import { AgentAction, AgentFinish } from \"@langchain/core/agents\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { Runnable, type RunnableConfig } from \"@langchain/core/runnables\";\nimport { Tool } from \"@langchain/core/tools\";\nimport { ToolExecutor } from \"./tool_executor.js\";\nimport { StateGraph } from \"../graph/state.js\";\nimport { END, START } from \"../constants.js\";\nimport type { BaseChannel } from \"../channels/base.js\";\n\ninterface Step {\n action: AgentAction | AgentFinish;\n observation: unknown;\n}\n\n/** @ignore */\nexport interface AgentExecutorState {\n agentOutcome?: AgentAction | AgentFinish;\n steps: Array<Step>;\n input: string;\n chatHistory?: BaseMessage[];\n}\n\n/** @ignore */\nexport function createAgentExecutor({\n agentRunnable,\n tools,\n}: {\n agentRunnable: Runnable;\n tools: Array<Tool> | ToolExecutor;\n}) {\n let toolExecutor: ToolExecutor;\n if (!Array.isArray(tools)) {\n toolExecutor = tools;\n } else {\n toolExecutor = new ToolExecutor({\n tools,\n });\n }\n\n // Define logic that will be used to determine which conditional edge to go down\n const shouldContinue = (data: AgentExecutorState) => {\n if (data.agentOutcome && \"returnValues\" in data.agentOutcome) {\n return \"end\";\n }\n return \"continue\";\n };\n\n const runAgent = async (\n data: AgentExecutorState,\n config?: RunnableConfig\n ) => {\n const agentOutcome = await agentRunnable.invoke(data, config);\n return {\n agentOutcome,\n };\n };\n\n const executeTools = async (\n data: AgentExecutorState,\n config?: RunnableConfig\n ): Promise<Partial<AgentExecutorState>> => {\n const agentAction = data.agentOutcome;\n if (!agentAction || \"returnValues\" in agentAction) {\n throw new Error(\"Agent has not been run yet\");\n }\n const output = await toolExecutor.invoke(agentAction, config);\n return {\n steps: [{ action: agentAction, observation: output }],\n };\n };\n\n // Define a new graph\n const workflow = new StateGraph<{\n [K in keyof AgentExecutorState]: BaseChannel<\n AgentExecutorState[K],\n AgentExecutorState[K]\n >;\n }>({\n channels: {\n input: null,\n agentOutcome: null,\n steps: {\n reducer: (x: Step[], y: Step[]) => x.concat(y),\n default: () => [] as Step[],\n },\n },\n })\n // Define the two nodes we will cycle between\n .addNode(\"agent\", runAgent)\n .addNode(\"action\", executeTools)\n // Set the entrypoint as `agent`\n // This means that this node is the first one called\n .addEdge(START, \"agent\")\n // We now add a conditional edge\n .addConditionalEdges(\n // First, we define the start node. We use `agent`.\n // This means these are the edges taken after the `agent` node is called.\n \"agent\",\n // Next, we pass in the function that will determine which node is called next.\n shouldContinue,\n // Finally we pass in a mapping.\n // The keys are strings, and the values are other nodes.\n // END is a special node marking that the graph should finish.\n // What will happen is we will call `should_continue`, and then the output of that\n // will be matched against the keys in this mapping.\n // Based on which one it matches, that node will then be called.\n {\n // If `tools`, then we call the tool node.\n continue: \"action\",\n // Otherwise we finish.\n end: END,\n }\n )\n // We now add a normal edge from `tools` to `agent`.\n // This means that after `tools` is called, `agent` node is called next.\n .addEdge(\"action\", \"agent\");\n\n return workflow.compile();\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent_executor.js","names":[],"sources":["../../src/prebuilt/agent_executor.ts"],"sourcesContent":["import { AgentAction, AgentFinish } from \"@langchain/core/agents\";\nimport { BaseMessage } from \"@langchain/core/messages\";\nimport { Runnable, type RunnableConfig } from \"@langchain/core/runnables\";\nimport { Tool } from \"@langchain/core/tools\";\nimport { ToolExecutor } from \"./tool_executor.js\";\nimport { StateGraph } from \"../graph/state.js\";\nimport { END, START } from \"../constants.js\";\nimport type { BaseChannel } from \"../channels/base.js\";\n\ninterface Step {\n action: AgentAction | AgentFinish;\n observation: unknown;\n}\n\n/** @ignore */\nexport interface AgentExecutorState {\n agentOutcome?: AgentAction | AgentFinish;\n steps: Array<Step>;\n input: string;\n chatHistory?: BaseMessage[];\n}\n\n/** @ignore */\nexport function createAgentExecutor({\n agentRunnable,\n tools,\n}: {\n agentRunnable: Runnable;\n tools: Array<Tool> | ToolExecutor;\n}) {\n let toolExecutor: ToolExecutor;\n if (!Array.isArray(tools)) {\n toolExecutor = tools;\n } else {\n toolExecutor = new ToolExecutor({\n tools,\n });\n }\n\n // Define logic that will be used to determine which conditional edge to go down\n const shouldContinue = (data: AgentExecutorState) => {\n if (data.agentOutcome && \"returnValues\" in data.agentOutcome) {\n return \"end\";\n }\n return \"continue\";\n };\n\n const runAgent = async (\n data: AgentExecutorState,\n config?: RunnableConfig\n ) => {\n const agentOutcome = await agentRunnable.invoke(data, config);\n return {\n agentOutcome,\n };\n };\n\n const executeTools = async (\n data: AgentExecutorState,\n config?: RunnableConfig\n ): Promise<Partial<AgentExecutorState>> => {\n const agentAction = data.agentOutcome;\n if (!agentAction || \"returnValues\" in agentAction) {\n throw new Error(\"Agent has not been run yet\");\n }\n const output = await toolExecutor.invoke(agentAction, config);\n return {\n steps: [{ action: agentAction, observation: output }],\n };\n };\n\n // Define a new graph\n const workflow = new StateGraph<{\n [K in keyof AgentExecutorState]: BaseChannel<\n AgentExecutorState[K],\n AgentExecutorState[K]\n >;\n }>({\n channels: {\n input: null,\n agentOutcome: null,\n steps: {\n reducer: (x: Step[], y: Step[]) => x.concat(y),\n default: () => [] as Step[],\n },\n },\n })\n // Define the two nodes we will cycle between\n .addNode(\"agent\", runAgent)\n .addNode(\"action\", executeTools)\n // Set the entrypoint as `agent`\n // This means that this node is the first one called\n .addEdge(START, \"agent\")\n // We now add a conditional edge\n .addConditionalEdges(\n // First, we define the start node. We use `agent`.\n // This means these are the edges taken after the `agent` node is called.\n \"agent\",\n // Next, we pass in the function that will determine which node is called next.\n shouldContinue,\n // Finally we pass in a mapping.\n // The keys are strings, and the values are other nodes.\n // END is a special node marking that the graph should finish.\n // What will happen is we will call `should_continue`, and then the output of that\n // will be matched against the keys in this mapping.\n // Based on which one it matches, that node will then be called.\n {\n // If `tools`, then we call the tool node.\n continue: \"action\",\n // Otherwise we finish.\n end: END,\n }\n )\n // We now add a normal edge from `tools` to `agent`.\n // This means that after `tools` is called, `agent` node is called next.\n .addEdge(\"action\", \"agent\");\n\n return workflow.compile();\n}\n"],"mappings":";;;;;AAuBA,SAAgB,oBAAoB,EAClC,eACA,SAIC;CACD,IAAI;AACJ,KAAI,CAAC,MAAM,QAAQ,MAAM,CACvB,gBAAe;KAEf,gBAAe,IAAI,aAAa,EAC9B,OACD,CAAC;CAIJ,MAAM,kBAAkB,SAA6B;AACnD,MAAI,KAAK,gBAAgB,kBAAkB,KAAK,aAC9C,QAAO;AAET,SAAO;;CAGT,MAAM,WAAW,OACf,MACA,WACG;AAEH,SAAO,EACL,cAFmB,MAAM,cAAc,OAAO,MAAM,OAAO,EAG5D;;CAGH,MAAM,eAAe,OACnB,MACA,WACyC;EACzC,MAAM,cAAc,KAAK;AACzB,MAAI,CAAC,eAAe,kBAAkB,YACpC,OAAM,IAAI,MAAM,6BAA6B;AAG/C,SAAO,EACL,OAAO,CAAC;GAAE,QAAQ;GAAa,aAFlB,MAAM,aAAa,OAAO,aAAa,OAAO;GAEP,CAAC,EACtD;;AAiDH,QA7CiB,IAAI,WAKlB,EACD,UAAU;EACR,OAAO;EACP,cAAc;EACd,OAAO;GACL,UAAU,GAAW,MAAc,EAAE,OAAO,EAAE;GAC9C,eAAe,EAAE;GAClB;EACF,EACF,CAAC,CAEC,QAAQ,SAAS,SAAS,CAC1B,QAAQ,UAAU,aAAa,CAG/B,QAAQ,OAAO,QAAQ,CAEvB,oBAGC,SAEA,gBAOA;EAEE,UAAU;EAEV,KAAK;EACN,CACF,CAGA,QAAQ,UAAU,QAAQ,CAEb,SAAS"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
const require_constants = require(
|
|
2
|
-
const require_state = require(
|
|
3
|
-
const require_tool_executor = require(
|
|
1
|
+
const require_constants = require("../constants.cjs");
|
|
2
|
+
const require_state = require("../graph/state.cjs");
|
|
3
|
+
const require_tool_executor = require("./tool_executor.cjs");
|
|
4
4
|
let _langchain_core_runnables = require("@langchain/core/runnables");
|
|
5
5
|
let _langchain_core_messages = require("@langchain/core/messages");
|
|
6
6
|
let _langchain_core_utils_function_calling = require("@langchain/core/utils/function_calling");
|
|
7
|
-
|
|
8
7
|
//#region src/prebuilt/chat_agent_executor.ts
|
|
9
8
|
/** @deprecated Use {@link createReactAgent} instead with tool calling. */
|
|
10
9
|
function createFunctionCallingExecutor({ model, tools }) {
|
|
@@ -56,7 +55,7 @@ function createFunctionCallingExecutor({ model, tools }) {
|
|
|
56
55
|
end: require_constants.END
|
|
57
56
|
}).addEdge("action", "agent").compile();
|
|
58
57
|
}
|
|
59
|
-
|
|
60
58
|
//#endregion
|
|
61
59
|
exports.createFunctionCallingExecutor = createFunctionCallingExecutor;
|
|
60
|
+
|
|
62
61
|
//# sourceMappingURL=chat_agent_executor.cjs.map
|