@langchain/langgraph 0.2.28 → 0.2.29

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.
@@ -121,6 +121,9 @@ function _isSend(x) {
121
121
  return operation !== undefined && operation.lg_name === "Send";
122
122
  }
123
123
  exports._isSend = _isSend;
124
+ /**
125
+ * One or more commands to update the graph's state and send messages to nodes.
126
+ */
124
127
  class Command {
125
128
  constructor(args) {
126
129
  Object.defineProperty(this, "lg_name", {
@@ -89,11 +89,32 @@ export type Interrupt = {
89
89
  ns?: string[];
90
90
  };
91
91
  export type CommandParams<R> = {
92
+ /**
93
+ * Value to resume execution with. To be used together with {@link interrupt}.
94
+ */
92
95
  resume?: R;
96
+ /**
97
+ * Graph to send the command to. Supported values are:
98
+ * - None: the current graph (default)
99
+ * - GraphCommand.PARENT: closest parent graph
100
+ */
93
101
  graph?: string;
102
+ /**
103
+ * Update to apply to the graph's state.
104
+ */
94
105
  update?: Record<string, any>;
106
+ /**
107
+ * Can be one of the following:
108
+ * - name of the node to navigate to next (any node that belongs to the specified `graph`)
109
+ * - sequence of node names to navigate to next
110
+ * - `Send` object (to execute a node with the input provided)
111
+ * - sequence of `Send` objects
112
+ */
95
113
  goto?: string | Send | (string | Send)[];
96
114
  };
115
+ /**
116
+ * One or more commands to update the graph's state and send messages to nodes.
117
+ */
97
118
  export declare class Command<R = unknown> {
98
119
  lg_name: string;
99
120
  resume?: R;
package/dist/constants.js CHANGED
@@ -115,6 +115,9 @@ export function _isSend(x) {
115
115
  const operation = x;
116
116
  return operation !== undefined && operation.lg_name === "Send";
117
117
  }
118
+ /**
119
+ * One or more commands to update the graph's state and send messages to nodes.
120
+ */
118
121
  export class Command {
119
122
  constructor(args) {
120
123
  Object.defineProperty(this, "lg_name", {
@@ -159,6 +159,7 @@ class Graph {
159
159
  runnable,
160
160
  metadata: options?.metadata,
161
161
  subgraphs: (0, subgraph_js_1.isPregelLike)(runnable) ? [runnable] : options?.subgraphs,
162
+ ends: options?.ends,
162
163
  };
163
164
  return this;
164
165
  }
@@ -290,6 +291,11 @@ class Graph {
290
291
  }
291
292
  }
292
293
  }
294
+ for (const node of Object.values(this.nodes)) {
295
+ for (const target of node.ends ?? []) {
296
+ allTargets.add(target);
297
+ }
298
+ }
293
299
  // validate targets
294
300
  for (const node of Object.keys(this.nodes)) {
295
301
  if (!allTargets.has(node)) {
@@ -331,6 +337,7 @@ class CompiledGraph extends index_js_1.Pregel {
331
337
  triggers: [],
332
338
  metadata: node.metadata,
333
339
  subgraphs: node.subgraphs,
340
+ ends: node.ends,
334
341
  })
335
342
  .pipe(node.runnable)
336
343
  .pipe(new write_js_1.ChannelWrite([{ channel: key, value: write_js_1.PASSTHROUGH }], [constants_js_1.TAG_HIDDEN]));
@@ -526,6 +533,13 @@ class CompiledGraph extends index_js_1.Pregel {
526
533
  }
527
534
  }
528
535
  }
536
+ for (const [key, node] of Object.entries(this.builder.nodes)) {
537
+ if (node.ends !== undefined) {
538
+ for (const end of node.ends) {
539
+ addEdge(_escapeMermaidKeywords(key), _escapeMermaidKeywords(end), undefined, true);
540
+ }
541
+ }
542
+ }
529
543
  return graph;
530
544
  }
531
545
  /**
@@ -30,10 +30,12 @@ export type NodeSpec<RunInput, RunOutput> = {
30
30
  runnable: Runnable<RunInput, RunOutput>;
31
31
  metadata?: Record<string, unknown>;
32
32
  subgraphs?: Pregel<any, any>[];
33
+ ends?: string[];
33
34
  };
34
35
  export type AddNodeOptions = {
35
36
  metadata?: Record<string, unknown>;
36
37
  subgraphs?: Pregel<any, any>[];
38
+ ends?: string[];
37
39
  };
38
40
  export declare class Graph<N extends string = typeof END, RunInput = any, RunOutput = any, NodeSpecType extends NodeSpec<RunInput, RunOutput> = NodeSpec<RunInput, RunOutput>, C extends StateDefinition = StateDefinition> {
39
41
  nodes: Record<N, NodeSpecType>;
@@ -155,6 +155,7 @@ export class Graph {
155
155
  runnable,
156
156
  metadata: options?.metadata,
157
157
  subgraphs: isPregelLike(runnable) ? [runnable] : options?.subgraphs,
158
+ ends: options?.ends,
158
159
  };
159
160
  return this;
160
161
  }
@@ -286,6 +287,11 @@ export class Graph {
286
287
  }
287
288
  }
288
289
  }
290
+ for (const node of Object.values(this.nodes)) {
291
+ for (const target of node.ends ?? []) {
292
+ allTargets.add(target);
293
+ }
294
+ }
289
295
  // validate targets
290
296
  for (const node of Object.keys(this.nodes)) {
291
297
  if (!allTargets.has(node)) {
@@ -326,6 +332,7 @@ export class CompiledGraph extends Pregel {
326
332
  triggers: [],
327
333
  metadata: node.metadata,
328
334
  subgraphs: node.subgraphs,
335
+ ends: node.ends,
329
336
  })
330
337
  .pipe(node.runnable)
331
338
  .pipe(new ChannelWrite([{ channel: key, value: PASSTHROUGH }], [TAG_HIDDEN]));
@@ -521,6 +528,13 @@ export class CompiledGraph extends Pregel {
521
528
  }
522
529
  }
523
530
  }
531
+ for (const [key, node] of Object.entries(this.builder.nodes)) {
532
+ if (node.ends !== undefined) {
533
+ for (const end of node.ends) {
534
+ addEdge(_escapeMermaidKeywords(key), _escapeMermaidKeywords(end), undefined, true);
535
+ }
536
+ }
537
+ }
524
538
  return graph;
525
539
  }
526
540
  /**
@@ -240,6 +240,7 @@ class StateGraph extends graph_js_1.Graph {
240
240
  ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
241
241
  [runnable]
242
242
  : options?.subgraphs,
243
+ ends: options?.ends,
243
244
  };
244
245
  this.nodes[key] = nodeSpec;
245
246
  return this;
@@ -431,6 +432,7 @@ class CompiledStateGraph extends graph_js_1.CompiledGraph {
431
432
  metadata: node?.metadata,
432
433
  retryPolicy: node?.retryPolicy,
433
434
  subgraphs: node?.subgraphs,
435
+ ends: node?.ends,
434
436
  });
435
437
  }
436
438
  }
@@ -237,6 +237,7 @@ export class StateGraph extends Graph {
237
237
  ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
238
238
  [runnable]
239
239
  : options?.subgraphs,
240
+ ends: options?.ends,
240
241
  };
241
242
  this.nodes[key] = nodeSpec;
242
243
  return this;
@@ -427,6 +428,7 @@ export class CompiledStateGraph extends CompiledGraph {
427
428
  metadata: node?.metadata,
428
429
  retryPolicy: node?.retryPolicy,
429
430
  subgraphs: node?.subgraphs,
431
+ ends: node?.ends,
430
432
  });
431
433
  }
432
434
  }
@@ -63,7 +63,7 @@ const defaultRunnableBound =
63
63
  /* #__PURE__ */ new runnables_1.RunnablePassthrough();
64
64
  class PregelNode extends runnables_1.RunnableBinding {
65
65
  constructor(fields) {
66
- const { channels, triggers, mapper, writers, bound, kwargs, metadata, retryPolicy, tags, subgraphs, } = fields;
66
+ const { channels, triggers, mapper, writers, bound, kwargs, metadata, retryPolicy, tags, subgraphs, ends, } = fields;
67
67
  const mergedTags = [
68
68
  ...(fields.config?.tags ? fields.config.tags : []),
69
69
  ...(tags ?? []),
@@ -145,6 +145,12 @@ class PregelNode extends runnables_1.RunnableBinding {
145
145
  writable: true,
146
146
  value: void 0
147
147
  });
148
+ Object.defineProperty(this, "ends", {
149
+ enumerable: true,
150
+ configurable: true,
151
+ writable: true,
152
+ value: void 0
153
+ });
148
154
  this.channels = channels;
149
155
  this.triggers = triggers;
150
156
  this.mapper = mapper;
@@ -155,6 +161,7 @@ class PregelNode extends runnables_1.RunnableBinding {
155
161
  this.tags = mergedTags;
156
162
  this.retryPolicy = retryPolicy;
157
163
  this.subgraphs = subgraphs;
164
+ this.ends = ends;
158
165
  }
159
166
  getWriters() {
160
167
  const newWriters = [...this.writers];
@@ -21,6 +21,7 @@ interface PregelNodeArgs<RunInput, RunOutput> extends Partial<RunnableBindingArg
21
21
  metadata?: Record<string, unknown>;
22
22
  retryPolicy?: RetryPolicy;
23
23
  subgraphs?: Runnable[];
24
+ ends?: string[];
24
25
  }
25
26
  export type PregelNodeInputType = any;
26
27
  export type PregelNodeOutputType = any;
@@ -36,6 +37,7 @@ export declare class PregelNode<RunInput = PregelNodeInputType, RunOutput = Preg
36
37
  tags: string[];
37
38
  retryPolicy?: RetryPolicy;
38
39
  subgraphs?: Runnable[];
40
+ ends?: string[];
39
41
  constructor(fields: PregelNodeArgs<RunInput, RunOutput>);
40
42
  getWriters(): Array<Runnable>;
41
43
  getNode(): Runnable<RunInput, RunOutput> | undefined;
@@ -59,7 +59,7 @@ const defaultRunnableBound =
59
59
  /* #__PURE__ */ new RunnablePassthrough();
60
60
  export class PregelNode extends RunnableBinding {
61
61
  constructor(fields) {
62
- const { channels, triggers, mapper, writers, bound, kwargs, metadata, retryPolicy, tags, subgraphs, } = fields;
62
+ const { channels, triggers, mapper, writers, bound, kwargs, metadata, retryPolicy, tags, subgraphs, ends, } = fields;
63
63
  const mergedTags = [
64
64
  ...(fields.config?.tags ? fields.config.tags : []),
65
65
  ...(tags ?? []),
@@ -141,6 +141,12 @@ export class PregelNode extends RunnableBinding {
141
141
  writable: true,
142
142
  value: void 0
143
143
  });
144
+ Object.defineProperty(this, "ends", {
145
+ enumerable: true,
146
+ configurable: true,
147
+ writable: true,
148
+ value: void 0
149
+ });
144
150
  this.channels = channels;
145
151
  this.triggers = triggers;
146
152
  this.mapper = mapper;
@@ -151,6 +157,7 @@ export class PregelNode extends RunnableBinding {
151
157
  this.tags = mergedTags;
152
158
  this.retryPolicy = retryPolicy;
153
159
  this.subgraphs = subgraphs;
160
+ this.ends = ends;
154
161
  }
155
162
  getWriters() {
156
163
  const newWriters = [...this.writers];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph",
3
- "version": "0.2.28",
3
+ "version": "0.2.29",
4
4
  "description": "LangGraph",
5
5
  "type": "module",
6
6
  "engines": {