@langchain/langgraph 0.0.34 → 0.1.0-rc.0

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.
Files changed (82) hide show
  1. package/README.md +11 -15
  2. package/dist/channels/any_value.cjs +3 -1
  3. package/dist/channels/any_value.d.ts +1 -1
  4. package/dist/channels/any_value.js +3 -1
  5. package/dist/channels/base.cjs +8 -0
  6. package/dist/channels/base.d.ts +12 -1
  7. package/dist/channels/base.js +8 -0
  8. package/dist/channels/binop.cjs +2 -1
  9. package/dist/channels/binop.d.ts +1 -1
  10. package/dist/channels/binop.js +2 -1
  11. package/dist/channels/dynamic_barrier_value.cjs +30 -18
  12. package/dist/channels/dynamic_barrier_value.d.ts +2 -1
  13. package/dist/channels/dynamic_barrier_value.js +30 -18
  14. package/dist/channels/ephemeral_value.cjs +3 -1
  15. package/dist/channels/ephemeral_value.d.ts +1 -1
  16. package/dist/channels/ephemeral_value.js +3 -1
  17. package/dist/channels/last_value.cjs +3 -2
  18. package/dist/channels/last_value.d.ts +1 -1
  19. package/dist/channels/last_value.js +3 -2
  20. package/dist/channels/named_barrier_value.cjs +14 -6
  21. package/dist/channels/named_barrier_value.d.ts +2 -1
  22. package/dist/channels/named_barrier_value.js +15 -7
  23. package/dist/channels/topic.cjs +10 -11
  24. package/dist/channels/topic.d.ts +1 -1
  25. package/dist/channels/topic.js +10 -11
  26. package/dist/checkpoint/base.cjs +9 -0
  27. package/dist/checkpoint/base.d.ts +23 -18
  28. package/dist/checkpoint/base.js +9 -0
  29. package/dist/checkpoint/id.cjs +13 -1
  30. package/dist/checkpoint/id.d.ts +1 -0
  31. package/dist/checkpoint/id.js +12 -1
  32. package/dist/checkpoint/index.d.ts +2 -1
  33. package/dist/checkpoint/memory.cjs +152 -39
  34. package/dist/checkpoint/memory.d.ts +6 -3
  35. package/dist/checkpoint/memory.js +152 -39
  36. package/dist/checkpoint/serde/types.cjs +2 -0
  37. package/dist/checkpoint/serde/types.d.ts +40 -0
  38. package/dist/checkpoint/serde/types.js +1 -0
  39. package/dist/checkpoint/sqlite.cjs +127 -98
  40. package/dist/checkpoint/sqlite.d.ts +5 -3
  41. package/dist/checkpoint/sqlite.js +127 -98
  42. package/dist/checkpoint/types.cjs +2 -0
  43. package/dist/checkpoint/types.d.ts +28 -0
  44. package/dist/checkpoint/types.js +1 -0
  45. package/dist/constants.cjs +17 -1
  46. package/dist/constants.d.ts +7 -0
  47. package/dist/constants.js +16 -0
  48. package/dist/errors.cjs +21 -1
  49. package/dist/errors.d.ts +8 -0
  50. package/dist/errors.js +18 -0
  51. package/dist/graph/graph.cjs +6 -3
  52. package/dist/graph/graph.d.ts +6 -2
  53. package/dist/graph/graph.js +7 -4
  54. package/dist/graph/index.d.ts +1 -1
  55. package/dist/graph/state.cjs +7 -7
  56. package/dist/graph/state.js +7 -7
  57. package/dist/pregel/algo.cjs +384 -0
  58. package/dist/pregel/algo.d.ts +32 -0
  59. package/dist/pregel/algo.js +374 -0
  60. package/dist/pregel/debug.cjs +158 -9
  61. package/dist/pregel/debug.d.ts +39 -2
  62. package/dist/pregel/debug.js +151 -7
  63. package/dist/pregel/index.cjs +217 -509
  64. package/dist/pregel/index.d.ts +29 -66
  65. package/dist/pregel/index.js +219 -506
  66. package/dist/pregel/io.cjs +2 -2
  67. package/dist/pregel/io.d.ts +5 -4
  68. package/dist/pregel/io.js +2 -2
  69. package/dist/pregel/loop.cjs +428 -0
  70. package/dist/pregel/loop.d.ts +84 -0
  71. package/dist/pregel/loop.js +421 -0
  72. package/dist/pregel/types.d.ts +53 -4
  73. package/dist/pregel/utils.cjs +33 -0
  74. package/dist/pregel/utils.d.ts +3 -0
  75. package/dist/pregel/utils.js +28 -0
  76. package/dist/pregel/write.cjs +3 -1
  77. package/dist/pregel/write.js +3 -1
  78. package/dist/utils.cjs +21 -1
  79. package/dist/utils.d.ts +4 -0
  80. package/dist/utils.js +18 -0
  81. package/dist/web.d.ts +3 -2
  82. package/package.json +4 -2
