@langchain/langgraph 0.2.40 → 0.2.42
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/README.md +237 -154
- package/dist/channels/any_value.cjs +10 -10
- package/dist/channels/any_value.d.ts +1 -1
- package/dist/channels/any_value.js +10 -10
- package/dist/channels/ephemeral_value.cjs +10 -9
- package/dist/channels/ephemeral_value.d.ts +1 -1
- package/dist/channels/ephemeral_value.js +10 -9
- package/dist/channels/last_value.cjs +8 -7
- package/dist/channels/last_value.d.ts +1 -1
- package/dist/channels/last_value.js +8 -7
- package/dist/constants.cjs +33 -6
- package/dist/constants.d.ts +17 -2
- package/dist/constants.js +32 -5
- package/dist/errors.d.ts +3 -3
- package/dist/func/index.cjs +272 -0
- package/dist/func/index.d.ts +310 -0
- package/dist/func/index.js +267 -0
- package/dist/func/types.cjs +15 -0
- package/dist/func/types.d.ts +59 -0
- package/dist/func/types.js +11 -0
- package/dist/graph/graph.cjs +31 -35
- package/dist/graph/graph.d.ts +1 -5
- package/dist/graph/graph.js +1 -5
- package/dist/graph/index.cjs +1 -3
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/index.js +1 -1
- package/dist/graph/message.d.ts +1 -1
- package/dist/graph/state.cjs +17 -17
- package/dist/graph/state.d.ts +2 -1
- package/dist/graph/state.js +2 -2
- package/dist/index.cjs +8 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/interrupt.cjs +21 -34
- package/dist/interrupt.d.ts +1 -1
- package/dist/interrupt.js +22 -35
- package/dist/prebuilt/agent_executor.cjs +3 -3
- package/dist/prebuilt/agent_executor.d.ts +1 -1
- package/dist/prebuilt/agent_executor.js +1 -1
- package/dist/prebuilt/chat_agent_executor.cjs +3 -3
- package/dist/prebuilt/chat_agent_executor.d.ts +1 -1
- package/dist/prebuilt/chat_agent_executor.js +1 -1
- package/dist/prebuilt/react_agent_executor.cjs +79 -12
- package/dist/prebuilt/react_agent_executor.d.ts +35 -4
- package/dist/prebuilt/react_agent_executor.js +79 -13
- package/dist/prebuilt/tool_node.cjs +1 -2
- package/dist/prebuilt/tool_node.d.ts +1 -1
- package/dist/prebuilt/tool_node.js +1 -2
- package/dist/pregel/algo.cjs +121 -12
- package/dist/pregel/algo.d.ts +8 -6
- package/dist/pregel/algo.js +122 -13
- package/dist/pregel/call.cjs +77 -0
- package/dist/pregel/call.d.ts +15 -0
- package/dist/pregel/call.js +71 -0
- package/dist/pregel/index.cjs +59 -96
- package/dist/pregel/index.d.ts +1 -10
- package/dist/pregel/index.js +61 -98
- package/dist/pregel/io.cjs +6 -1
- package/dist/pregel/io.js +7 -2
- package/dist/pregel/loop.cjs +109 -75
- package/dist/pregel/loop.d.ts +17 -23
- package/dist/pregel/loop.js +110 -75
- package/dist/pregel/messages.d.ts +1 -1
- package/dist/pregel/retry.cjs +22 -50
- package/dist/pregel/retry.d.ts +6 -6
- package/dist/pregel/retry.js +22 -50
- package/dist/pregel/runner.cjs +275 -0
- package/dist/pregel/runner.d.ts +64 -0
- package/dist/pregel/runner.js +271 -0
- package/dist/pregel/stream.cjs +71 -0
- package/dist/pregel/stream.d.ts +17 -0
- package/dist/pregel/stream.js +67 -0
- package/dist/pregel/types.cjs +54 -0
- package/dist/pregel/types.d.ts +78 -6
- package/dist/pregel/types.js +51 -1
- package/dist/pregel/utils/config.cjs +26 -1
- package/dist/pregel/utils/config.d.ts +14 -0
- package/dist/pregel/utils/config.js +22 -0
- package/dist/pregel/write.d.ts +1 -1
- package/dist/utils.cjs +15 -1
- package/dist/utils.d.ts +3 -1
- package/dist/utils.js +12 -0
- package/dist/web.cjs +7 -5
- package/dist/web.d.ts +4 -4
- package/dist/web.js +3 -3
- package/package.json +8 -8
package/dist/pregel/index.cjs
CHANGED
|
@@ -16,11 +16,12 @@ const algo_js_1 = require("./algo.cjs");
|
|
|
16
16
|
const index_js_1 = require("./utils/index.cjs");
|
|
17
17
|
const subgraph_js_1 = require("./utils/subgraph.cjs");
|
|
18
18
|
const loop_js_1 = require("./loop.cjs");
|
|
19
|
-
const retry_js_1 = require("./retry.cjs");
|
|
20
19
|
const base_js_2 = require("../managed/base.cjs");
|
|
21
20
|
const utils_js_1 = require("../utils.cjs");
|
|
22
21
|
const config_js_1 = require("./utils/config.cjs");
|
|
23
22
|
const messages_js_1 = require("./messages.cjs");
|
|
23
|
+
const runner_js_1 = require("./runner.cjs");
|
|
24
|
+
const stream_js_1 = require("./stream.cjs");
|
|
24
25
|
function isString(value) {
|
|
25
26
|
return typeof value === "string";
|
|
26
27
|
}
|
|
@@ -824,92 +825,6 @@ class Pregel extends runnables_1.Runnable {
|
|
|
824
825
|
managed,
|
|
825
826
|
};
|
|
826
827
|
}
|
|
827
|
-
async _runLoop(params) {
|
|
828
|
-
const { loop, interruptAfter, interruptBefore, runManager, debug, config } = params;
|
|
829
|
-
let tickError;
|
|
830
|
-
try {
|
|
831
|
-
while (await loop.tick({
|
|
832
|
-
inputKeys: this.inputChannels,
|
|
833
|
-
interruptAfter,
|
|
834
|
-
interruptBefore,
|
|
835
|
-
manager: runManager,
|
|
836
|
-
})) {
|
|
837
|
-
if (debug) {
|
|
838
|
-
(0, debug_js_1.printStepCheckpoint)(loop.checkpointMetadata.step, loop.channels, this.streamChannelsList);
|
|
839
|
-
}
|
|
840
|
-
if (debug) {
|
|
841
|
-
(0, debug_js_1.printStepTasks)(loop.step, Object.values(loop.tasks));
|
|
842
|
-
}
|
|
843
|
-
// execute tasks, and wait for one to fail or all to finish.
|
|
844
|
-
// each task is independent from all other concurrent tasks
|
|
845
|
-
// yield updates/debug output as each task finishes
|
|
846
|
-
const taskStream = (0, retry_js_1.executeTasksWithRetry)(Object.values(loop.tasks).filter((task) => task.writes.length === 0), {
|
|
847
|
-
stepTimeout: this.stepTimeout,
|
|
848
|
-
signal: config.signal,
|
|
849
|
-
retryPolicy: this.retryPolicy,
|
|
850
|
-
});
|
|
851
|
-
let graphInterrupt;
|
|
852
|
-
for await (const { task, error } of taskStream) {
|
|
853
|
-
if (error !== undefined) {
|
|
854
|
-
if ((0, errors_js_1.isGraphBubbleUp)(error)) {
|
|
855
|
-
if (loop.isNested) {
|
|
856
|
-
throw error;
|
|
857
|
-
}
|
|
858
|
-
if ((0, errors_js_1.isGraphInterrupt)(error)) {
|
|
859
|
-
graphInterrupt = error;
|
|
860
|
-
if (error.interrupts.length) {
|
|
861
|
-
const interrupts = error.interrupts.map((interrupt) => [constants_js_1.INTERRUPT, interrupt]);
|
|
862
|
-
const resumes = task.writes.filter((w) => w[0] === constants_js_1.RESUME);
|
|
863
|
-
if (resumes.length) {
|
|
864
|
-
interrupts.push(...resumes);
|
|
865
|
-
}
|
|
866
|
-
loop.putWrites(task.id, interrupts);
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
else {
|
|
871
|
-
loop.putWrites(task.id, [
|
|
872
|
-
[constants_js_1.ERROR, { message: error.message, name: error.name }],
|
|
873
|
-
]);
|
|
874
|
-
throw error;
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
else {
|
|
878
|
-
loop.putWrites(task.id, task.writes);
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
if (debug) {
|
|
882
|
-
(0, debug_js_1.printStepWrites)(loop.step, Object.values(loop.tasks)
|
|
883
|
-
.map((task) => task.writes)
|
|
884
|
-
.flat(), this.streamChannelsList);
|
|
885
|
-
}
|
|
886
|
-
if (graphInterrupt !== undefined) {
|
|
887
|
-
throw graphInterrupt;
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
if (loop.status === "out_of_steps") {
|
|
891
|
-
throw new errors_js_1.GraphRecursionError([
|
|
892
|
-
`Recursion limit of ${config.recursionLimit} reached`,
|
|
893
|
-
"without hitting a stop condition. You can increase the",
|
|
894
|
-
`limit by setting the "recursionLimit" config key.`,
|
|
895
|
-
].join(" "), {
|
|
896
|
-
lc_error_code: "GRAPH_RECURSION_LIMIT",
|
|
897
|
-
});
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
catch (e) {
|
|
901
|
-
tickError = e;
|
|
902
|
-
const suppress = await loop.finishAndHandleError(tickError);
|
|
903
|
-
if (!suppress) {
|
|
904
|
-
throw e;
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
finally {
|
|
908
|
-
if (tickError === undefined) {
|
|
909
|
-
await loop.finishAndHandleError();
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
828
|
async *_streamIterator(input, options) {
|
|
914
829
|
const streamSubgraphs = options?.subgraphs;
|
|
915
830
|
const inputConfig = (0, config_js_1.ensureLangGraphConfig)(this.config, options);
|
|
@@ -925,7 +840,7 @@ class Pregel extends runnables_1.Runnable {
|
|
|
925
840
|
const { runId, ...restConfig } = inputConfig;
|
|
926
841
|
// assign defaults
|
|
927
842
|
const [debug, streamMode, , outputKeys, config, interruptBefore, interruptAfter, checkpointer, store, streamModeSingle,] = this._defaults(restConfig);
|
|
928
|
-
const stream = new
|
|
843
|
+
const stream = new stream_js_1.IterableReadableWritableStream({
|
|
929
844
|
modes: new Set(streamMode),
|
|
930
845
|
});
|
|
931
846
|
// set up messages stream mode
|
|
@@ -974,6 +889,14 @@ class Pregel extends runnables_1.Runnable {
|
|
|
974
889
|
streamKeys: this.streamChannelsAsIs,
|
|
975
890
|
store,
|
|
976
891
|
stream,
|
|
892
|
+
interruptAfter,
|
|
893
|
+
interruptBefore,
|
|
894
|
+
manager: runManager,
|
|
895
|
+
debug: this.debug,
|
|
896
|
+
});
|
|
897
|
+
const runner = new runner_js_1.PregelRunner({
|
|
898
|
+
loop,
|
|
899
|
+
nodeFinished: config.configurable?.nodeFinished,
|
|
977
900
|
});
|
|
978
901
|
if (options?.subgraphs) {
|
|
979
902
|
loop.config.configurable = {
|
|
@@ -981,14 +904,7 @@ class Pregel extends runnables_1.Runnable {
|
|
|
981
904
|
[constants_js_1.CONFIG_KEY_STREAM]: loop.stream,
|
|
982
905
|
};
|
|
983
906
|
}
|
|
984
|
-
await this._runLoop({
|
|
985
|
-
loop,
|
|
986
|
-
interruptAfter,
|
|
987
|
-
interruptBefore,
|
|
988
|
-
runManager,
|
|
989
|
-
debug,
|
|
990
|
-
config,
|
|
991
|
-
});
|
|
907
|
+
await this._runLoop({ loop, runner, debug, config });
|
|
992
908
|
}
|
|
993
909
|
catch (e) {
|
|
994
910
|
loopError = e;
|
|
@@ -1086,5 +1002,52 @@ class Pregel extends runnables_1.Runnable {
|
|
|
1086
1002
|
}
|
|
1087
1003
|
return chunks;
|
|
1088
1004
|
}
|
|
1005
|
+
async _runLoop(params) {
|
|
1006
|
+
const { loop, runner, debug, config } = params;
|
|
1007
|
+
let tickError;
|
|
1008
|
+
try {
|
|
1009
|
+
while (await loop.tick({
|
|
1010
|
+
inputKeys: this.inputChannels,
|
|
1011
|
+
})) {
|
|
1012
|
+
if (debug) {
|
|
1013
|
+
(0, debug_js_1.printStepCheckpoint)(loop.checkpointMetadata.step, loop.channels, this.streamChannelsList);
|
|
1014
|
+
}
|
|
1015
|
+
if (debug) {
|
|
1016
|
+
(0, debug_js_1.printStepTasks)(loop.step, Object.values(loop.tasks));
|
|
1017
|
+
}
|
|
1018
|
+
await runner.tick({
|
|
1019
|
+
timeout: this.stepTimeout,
|
|
1020
|
+
retryPolicy: this.retryPolicy,
|
|
1021
|
+
onStepWrite: (step, writes) => {
|
|
1022
|
+
if (debug) {
|
|
1023
|
+
(0, debug_js_1.printStepWrites)(step, writes, this.streamChannelsList);
|
|
1024
|
+
}
|
|
1025
|
+
},
|
|
1026
|
+
signal: config.signal,
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
if (loop.status === "out_of_steps") {
|
|
1030
|
+
throw new errors_js_1.GraphRecursionError([
|
|
1031
|
+
`Recursion limit of ${config.recursionLimit} reached`,
|
|
1032
|
+
"without hitting a stop condition. You can increase the",
|
|
1033
|
+
`limit by setting the "recursionLimit" config key.`,
|
|
1034
|
+
].join(" "), {
|
|
1035
|
+
lc_error_code: "GRAPH_RECURSION_LIMIT",
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
catch (e) {
|
|
1040
|
+
tickError = e;
|
|
1041
|
+
const suppress = await loop.finishAndHandleError(tickError);
|
|
1042
|
+
if (!suppress) {
|
|
1043
|
+
throw e;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
finally {
|
|
1047
|
+
if (tickError === undefined) {
|
|
1048
|
+
await loop.finishAndHandleError();
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1089
1052
|
}
|
|
1090
1053
|
exports.Pregel = Pregel;
|
package/dist/pregel/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Runnable, RunnableConfig, RunnableFunc } from "@langchain/core/runnables";
|
|
2
2
|
import { IterableReadableStream } from "@langchain/core/utils/stream";
|
|
3
|
-
import type { CallbackManagerForChainRun } from "@langchain/core/callbacks/manager";
|
|
4
3
|
import { All, BaseCheckpointSaver, BaseStore, CheckpointListOptions, CheckpointTuple } from "@langchain/langgraph-checkpoint";
|
|
5
4
|
import { BaseChannel } from "../channels/base.js";
|
|
6
5
|
import { PregelNode } from "./read.js";
|
|
@@ -9,7 +8,6 @@ import { Command } from "../constants.js";
|
|
|
9
8
|
import { PregelInterface, PregelParams, StateSnapshot, StreamMode, PregelInputType, PregelOutputType, PregelOptions } from "./types.js";
|
|
10
9
|
import { StrRecord } from "./algo.js";
|
|
11
10
|
import { RetryPolicy } from "./utils/index.js";
|
|
12
|
-
import { PregelLoop } from "./loop.js";
|
|
13
11
|
import { ManagedValueMapping, type ManagedValueSpec } from "../managed/base.js";
|
|
14
12
|
import { LangGraphRunnableConfig } from "./runnable_types.js";
|
|
15
13
|
type WriteValue = Runnable | RunnableFunc<unknown, unknown> | unknown;
|
|
@@ -112,14 +110,6 @@ export declare class Pregel<Nn extends StrRecord<string, PregelNode>, Cc extends
|
|
|
112
110
|
channelSpecs: Record<string, BaseChannel<unknown, unknown, unknown>>;
|
|
113
111
|
managed: ManagedValueMapping;
|
|
114
112
|
}>;
|
|
115
|
-
_runLoop(params: {
|
|
116
|
-
loop: PregelLoop;
|
|
117
|
-
interruptAfter: string[] | "*";
|
|
118
|
-
interruptBefore: string[] | "*";
|
|
119
|
-
runManager?: CallbackManagerForChainRun;
|
|
120
|
-
debug: boolean;
|
|
121
|
-
config: LangGraphRunnableConfig;
|
|
122
|
-
}): Promise<void>;
|
|
123
113
|
_streamIterator(input: PregelInputType | Command, options?: Partial<PregelOptions<Nn, Cc>>): AsyncGenerator<PregelOutputType>;
|
|
124
114
|
/**
|
|
125
115
|
* Run the graph with a single input and config.
|
|
@@ -137,4 +127,5 @@ export declare class Pregel<Nn extends StrRecord<string, PregelNode>, Cc extends
|
|
|
137
127
|
* @param options.debug Whether to print debug information during execution.
|
|
138
128
|
*/
|
|
139
129
|
invoke(input: InputType | Command | null, options?: Partial<PregelOptions<Nn, Cc, ConfigurableFieldType>>): Promise<OutputType>;
|
|
130
|
+
private _runLoop;
|
|
140
131
|
}
|
package/dist/pregel/index.js
CHANGED
|
@@ -7,17 +7,18 @@ import { validateGraph, validateKeys } from "./validate.js";
|
|
|
7
7
|
import { readChannels } from "./io.js";
|
|
8
8
|
import { printStepCheckpoint, printStepTasks, printStepWrites, tasksWithWrites, } from "./debug.js";
|
|
9
9
|
import { ChannelWrite, PASSTHROUGH } from "./write.js";
|
|
10
|
-
import { CONFIG_KEY_CHECKPOINTER, CONFIG_KEY_READ, CONFIG_KEY_SEND, ERROR, INTERRUPT, CHECKPOINT_NAMESPACE_SEPARATOR, CHECKPOINT_NAMESPACE_END, CONFIG_KEY_STREAM, CONFIG_KEY_TASK_ID, NULL_TASK_ID, INPUT,
|
|
11
|
-
import { GraphRecursionError, GraphValueError, InvalidUpdateError,
|
|
10
|
+
import { CONFIG_KEY_CHECKPOINTER, CONFIG_KEY_READ, CONFIG_KEY_SEND, ERROR, INTERRUPT, CHECKPOINT_NAMESPACE_SEPARATOR, CHECKPOINT_NAMESPACE_END, CONFIG_KEY_STREAM, CONFIG_KEY_TASK_ID, NULL_TASK_ID, INPUT, PUSH, } from "../constants.js";
|
|
11
|
+
import { GraphRecursionError, GraphValueError, InvalidUpdateError, } from "../errors.js";
|
|
12
12
|
import { _prepareNextTasks, _localRead, _applyWrites, } from "./algo.js";
|
|
13
13
|
import { _coerceToDict, getNewChannelVersions, patchCheckpointMap, } from "./utils/index.js";
|
|
14
14
|
import { findSubgraphPregel } from "./utils/subgraph.js";
|
|
15
|
-
import { PregelLoop
|
|
16
|
-
import { executeTasksWithRetry } from "./retry.js";
|
|
15
|
+
import { PregelLoop } from "./loop.js";
|
|
17
16
|
import { ChannelKeyPlaceholder, isConfiguredManagedValue, ManagedValueMapping, NoopManagedValue, } from "../managed/base.js";
|
|
18
17
|
import { gatherIterator, patchConfigurable } from "../utils.js";
|
|
19
18
|
import { ensureLangGraphConfig } from "./utils/config.js";
|
|
20
19
|
import { StreamMessagesHandler } from "./messages.js";
|
|
20
|
+
import { PregelRunner } from "./runner.js";
|
|
21
|
+
import { IterableReadableWritableStream } from "./stream.js";
|
|
21
22
|
function isString(value) {
|
|
22
23
|
return typeof value === "string";
|
|
23
24
|
}
|
|
@@ -820,92 +821,6 @@ export class Pregel extends Runnable {
|
|
|
820
821
|
managed,
|
|
821
822
|
};
|
|
822
823
|
}
|
|
823
|
-
async _runLoop(params) {
|
|
824
|
-
const { loop, interruptAfter, interruptBefore, runManager, debug, config } = params;
|
|
825
|
-
let tickError;
|
|
826
|
-
try {
|
|
827
|
-
while (await loop.tick({
|
|
828
|
-
inputKeys: this.inputChannels,
|
|
829
|
-
interruptAfter,
|
|
830
|
-
interruptBefore,
|
|
831
|
-
manager: runManager,
|
|
832
|
-
})) {
|
|
833
|
-
if (debug) {
|
|
834
|
-
printStepCheckpoint(loop.checkpointMetadata.step, loop.channels, this.streamChannelsList);
|
|
835
|
-
}
|
|
836
|
-
if (debug) {
|
|
837
|
-
printStepTasks(loop.step, Object.values(loop.tasks));
|
|
838
|
-
}
|
|
839
|
-
// execute tasks, and wait for one to fail or all to finish.
|
|
840
|
-
// each task is independent from all other concurrent tasks
|
|
841
|
-
// yield updates/debug output as each task finishes
|
|
842
|
-
const taskStream = executeTasksWithRetry(Object.values(loop.tasks).filter((task) => task.writes.length === 0), {
|
|
843
|
-
stepTimeout: this.stepTimeout,
|
|
844
|
-
signal: config.signal,
|
|
845
|
-
retryPolicy: this.retryPolicy,
|
|
846
|
-
});
|
|
847
|
-
let graphInterrupt;
|
|
848
|
-
for await (const { task, error } of taskStream) {
|
|
849
|
-
if (error !== undefined) {
|
|
850
|
-
if (isGraphBubbleUp(error)) {
|
|
851
|
-
if (loop.isNested) {
|
|
852
|
-
throw error;
|
|
853
|
-
}
|
|
854
|
-
if (isGraphInterrupt(error)) {
|
|
855
|
-
graphInterrupt = error;
|
|
856
|
-
if (error.interrupts.length) {
|
|
857
|
-
const interrupts = error.interrupts.map((interrupt) => [INTERRUPT, interrupt]);
|
|
858
|
-
const resumes = task.writes.filter((w) => w[0] === RESUME);
|
|
859
|
-
if (resumes.length) {
|
|
860
|
-
interrupts.push(...resumes);
|
|
861
|
-
}
|
|
862
|
-
loop.putWrites(task.id, interrupts);
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
else {
|
|
867
|
-
loop.putWrites(task.id, [
|
|
868
|
-
[ERROR, { message: error.message, name: error.name }],
|
|
869
|
-
]);
|
|
870
|
-
throw error;
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
else {
|
|
874
|
-
loop.putWrites(task.id, task.writes);
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
if (debug) {
|
|
878
|
-
printStepWrites(loop.step, Object.values(loop.tasks)
|
|
879
|
-
.map((task) => task.writes)
|
|
880
|
-
.flat(), this.streamChannelsList);
|
|
881
|
-
}
|
|
882
|
-
if (graphInterrupt !== undefined) {
|
|
883
|
-
throw graphInterrupt;
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
if (loop.status === "out_of_steps") {
|
|
887
|
-
throw new GraphRecursionError([
|
|
888
|
-
`Recursion limit of ${config.recursionLimit} reached`,
|
|
889
|
-
"without hitting a stop condition. You can increase the",
|
|
890
|
-
`limit by setting the "recursionLimit" config key.`,
|
|
891
|
-
].join(" "), {
|
|
892
|
-
lc_error_code: "GRAPH_RECURSION_LIMIT",
|
|
893
|
-
});
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
catch (e) {
|
|
897
|
-
tickError = e;
|
|
898
|
-
const suppress = await loop.finishAndHandleError(tickError);
|
|
899
|
-
if (!suppress) {
|
|
900
|
-
throw e;
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
finally {
|
|
904
|
-
if (tickError === undefined) {
|
|
905
|
-
await loop.finishAndHandleError();
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
824
|
async *_streamIterator(input, options) {
|
|
910
825
|
const streamSubgraphs = options?.subgraphs;
|
|
911
826
|
const inputConfig = ensureLangGraphConfig(this.config, options);
|
|
@@ -970,6 +885,14 @@ export class Pregel extends Runnable {
|
|
|
970
885
|
streamKeys: this.streamChannelsAsIs,
|
|
971
886
|
store,
|
|
972
887
|
stream,
|
|
888
|
+
interruptAfter,
|
|
889
|
+
interruptBefore,
|
|
890
|
+
manager: runManager,
|
|
891
|
+
debug: this.debug,
|
|
892
|
+
});
|
|
893
|
+
const runner = new PregelRunner({
|
|
894
|
+
loop,
|
|
895
|
+
nodeFinished: config.configurable?.nodeFinished,
|
|
973
896
|
});
|
|
974
897
|
if (options?.subgraphs) {
|
|
975
898
|
loop.config.configurable = {
|
|
@@ -977,14 +900,7 @@ export class Pregel extends Runnable {
|
|
|
977
900
|
[CONFIG_KEY_STREAM]: loop.stream,
|
|
978
901
|
};
|
|
979
902
|
}
|
|
980
|
-
await this._runLoop({
|
|
981
|
-
loop,
|
|
982
|
-
interruptAfter,
|
|
983
|
-
interruptBefore,
|
|
984
|
-
runManager,
|
|
985
|
-
debug,
|
|
986
|
-
config,
|
|
987
|
-
});
|
|
903
|
+
await this._runLoop({ loop, runner, debug, config });
|
|
988
904
|
}
|
|
989
905
|
catch (e) {
|
|
990
906
|
loopError = e;
|
|
@@ -1082,4 +998,51 @@ export class Pregel extends Runnable {
|
|
|
1082
998
|
}
|
|
1083
999
|
return chunks;
|
|
1084
1000
|
}
|
|
1001
|
+
async _runLoop(params) {
|
|
1002
|
+
const { loop, runner, debug, config } = params;
|
|
1003
|
+
let tickError;
|
|
1004
|
+
try {
|
|
1005
|
+
while (await loop.tick({
|
|
1006
|
+
inputKeys: this.inputChannels,
|
|
1007
|
+
})) {
|
|
1008
|
+
if (debug) {
|
|
1009
|
+
printStepCheckpoint(loop.checkpointMetadata.step, loop.channels, this.streamChannelsList);
|
|
1010
|
+
}
|
|
1011
|
+
if (debug) {
|
|
1012
|
+
printStepTasks(loop.step, Object.values(loop.tasks));
|
|
1013
|
+
}
|
|
1014
|
+
await runner.tick({
|
|
1015
|
+
timeout: this.stepTimeout,
|
|
1016
|
+
retryPolicy: this.retryPolicy,
|
|
1017
|
+
onStepWrite: (step, writes) => {
|
|
1018
|
+
if (debug) {
|
|
1019
|
+
printStepWrites(step, writes, this.streamChannelsList);
|
|
1020
|
+
}
|
|
1021
|
+
},
|
|
1022
|
+
signal: config.signal,
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
if (loop.status === "out_of_steps") {
|
|
1026
|
+
throw new GraphRecursionError([
|
|
1027
|
+
`Recursion limit of ${config.recursionLimit} reached`,
|
|
1028
|
+
"without hitting a stop condition. You can increase the",
|
|
1029
|
+
`limit by setting the "recursionLimit" config key.`,
|
|
1030
|
+
].join(" "), {
|
|
1031
|
+
lc_error_code: "GRAPH_RECURSION_LIMIT",
|
|
1032
|
+
});
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
catch (e) {
|
|
1036
|
+
tickError = e;
|
|
1037
|
+
const suppress = await loop.finishAndHandleError(tickError);
|
|
1038
|
+
if (!suppress) {
|
|
1039
|
+
throw e;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
finally {
|
|
1043
|
+
if (tickError === undefined) {
|
|
1044
|
+
await loop.finishAndHandleError();
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1085
1048
|
}
|
package/dist/pregel/io.cjs
CHANGED
|
@@ -171,7 +171,12 @@ function* mapOutputUpdates(outputChannels, tasks, cached
|
|
|
171
171
|
}
|
|
172
172
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
173
173
|
let updated;
|
|
174
|
-
if (
|
|
174
|
+
if (outputTasks.some(([task]) => task.writes.some(([chan, _]) => chan === constants_js_1.RETURN))) {
|
|
175
|
+
updated = outputTasks.flatMap(([task]) => task.writes
|
|
176
|
+
.filter(([chan, _]) => chan === constants_js_1.RETURN)
|
|
177
|
+
.map(([_, value]) => [task.name, value]));
|
|
178
|
+
}
|
|
179
|
+
else if (!Array.isArray(outputChannels)) {
|
|
175
180
|
updated = outputTasks.flatMap(([task]) => task.writes
|
|
176
181
|
.filter(([chan, _]) => chan === outputChannels)
|
|
177
182
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/dist/pregel/io.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { validate } from "uuid";
|
|
2
|
-
import { _isSend, Command, ERROR, INTERRUPT, NULL_TASK_ID, RESUME, SELF, TAG_HIDDEN, TASKS, } from "../constants.js";
|
|
2
|
+
import { _isSend, Command, ERROR, INTERRUPT, NULL_TASK_ID, RESUME, RETURN, SELF, TAG_HIDDEN, TASKS, } from "../constants.js";
|
|
3
3
|
import { EmptyChannelError, InvalidUpdateError } from "../errors.js";
|
|
4
4
|
export function readChannel(channels, chan, catchErrors = true, returnException = false) {
|
|
5
5
|
try {
|
|
@@ -163,7 +163,12 @@ export function* mapOutputUpdates(outputChannels, tasks, cached
|
|
|
163
163
|
}
|
|
164
164
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
165
165
|
let updated;
|
|
166
|
-
if (
|
|
166
|
+
if (outputTasks.some(([task]) => task.writes.some(([chan, _]) => chan === RETURN))) {
|
|
167
|
+
updated = outputTasks.flatMap(([task]) => task.writes
|
|
168
|
+
.filter(([chan, _]) => chan === RETURN)
|
|
169
|
+
.map(([_, value]) => [task.name, value]));
|
|
170
|
+
}
|
|
171
|
+
else if (!Array.isArray(outputChannels)) {
|
|
167
172
|
updated = outputTasks.flatMap(([task]) => task.writes
|
|
168
173
|
.filter(([chan, _]) => chan === outputChannels)
|
|
169
174
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|