@langchain/langgraph 0.2.14 → 0.2.15
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/graph/index.cjs +2 -1
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/index.js +1 -1
- package/dist/graph/state.cjs +5 -0
- package/dist/graph/state.d.ts +5 -0
- package/dist/graph/state.js +5 -0
- package/dist/pregel/debug.cjs +19 -6
- package/dist/pregel/debug.d.ts +2 -1
- package/dist/pregel/debug.js +19 -6
- package/dist/pregel/index.cjs +2 -22
- package/dist/pregel/index.js +2 -22
- package/dist/pregel/loop.cjs +15 -1
- package/dist/pregel/loop.d.ts +2 -0
- package/dist/pregel/loop.js +15 -1
- package/dist/pregel/retry.cjs +1 -5
- package/dist/pregel/retry.js +1 -5
- package/dist/pregel/utils/subgraph.cjs +32 -0
- package/dist/pregel/utils/subgraph.d.ts +3 -0
- package/dist/pregel/utils/subgraph.js +28 -0
- package/dist/web.cjs +2 -1
- package/dist/web.d.ts +1 -1
- package/dist/web.js +1 -1
- package/package.json +2 -2
package/dist/graph/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.messagesStateReducer = exports.MessageGraph = exports.StateGraph = exports.Graph = exports.START = exports.END = exports.AnnotationRoot = exports.Annotation = void 0;
|
|
3
|
+
exports.messagesStateReducer = exports.MessageGraph = exports.CompiledStateGraph = exports.StateGraph = exports.Graph = exports.START = exports.END = exports.AnnotationRoot = exports.Annotation = void 0;
|
|
4
4
|
var annotation_js_1 = require("./annotation.cjs");
|
|
5
5
|
Object.defineProperty(exports, "Annotation", { enumerable: true, get: function () { return annotation_js_1.Annotation; } });
|
|
6
6
|
Object.defineProperty(exports, "AnnotationRoot", { enumerable: true, get: function () { return annotation_js_1.AnnotationRoot; } });
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "START", { enumerable: true, get: function () { r
|
|
|
10
10
|
Object.defineProperty(exports, "Graph", { enumerable: true, get: function () { return graph_js_1.Graph; } });
|
|
11
11
|
var state_js_1 = require("./state.cjs");
|
|
12
12
|
Object.defineProperty(exports, "StateGraph", { enumerable: true, get: function () { return state_js_1.StateGraph; } });
|
|
13
|
+
Object.defineProperty(exports, "CompiledStateGraph", { enumerable: true, get: function () { return state_js_1.CompiledStateGraph; } });
|
|
13
14
|
var message_js_1 = require("./message.cjs");
|
|
14
15
|
Object.defineProperty(exports, "MessageGraph", { enumerable: true, get: function () { return message_js_1.MessageGraph; } });
|
|
15
16
|
Object.defineProperty(exports, "messagesStateReducer", { enumerable: true, get: function () { return message_js_1.messagesStateReducer; } });
|
package/dist/graph/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Annotation, type StateType, type UpdateType, type NodeType, AnnotationRoot, type StateDefinition, type SingleReducer, } from "./annotation.js";
|
|
2
2
|
export { END, START, Graph, type CompiledGraph } from "./graph.js";
|
|
3
|
-
export { type StateGraphArgs, StateGraph,
|
|
3
|
+
export { type StateGraphArgs, StateGraph, CompiledStateGraph, } from "./state.js";
|
|
4
4
|
export { MessageGraph, messagesStateReducer, type Messages, } from "./message.js";
|
package/dist/graph/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Annotation, AnnotationRoot, } from "./annotation.js";
|
|
2
2
|
export { END, START, Graph } from "./graph.js";
|
|
3
|
-
export { StateGraph, } from "./state.js";
|
|
3
|
+
export { StateGraph, CompiledStateGraph, } from "./state.js";
|
|
4
4
|
export { MessageGraph, messagesStateReducer, } from "./message.js";
|
package/dist/graph/state.cjs
CHANGED
|
@@ -312,6 +312,11 @@ function _getChannels(schema) {
|
|
|
312
312
|
}
|
|
313
313
|
return channels;
|
|
314
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* Final result from building and compiling a {@link StateGraph}.
|
|
317
|
+
* Should not be instantiated directly, only using the StateGraph `.compile()`
|
|
318
|
+
* instance method.
|
|
319
|
+
*/
|
|
315
320
|
class CompiledStateGraph extends graph_js_1.CompiledGraph {
|
|
316
321
|
attachNode(key, node) {
|
|
317
322
|
const stateKeys = Object.keys(this.builder.channels);
|
package/dist/graph/state.d.ts
CHANGED
|
@@ -123,6 +123,11 @@ export declare class StateGraph<SD extends StateDefinition | unknown, S = SD ext
|
|
|
123
123
|
interruptAfter?: N[] | All;
|
|
124
124
|
}): CompiledStateGraph<S, U, N, I, O, C>;
|
|
125
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Final result from building and compiling a {@link StateGraph}.
|
|
128
|
+
* Should not be instantiated directly, only using the StateGraph `.compile()`
|
|
129
|
+
* instance method.
|
|
130
|
+
*/
|
|
126
131
|
export declare class CompiledStateGraph<S, U, N extends string = typeof START, I extends StateDefinition = StateDefinition, O extends StateDefinition = StateDefinition, C extends StateDefinition = StateDefinition> extends CompiledGraph<N, S, U, StateType<C>> {
|
|
127
132
|
builder: StateGraph<unknown, S, U, N, I, O, C>;
|
|
128
133
|
attachNode(key: typeof START, node?: never): void;
|
package/dist/graph/state.js
CHANGED
|
@@ -308,6 +308,11 @@ function _getChannels(schema) {
|
|
|
308
308
|
}
|
|
309
309
|
return channels;
|
|
310
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* Final result from building and compiling a {@link StateGraph}.
|
|
313
|
+
* Should not be instantiated directly, only using the StateGraph `.compile()`
|
|
314
|
+
* instance method.
|
|
315
|
+
*/
|
|
311
316
|
export class CompiledStateGraph extends CompiledGraph {
|
|
312
317
|
attachNode(key, node) {
|
|
313
318
|
const stateKeys = Object.keys(this.builder.channels);
|
package/dist/pregel/debug.cjs
CHANGED
|
@@ -4,6 +4,7 @@ exports.printStepWrites = exports.printStepTasks = exports.printStepCheckpoint =
|
|
|
4
4
|
const constants_js_1 = require("../constants.cjs");
|
|
5
5
|
const errors_js_1 = require("../errors.cjs");
|
|
6
6
|
const io_js_1 = require("./io.cjs");
|
|
7
|
+
const subgraph_js_1 = require("./utils/subgraph.cjs");
|
|
7
8
|
const COLORS_MAP = {
|
|
8
9
|
blue: {
|
|
9
10
|
start: "\x1b[34m",
|
|
@@ -101,7 +102,7 @@ function* mapDebugTaskResults(step, tasks, streamChannels) {
|
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
exports.mapDebugTaskResults = mapDebugTaskResults;
|
|
104
|
-
function* mapDebugCheckpoint(step, config, channels, streamChannels, metadata, tasks, pendingWrites) {
|
|
105
|
+
function* mapDebugCheckpoint(step, config, channels, streamChannels, metadata, tasks, pendingWrites, parentConfig) {
|
|
105
106
|
function formatConfig(config) {
|
|
106
107
|
// make sure the config is consistent with Python
|
|
107
108
|
const pyConfig = {};
|
|
@@ -123,11 +124,22 @@ function* mapDebugCheckpoint(step, config, channels, streamChannels, metadata, t
|
|
|
123
124
|
pyConfig.tags = config.tags;
|
|
124
125
|
return pyConfig;
|
|
125
126
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
const parentNs = config.configurable?.checkpoint_ns;
|
|
128
|
+
const taskStates = {};
|
|
129
|
+
for (const task of tasks) {
|
|
130
|
+
if (!(0, subgraph_js_1.findSubgraphPregel)(task.proc))
|
|
131
|
+
continue;
|
|
132
|
+
let taskNs = `${task.name}:${task.id}`;
|
|
133
|
+
if (parentNs)
|
|
134
|
+
taskNs = `${parentNs}|${taskNs}`;
|
|
135
|
+
taskStates[task.id] = {
|
|
136
|
+
configurable: {
|
|
137
|
+
thread_id: config.configurable?.thread_id,
|
|
138
|
+
checkpoint_ns: taskNs,
|
|
139
|
+
},
|
|
140
|
+
};
|
|
129
141
|
}
|
|
130
|
-
const ts =
|
|
142
|
+
const ts = new Date().toISOString();
|
|
131
143
|
yield {
|
|
132
144
|
type: "checkpoint",
|
|
133
145
|
timestamp: ts,
|
|
@@ -137,7 +149,8 @@ function* mapDebugCheckpoint(step, config, channels, streamChannels, metadata, t
|
|
|
137
149
|
values: (0, io_js_1.readChannels)(channels, streamChannels),
|
|
138
150
|
metadata,
|
|
139
151
|
next: tasks.map((task) => task.name),
|
|
140
|
-
tasks: tasksWithWrites(tasks, pendingWrites),
|
|
152
|
+
tasks: tasksWithWrites(tasks, pendingWrites, taskStates),
|
|
153
|
+
parentConfig: parentConfig ? formatConfig(parentConfig) : undefined,
|
|
141
154
|
},
|
|
142
155
|
};
|
|
143
156
|
}
|
package/dist/pregel/debug.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export declare function mapDebugTaskResults<N extends PropertyKey, C extends Pro
|
|
|
26
26
|
interrupts: PendingWrite<C>[];
|
|
27
27
|
};
|
|
28
28
|
}, void, unknown>;
|
|
29
|
-
export declare function mapDebugCheckpoint<N extends PropertyKey, C extends PropertyKey>(step: number, config: RunnableConfig, channels: Record<string, BaseChannel>, streamChannels: string | string[], metadata: CheckpointMetadata, tasks: readonly PregelExecutableTask<N, C>[], pendingWrites: CheckpointPendingWrite[]): Generator<{
|
|
29
|
+
export declare function mapDebugCheckpoint<N extends PropertyKey, C extends PropertyKey>(step: number, config: RunnableConfig, channels: Record<string, BaseChannel>, streamChannels: string | string[], metadata: CheckpointMetadata, tasks: readonly PregelExecutableTask<N, C>[], pendingWrites: CheckpointPendingWrite[], parentConfig: RunnableConfig | undefined): Generator<{
|
|
30
30
|
type: string;
|
|
31
31
|
timestamp: string;
|
|
32
32
|
step: number;
|
|
@@ -36,6 +36,7 @@ export declare function mapDebugCheckpoint<N extends PropertyKey, C extends Prop
|
|
|
36
36
|
metadata: CheckpointMetadata;
|
|
37
37
|
next: N[];
|
|
38
38
|
tasks: PregelTaskDescription[];
|
|
39
|
+
parentConfig: Partial<Record<"configurable" | "timeout" | "signal" | "tags" | "metadata" | "callbacks" | "recursion_limit" | "max_concurrency" | "run_name" | "run_id", unknown>> | undefined;
|
|
39
40
|
};
|
|
40
41
|
}, void, unknown>;
|
|
41
42
|
export declare function tasksWithWrites<N extends PropertyKey, C extends PropertyKey>(tasks: PregelTaskDescription[] | readonly PregelExecutableTask<N, C>[], pendingWrites: CheckpointPendingWrite[], states?: Record<string, RunnableConfig | StateSnapshot>): PregelTaskDescription[];
|
package/dist/pregel/debug.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ERROR, INTERRUPT, TAG_HIDDEN } from "../constants.js";
|
|
2
2
|
import { EmptyChannelError } from "../errors.js";
|
|
3
3
|
import { readChannels } from "./io.js";
|
|
4
|
+
import { findSubgraphPregel } from "./utils/subgraph.js";
|
|
4
5
|
const COLORS_MAP = {
|
|
5
6
|
blue: {
|
|
6
7
|
start: "\x1b[34m",
|
|
@@ -95,7 +96,7 @@ export function* mapDebugTaskResults(step, tasks, streamChannels) {
|
|
|
95
96
|
};
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
|
-
export function* mapDebugCheckpoint(step, config, channels, streamChannels, metadata, tasks, pendingWrites) {
|
|
99
|
+
export function* mapDebugCheckpoint(step, config, channels, streamChannels, metadata, tasks, pendingWrites, parentConfig) {
|
|
99
100
|
function formatConfig(config) {
|
|
100
101
|
// make sure the config is consistent with Python
|
|
101
102
|
const pyConfig = {};
|
|
@@ -117,11 +118,22 @@ export function* mapDebugCheckpoint(step, config, channels, streamChannels, meta
|
|
|
117
118
|
pyConfig.tags = config.tags;
|
|
118
119
|
return pyConfig;
|
|
119
120
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
const parentNs = config.configurable?.checkpoint_ns;
|
|
122
|
+
const taskStates = {};
|
|
123
|
+
for (const task of tasks) {
|
|
124
|
+
if (!findSubgraphPregel(task.proc))
|
|
125
|
+
continue;
|
|
126
|
+
let taskNs = `${task.name}:${task.id}`;
|
|
127
|
+
if (parentNs)
|
|
128
|
+
taskNs = `${parentNs}|${taskNs}`;
|
|
129
|
+
taskStates[task.id] = {
|
|
130
|
+
configurable: {
|
|
131
|
+
thread_id: config.configurable?.thread_id,
|
|
132
|
+
checkpoint_ns: taskNs,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
123
135
|
}
|
|
124
|
-
const ts =
|
|
136
|
+
const ts = new Date().toISOString();
|
|
125
137
|
yield {
|
|
126
138
|
type: "checkpoint",
|
|
127
139
|
timestamp: ts,
|
|
@@ -131,7 +143,8 @@ export function* mapDebugCheckpoint(step, config, channels, streamChannels, meta
|
|
|
131
143
|
values: readChannels(channels, streamChannels),
|
|
132
144
|
metadata,
|
|
133
145
|
next: tasks.map((task) => task.name),
|
|
134
|
-
tasks: tasksWithWrites(tasks, pendingWrites),
|
|
146
|
+
tasks: tasksWithWrites(tasks, pendingWrites, taskStates),
|
|
147
|
+
parentConfig: parentConfig ? formatConfig(parentConfig) : undefined,
|
|
135
148
|
},
|
|
136
149
|
};
|
|
137
150
|
}
|
package/dist/pregel/index.cjs
CHANGED
|
@@ -18,6 +18,7 @@ const constants_js_1 = require("../constants.cjs");
|
|
|
18
18
|
const errors_js_1 = require("../errors.cjs");
|
|
19
19
|
const algo_js_1 = require("./algo.cjs");
|
|
20
20
|
const index_js_1 = require("./utils/index.cjs");
|
|
21
|
+
const subgraph_js_1 = require("./utils/subgraph.cjs");
|
|
21
22
|
const loop_js_1 = require("./loop.cjs");
|
|
22
23
|
const retry_js_1 = require("./retry.cjs");
|
|
23
24
|
const base_js_2 = require("../managed/base.cjs");
|
|
@@ -81,16 +82,6 @@ class Channel {
|
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
exports.Channel = Channel;
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
|
-
function isPregel(x) {
|
|
86
|
-
return ("inputChannels" in x &&
|
|
87
|
-
x.inputChannels !== undefined &&
|
|
88
|
-
"outputChannels" &&
|
|
89
|
-
x.outputChannels !== undefined);
|
|
90
|
-
}
|
|
91
|
-
function isRunnableSequence(x) {
|
|
92
|
-
return "steps" in x && Array.isArray(x.steps);
|
|
93
|
-
}
|
|
94
85
|
class Pregel extends runnables_1.Runnable {
|
|
95
86
|
static lc_name() {
|
|
96
87
|
return "LangGraph";
|
|
@@ -264,18 +255,7 @@ class Pregel extends runnables_1.Runnable {
|
|
|
264
255
|
continue;
|
|
265
256
|
}
|
|
266
257
|
}
|
|
267
|
-
|
|
268
|
-
let graph;
|
|
269
|
-
const candidates = [node.bound];
|
|
270
|
-
for (const candidate of candidates) {
|
|
271
|
-
if (isPregel(candidate)) {
|
|
272
|
-
graph = candidate;
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
else if (isRunnableSequence(candidate)) {
|
|
276
|
-
candidates.push(...candidate.steps);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
258
|
+
const graph = (0, subgraph_js_1.findSubgraphPregel)(node.bound);
|
|
279
259
|
// if found, yield recursively
|
|
280
260
|
if (graph !== undefined) {
|
|
281
261
|
if (name === namespace) {
|
package/dist/pregel/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import { CONFIG_KEY_CHECKPOINTER, CONFIG_KEY_READ, CONFIG_KEY_SEND, ERROR, INTER
|
|
|
12
12
|
import { GraphRecursionError, GraphValueError, InvalidUpdateError, isGraphInterrupt, } from "../errors.js";
|
|
13
13
|
import { _prepareNextTasks, _localRead, _applyWrites, } from "./algo.js";
|
|
14
14
|
import { _coerceToDict, getNewChannelVersions, patchCheckpointMap, } from "./utils/index.js";
|
|
15
|
+
import { findSubgraphPregel } from "./utils/subgraph.js";
|
|
15
16
|
import { PregelLoop, StreamProtocol } from "./loop.js";
|
|
16
17
|
import { executeTasksWithRetry } from "./retry.js";
|
|
17
18
|
import { ChannelKeyPlaceholder, isConfiguredManagedValue, ManagedValueMapping, NoopManagedValue, } from "../managed/base.js";
|
|
@@ -74,16 +75,6 @@ export class Channel {
|
|
|
74
75
|
return new ChannelWrite(channelWriteEntries);
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
-
function isPregel(x) {
|
|
79
|
-
return ("inputChannels" in x &&
|
|
80
|
-
x.inputChannels !== undefined &&
|
|
81
|
-
"outputChannels" &&
|
|
82
|
-
x.outputChannels !== undefined);
|
|
83
|
-
}
|
|
84
|
-
function isRunnableSequence(x) {
|
|
85
|
-
return "steps" in x && Array.isArray(x.steps);
|
|
86
|
-
}
|
|
87
78
|
export class Pregel extends Runnable {
|
|
88
79
|
static lc_name() {
|
|
89
80
|
return "LangGraph";
|
|
@@ -257,18 +248,7 @@ export class Pregel extends Runnable {
|
|
|
257
248
|
continue;
|
|
258
249
|
}
|
|
259
250
|
}
|
|
260
|
-
|
|
261
|
-
let graph;
|
|
262
|
-
const candidates = [node.bound];
|
|
263
|
-
for (const candidate of candidates) {
|
|
264
|
-
if (isPregel(candidate)) {
|
|
265
|
-
graph = candidate;
|
|
266
|
-
break;
|
|
267
|
-
}
|
|
268
|
-
else if (isRunnableSequence(candidate)) {
|
|
269
|
-
candidates.push(...candidate.steps);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
251
|
+
const graph = findSubgraphPregel(node.bound);
|
|
272
252
|
// if found, yield recursively
|
|
273
253
|
if (graph !== undefined) {
|
|
274
254
|
if (name === namespace) {
|
package/dist/pregel/loop.cjs
CHANGED
|
@@ -166,6 +166,12 @@ class PregelLoop {
|
|
|
166
166
|
writable: true,
|
|
167
167
|
value: 0
|
|
168
168
|
});
|
|
169
|
+
Object.defineProperty(this, "prevCheckpointConfig", {
|
|
170
|
+
enumerable: true,
|
|
171
|
+
configurable: true,
|
|
172
|
+
writable: true,
|
|
173
|
+
value: void 0
|
|
174
|
+
});
|
|
169
175
|
Object.defineProperty(this, "status", {
|
|
170
176
|
enumerable: true,
|
|
171
177
|
configurable: true,
|
|
@@ -238,6 +244,7 @@ class PregelLoop {
|
|
|
238
244
|
this.store = params.store;
|
|
239
245
|
this.stream = params.stream;
|
|
240
246
|
this.checkpointNamespace = params.checkpointNamespace;
|
|
247
|
+
this.prevCheckpointConfig = params.prevCheckpointConfig;
|
|
241
248
|
}
|
|
242
249
|
static async initialize(params) {
|
|
243
250
|
let { config, stream } = params;
|
|
@@ -284,6 +291,7 @@ class PregelLoop {
|
|
|
284
291
|
...saved.config.configurable,
|
|
285
292
|
},
|
|
286
293
|
};
|
|
294
|
+
const prevCheckpointConfig = saved.parentConfig;
|
|
287
295
|
const checkpoint = (0, langgraph_checkpoint_1.copyCheckpoint)(saved.checkpoint);
|
|
288
296
|
const checkpointMetadata = { ...saved.metadata };
|
|
289
297
|
const checkpointPendingWrites = saved.pendingWrites ?? [];
|
|
@@ -318,6 +326,7 @@ class PregelLoop {
|
|
|
318
326
|
checkpoint,
|
|
319
327
|
checkpointMetadata,
|
|
320
328
|
checkpointConfig,
|
|
329
|
+
prevCheckpointConfig,
|
|
321
330
|
checkpointNamespace,
|
|
322
331
|
channels,
|
|
323
332
|
managed: params.managed,
|
|
@@ -467,7 +476,7 @@ class PregelLoop {
|
|
|
467
476
|
// Produce debug output
|
|
468
477
|
if (this.checkpointer) {
|
|
469
478
|
this._emit(await (0, utils_js_1.gatherIterator)((0, utils_js_1.prefixGenerator)((0, debug_js_1.mapDebugCheckpoint)(this.step - 1, // printing checkpoint for previous step
|
|
470
|
-
this.checkpointConfig, this.channels, this.streamKeys, this.checkpointMetadata, Object.values(this.tasks), this.checkpointPendingWrites), "debug")));
|
|
479
|
+
this.checkpointConfig, this.channels, this.streamKeys, this.checkpointMetadata, Object.values(this.tasks), this.checkpointPendingWrites, this.prevCheckpointConfig), "debug")));
|
|
471
480
|
}
|
|
472
481
|
if (Object.values(this.tasks).length === 0) {
|
|
473
482
|
this.status = "done";
|
|
@@ -600,6 +609,11 @@ class PregelLoop {
|
|
|
600
609
|
};
|
|
601
610
|
// Bail if no checkpointer
|
|
602
611
|
if (this.checkpointer !== undefined) {
|
|
612
|
+
// store the previous checkpoint config for debug events
|
|
613
|
+
this.prevCheckpointConfig = this.checkpointConfig?.configurable
|
|
614
|
+
?.checkpoint_id
|
|
615
|
+
? this.checkpointConfig
|
|
616
|
+
: undefined;
|
|
603
617
|
// create new checkpoint
|
|
604
618
|
this.checkpointMetadata = metadata;
|
|
605
619
|
// child graphs keep at most one checkpoint per parent checkpoint
|
package/dist/pregel/loop.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ type PregelLoopParams = {
|
|
|
41
41
|
isNested: boolean;
|
|
42
42
|
stream: StreamProtocol;
|
|
43
43
|
store?: AsyncBatchedStore;
|
|
44
|
+
prevCheckpointConfig: RunnableConfig | undefined;
|
|
44
45
|
};
|
|
45
46
|
export declare class StreamProtocol {
|
|
46
47
|
push: (chunk: StreamChunk) => void;
|
|
@@ -68,6 +69,7 @@ export declare class PregelLoop {
|
|
|
68
69
|
protected nodes: Record<string, PregelNode>;
|
|
69
70
|
protected skipDoneTasks: boolean;
|
|
70
71
|
protected taskWritesLeft: number;
|
|
72
|
+
protected prevCheckpointConfig: RunnableConfig | undefined;
|
|
71
73
|
status: "pending" | "done" | "interrupt_before" | "interrupt_after" | "out_of_steps";
|
|
72
74
|
tasks: Record<string, PregelExecutableTask<any, any>>;
|
|
73
75
|
stream: StreamProtocol;
|
package/dist/pregel/loop.js
CHANGED
|
@@ -162,6 +162,12 @@ export class PregelLoop {
|
|
|
162
162
|
writable: true,
|
|
163
163
|
value: 0
|
|
164
164
|
});
|
|
165
|
+
Object.defineProperty(this, "prevCheckpointConfig", {
|
|
166
|
+
enumerable: true,
|
|
167
|
+
configurable: true,
|
|
168
|
+
writable: true,
|
|
169
|
+
value: void 0
|
|
170
|
+
});
|
|
165
171
|
Object.defineProperty(this, "status", {
|
|
166
172
|
enumerable: true,
|
|
167
173
|
configurable: true,
|
|
@@ -234,6 +240,7 @@ export class PregelLoop {
|
|
|
234
240
|
this.store = params.store;
|
|
235
241
|
this.stream = params.stream;
|
|
236
242
|
this.checkpointNamespace = params.checkpointNamespace;
|
|
243
|
+
this.prevCheckpointConfig = params.prevCheckpointConfig;
|
|
237
244
|
}
|
|
238
245
|
static async initialize(params) {
|
|
239
246
|
let { config, stream } = params;
|
|
@@ -280,6 +287,7 @@ export class PregelLoop {
|
|
|
280
287
|
...saved.config.configurable,
|
|
281
288
|
},
|
|
282
289
|
};
|
|
290
|
+
const prevCheckpointConfig = saved.parentConfig;
|
|
283
291
|
const checkpoint = copyCheckpoint(saved.checkpoint);
|
|
284
292
|
const checkpointMetadata = { ...saved.metadata };
|
|
285
293
|
const checkpointPendingWrites = saved.pendingWrites ?? [];
|
|
@@ -314,6 +322,7 @@ export class PregelLoop {
|
|
|
314
322
|
checkpoint,
|
|
315
323
|
checkpointMetadata,
|
|
316
324
|
checkpointConfig,
|
|
325
|
+
prevCheckpointConfig,
|
|
317
326
|
checkpointNamespace,
|
|
318
327
|
channels,
|
|
319
328
|
managed: params.managed,
|
|
@@ -463,7 +472,7 @@ export class PregelLoop {
|
|
|
463
472
|
// Produce debug output
|
|
464
473
|
if (this.checkpointer) {
|
|
465
474
|
this._emit(await gatherIterator(prefixGenerator(mapDebugCheckpoint(this.step - 1, // printing checkpoint for previous step
|
|
466
|
-
this.checkpointConfig, this.channels, this.streamKeys, this.checkpointMetadata, Object.values(this.tasks), this.checkpointPendingWrites), "debug")));
|
|
475
|
+
this.checkpointConfig, this.channels, this.streamKeys, this.checkpointMetadata, Object.values(this.tasks), this.checkpointPendingWrites, this.prevCheckpointConfig), "debug")));
|
|
467
476
|
}
|
|
468
477
|
if (Object.values(this.tasks).length === 0) {
|
|
469
478
|
this.status = "done";
|
|
@@ -596,6 +605,11 @@ export class PregelLoop {
|
|
|
596
605
|
};
|
|
597
606
|
// Bail if no checkpointer
|
|
598
607
|
if (this.checkpointer !== undefined) {
|
|
608
|
+
// store the previous checkpoint config for debug events
|
|
609
|
+
this.prevCheckpointConfig = this.checkpointConfig?.configurable
|
|
610
|
+
?.checkpoint_id
|
|
611
|
+
? this.checkpointConfig
|
|
612
|
+
: undefined;
|
|
599
613
|
// create new checkpoint
|
|
600
614
|
this.checkpointMetadata = metadata;
|
|
601
615
|
// child graphs keep at most one checkpoint per parent checkpoint
|
package/dist/pregel/retry.cjs
CHANGED
|
@@ -131,13 +131,9 @@ pregelTask, retryPolicy) {
|
|
|
131
131
|
error.constructor.unminifiable_name ??
|
|
132
132
|
error.constructor.name;
|
|
133
133
|
console.log(`Retrying task "${pregelTask.name}" after ${interval.toFixed(2)} seconds (attempt ${attempts}) after ${errorName}: ${error}`);
|
|
134
|
-
// Clear checkpoint_ns seen (for subgraph detection)
|
|
135
|
-
const checkpointNs = pregelTask.config?.configurable?.checkpoint_ns;
|
|
136
|
-
if (checkpointNs) {
|
|
137
|
-
(0, errors_js_1.getSubgraphsSeenSet)().delete(checkpointNs);
|
|
138
|
-
}
|
|
139
134
|
}
|
|
140
135
|
finally {
|
|
136
|
+
// Clear checkpoint_ns seen (for subgraph detection)
|
|
141
137
|
const checkpointNs = pregelTask.config?.configurable?.checkpoint_ns;
|
|
142
138
|
if (checkpointNs) {
|
|
143
139
|
(0, errors_js_1.getSubgraphsSeenSet)().delete(checkpointNs);
|
package/dist/pregel/retry.js
CHANGED
|
@@ -127,13 +127,9 @@ pregelTask, retryPolicy) {
|
|
|
127
127
|
error.constructor.unminifiable_name ??
|
|
128
128
|
error.constructor.name;
|
|
129
129
|
console.log(`Retrying task "${pregelTask.name}" after ${interval.toFixed(2)} seconds (attempt ${attempts}) after ${errorName}: ${error}`);
|
|
130
|
-
// Clear checkpoint_ns seen (for subgraph detection)
|
|
131
|
-
const checkpointNs = pregelTask.config?.configurable?.checkpoint_ns;
|
|
132
|
-
if (checkpointNs) {
|
|
133
|
-
getSubgraphsSeenSet().delete(checkpointNs);
|
|
134
|
-
}
|
|
135
130
|
}
|
|
136
131
|
finally {
|
|
132
|
+
// Clear checkpoint_ns seen (for subgraph detection)
|
|
137
133
|
const checkpointNs = pregelTask.config?.configurable?.checkpoint_ns;
|
|
138
134
|
if (checkpointNs) {
|
|
139
135
|
getSubgraphsSeenSet().delete(checkpointNs);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findSubgraphPregel = void 0;
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
+
function isRunnableSequence(x) {
|
|
6
|
+
return "steps" in x && Array.isArray(x.steps);
|
|
7
|
+
}
|
|
8
|
+
function isPregelLike(
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
+
x
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
) {
|
|
13
|
+
return ("inputChannels" in x &&
|
|
14
|
+
x.inputChannels !== undefined &&
|
|
15
|
+
"outputChannels" &&
|
|
16
|
+
x.outputChannels !== undefined);
|
|
17
|
+
}
|
|
18
|
+
function findSubgraphPregel(candidate
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
) {
|
|
21
|
+
const candidates = [candidate];
|
|
22
|
+
for (const candidate of candidates) {
|
|
23
|
+
if (isPregelLike(candidate)) {
|
|
24
|
+
return candidate;
|
|
25
|
+
}
|
|
26
|
+
else if (isRunnableSequence(candidate)) {
|
|
27
|
+
candidates.push(...candidate.steps);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
exports.findSubgraphPregel = findSubgraphPregel;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
|
+
function isRunnableSequence(x) {
|
|
3
|
+
return "steps" in x && Array.isArray(x.steps);
|
|
4
|
+
}
|
|
5
|
+
function isPregelLike(
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
x
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
) {
|
|
10
|
+
return ("inputChannels" in x &&
|
|
11
|
+
x.inputChannels !== undefined &&
|
|
12
|
+
"outputChannels" &&
|
|
13
|
+
x.outputChannels !== undefined);
|
|
14
|
+
}
|
|
15
|
+
export function findSubgraphPregel(candidate
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
) {
|
|
18
|
+
const candidates = [candidate];
|
|
19
|
+
for (const candidate of candidates) {
|
|
20
|
+
if (isPregelLike(candidate)) {
|
|
21
|
+
return candidate;
|
|
22
|
+
}
|
|
23
|
+
else if (isRunnableSequence(candidate)) {
|
|
24
|
+
candidates.push(...candidate.steps);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
package/dist/web.cjs
CHANGED
|
@@ -14,12 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.MessagesAnnotation = exports.InMemoryStore = exports.AsyncBatchedStore = exports.BaseStore = exports.BaseCheckpointSaver = exports.emptyCheckpoint = exports.copyCheckpoint = exports.MemorySaver = exports.Send = exports.BinaryOperatorAggregate = exports.BaseChannel = exports.Annotation = exports.messagesStateReducer = exports.MessageGraph = exports.StateGraph = exports.START = exports.Graph = exports.END = void 0;
|
|
17
|
+
exports.MessagesAnnotation = exports.InMemoryStore = exports.AsyncBatchedStore = exports.BaseStore = exports.BaseCheckpointSaver = exports.emptyCheckpoint = exports.copyCheckpoint = exports.MemorySaver = exports.Send = exports.BinaryOperatorAggregate = exports.BaseChannel = exports.Annotation = exports.messagesStateReducer = exports.MessageGraph = exports.CompiledStateGraph = exports.StateGraph = exports.START = exports.Graph = exports.END = void 0;
|
|
18
18
|
var index_js_1 = require("./graph/index.cjs");
|
|
19
19
|
Object.defineProperty(exports, "END", { enumerable: true, get: function () { return index_js_1.END; } });
|
|
20
20
|
Object.defineProperty(exports, "Graph", { enumerable: true, get: function () { return index_js_1.Graph; } });
|
|
21
21
|
Object.defineProperty(exports, "START", { enumerable: true, get: function () { return index_js_1.START; } });
|
|
22
22
|
Object.defineProperty(exports, "StateGraph", { enumerable: true, get: function () { return index_js_1.StateGraph; } });
|
|
23
|
+
Object.defineProperty(exports, "CompiledStateGraph", { enumerable: true, get: function () { return index_js_1.CompiledStateGraph; } });
|
|
23
24
|
Object.defineProperty(exports, "MessageGraph", { enumerable: true, get: function () { return index_js_1.MessageGraph; } });
|
|
24
25
|
Object.defineProperty(exports, "messagesStateReducer", { enumerable: true, get: function () { return index_js_1.messagesStateReducer; } });
|
|
25
26
|
Object.defineProperty(exports, "Annotation", { enumerable: true, get: function () { return index_js_1.Annotation; } });
|
package/dist/web.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { END, Graph, type StateGraphArgs, START, StateGraph,
|
|
1
|
+
export { END, Graph, type StateGraphArgs, START, StateGraph, CompiledStateGraph, MessageGraph, messagesStateReducer, type Messages, Annotation, type StateType, type UpdateType, type NodeType, type StateDefinition, type SingleReducer, type CompiledGraph, } from "./graph/index.js";
|
|
2
2
|
export type { StateSnapshot } from "./pregel/types.js";
|
|
3
3
|
export * from "./errors.js";
|
|
4
4
|
export { BaseChannel, type BinaryOperator, BinaryOperatorAggregate, type AnyValue, type WaitForNames, type DynamicBarrierValue, type LastValue, type NamedBarrierValue, type Topic, } from "./channels/index.js";
|
package/dist/web.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { END, Graph, START, StateGraph, MessageGraph, messagesStateReducer, Annotation, } from "./graph/index.js";
|
|
1
|
+
export { END, Graph, START, StateGraph, CompiledStateGraph, MessageGraph, messagesStateReducer, Annotation, } from "./graph/index.js";
|
|
2
2
|
export * from "./errors.js";
|
|
3
3
|
export { BaseChannel, BinaryOperatorAggregate, } from "./channels/index.js";
|
|
4
4
|
export { Send } from "./constants.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/langgraph",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.15",
|
|
4
4
|
"description": "LangGraph",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@jest/globals": "^29.5.0",
|
|
44
44
|
"@langchain/anthropic": "^0.3.0",
|
|
45
45
|
"@langchain/community": "^0.3.0",
|
|
46
|
-
"@langchain/core": "^0.3.
|
|
46
|
+
"@langchain/core": "^0.3.10",
|
|
47
47
|
"@langchain/langgraph-checkpoint-postgres": "workspace:*",
|
|
48
48
|
"@langchain/langgraph-checkpoint-sqlite": "workspace:*",
|
|
49
49
|
"@langchain/openai": "^0.3.0",
|