@@ -1,11 +1,10 @@
1
1
  import { Runnable, RunnableConfig, RunnableFunc } from "@langchain/core/runnables";
2
- import { CallbackManagerForChainRun } from "@langchain/core/callbacks/manager";
3
- import { IterableReadableStream } from "@langchain/core/utils/stream";
4
2
  import { BaseChannel } from "../channels/base.js";
5
- import { BaseCheckpointSaver, Checkpoint, ReadonlyCheckpoint } from "../checkpoint/base.js";
3
+ import { BaseCheckpointSaver, CheckpointListOptions } from "../checkpoint/base.js";
6
4
  import { PregelNode } from "./read.js";
7
5
  import { ChannelWrite } from "./write.js";
8
- import { All, PregelExecutableTask, PregelTaskDescription, StateSnapshot } from "./types.js";
6
+ import { All, PregelInterface, PregelParams, StateSnapshot, StreamMode } from "./types.js";
7
+ import { StrRecord } from "./algo.js";
9
8
  type WriteValue = Runnable | RunnableFunc<unknown, unknown> | unknown;
10
9
  export declare class Channel {
11
10
  static subscribeTo(channels: string, options?: {
@@ -17,51 +16,20 @@ export declare class Channel {
17
16
  }): PregelNode;
18
17
  static writeTo(channels: string[], kwargs?: Record<string, WriteValue>): ChannelWrite;
19
18
  }
20
- export type StreamMode = "values" | "updates";
21
19
  /**
22
- * Construct a type with a set of properties K of type T
20
+ * Config for executing the graph.
23
21
  */
24
- type StrRecord<K extends string, T> = {
25
- [P in K]: T;
26
- };
27
- export interface PregelInterface<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>> {
28
- nodes: Nn;
29
- channels: Cc;
30
- inputs: keyof Cc | Array<keyof Cc>;
31
- outputs: keyof Cc | Array<keyof Cc>;
32
- /**
33
- * @default true
34
- */
35
- autoValidate?: boolean;
36
- /**
37
- * @default "values"
38
- */
39
- streamMode?: StreamMode;
40
- streamChannels?: keyof Cc | Array<keyof Cc>;
41
- /**
42
- * @default []
43
- */
44
- interruptAfter?: Array<keyof Nn> | All;
45
- /**
46
- * @default []
47
- */
48
- interruptBefore?: Array<keyof Nn> | All;
49
- /**
50
- * @default undefined
51
- */
52
- stepTimeout?: number;
53
- /**
54
- * @default false
55
- */
56
- debug?: boolean;
57
- checkpointer?: BaseCheckpointSaver;
58
- }
59
22
  export interface PregelOptions<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>> extends RunnableConfig {
60
- streamMode?: StreamMode;
23
+ /** The stream mode for the graph run. Default is ["values"]. */
24
+ streamMode?: StreamMode | StreamMode[];
61
25
  inputKeys?: keyof Cc | Array<keyof Cc>;
26
+ /** The output keys to retrieve from the graph run. */
62
27
  outputKeys?: keyof Cc | Array<keyof Cc>;
28
+ /** The nodes to interrupt the graph run before. */
63
29
  interruptBefore?: All | Array<keyof Nn>;
30
+ /** The nodes to interrupt the graph run after. */
64
31
  interruptAfter?: All | Array<keyof Nn>;
32
+ /** Enable debug mode for the graph run. */
65
33
  debug?: boolean;
66
34
  }
67
35
  export type PregelInputType = any;
@@ -71,49 +39,44 @@ export declare class Pregel<Nn extends StrRecord<string, PregelNode>, Cc extends
71
39
  lc_namespace: string[];
72
40
  nodes: Nn;
73
41
  channels: Cc;
74
- inputs: keyof Cc | Array<keyof Cc>;
75
- outputs: keyof Cc | Array<keyof Cc>;
42
+ inputChannels: keyof Cc | Array<keyof Cc>;
43
+ outputChannels: keyof Cc | Array<keyof Cc>;
76
44
  autoValidate: boolean;
77
- streamMode: StreamMode;
45
+ streamMode: StreamMode[];
78
46
  streamChannels?: keyof Cc | Array<keyof Cc>;
79
47
  interruptAfter?: Array<keyof Nn> | All;
80
48
  interruptBefore?: Array<keyof Nn> | All;
81
49
  stepTimeout?: number;
82
50
  debug: boolean;
83
51
  checkpointer?: BaseCheckpointSaver;
84
- constructor(fields: PregelInterface<Nn, Cc>);
52
+ constructor(fields: PregelParams<Nn, Cc>);
85
53
  validate(): this;
86
54
  get streamChannelsList(): Array<keyof Cc>;
87
55
  get streamChannelsAsIs(): keyof Cc | Array<keyof Cc>;
88
56
  getState(config: RunnableConfig): Promise<StateSnapshot>;
89
- getStateHistory(config: RunnableConfig, limit?: number, before?: RunnableConfig): AsyncIterableIterator<StateSnapshot>;
57
+ getStateHistory(config: RunnableConfig, options?: CheckpointListOptions): AsyncIterableIterator<StateSnapshot>;
90
58
  updateState(config: RunnableConfig, values: Record<string, unknown> | unknown, asNode?: keyof Nn): Promise<RunnableConfig>;
91
59
  _defaults(config: PregelOptions<Nn, Cc>): [
92
60
  boolean,
93
- StreamMode,
61
+ StreamMode[],
94
62
  // stream mode
95
- keyof Cc | Array<keyof Cc>,
63
+ string | string[],
96
64
  // input keys
97
- keyof Cc | Array<keyof Cc>,
65
+ string | string[],
98
66
  RunnableConfig,
99
67
  // config without pregel keys
100
- All | Array<keyof Nn>,
68
+ All | string[],
101
69
  // interrupt before
102
- All | Array<keyof Nn>
70
+ All | string[],
71
+ // interrupt after
72
+ BaseCheckpointSaver | undefined
103
73
  ];
104
- _transform(input: AsyncGenerator<PregelInputType>, runManager?: CallbackManagerForChainRun, config?: PregelOptions<Nn, Cc>): AsyncGenerator<PregelOutputType>;
105
- invoke(input: PregelInputType, options?: PregelOptions<Nn, Cc>): Promise<PregelOutputType>;
106
- stream(input: PregelInputType, config?: PregelOptions<Nn, Cc>): Promise<IterableReadableStream<PregelOutputType>>;
107
- transform(generator: AsyncGenerator<PregelInputType>, config?: PregelOptions<Nn, Cc>): AsyncGenerator<PregelOutputType>;
74
+ _streamIterator(input: PregelInputType, options?: Partial<PregelOptions<Nn, Cc>>): AsyncGenerator<PregelOutputType>;
75
+ /**
76
+ * Run the graph with a single input and config.
77
+ * @param input
78
+ * @param options
79
+ */
80
+ invoke(input: PregelInputType, options?: Partial<PregelOptions<Nn, Cc>>): Promise<PregelOutputType>;
108
81
  }
109
- export declare function _shouldInterrupt<N extends PropertyKey, C extends PropertyKey>(checkpoint: ReadonlyCheckpoint, interruptNodes: All | Array<N>, snapshotChannels: Array<C>, tasks: Array<PregelExecutableTask<N, C>>): boolean;
110
- export declare function _localRead<Cc extends StrRecord<string, BaseChannel>>(checkpoint: ReadonlyCheckpoint, channels: Cc, writes: Array<[keyof Cc, unknown]>, select: Array<keyof Cc> | keyof Cc, fresh?: boolean): Record<string, unknown> | unknown;
111
- export declare function _localWrite(commit: (writes: [string, any][]) => void, processes: Record<string, PregelNode>, channels: Record<string, BaseChannel>, writes: [string, any][]): void;
112
- export declare function _applyWrites<Cc extends Record<string, BaseChannel>>(checkpoint: Checkpoint, channels: Cc, pendingWrites: Array<[keyof Cc, unknown]>): void;
113
- export declare function _prepareNextTasks<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>>(checkpoint: ReadonlyCheckpoint, processes: Nn, channels: Cc, forExecution: false, extra: {
114
- step: number;
115
- }): [Checkpoint, Array<PregelTaskDescription>];
116
- export declare function _prepareNextTasks<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>>(checkpoint: ReadonlyCheckpoint, processes: Nn, channels: Cc, forExecution: true, extra: {
117
- step: number;
118
- }): [Checkpoint, Array<PregelExecutableTask<keyof Nn, keyof Cc>>];
119
82
  export {};