@langchain/langgraph 0.0.1 → 0.0.3-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.
- package/README.md +24 -3
- package/dist/checkpoint/base.cjs +2 -7
- package/dist/checkpoint/base.d.ts +1 -1
- package/dist/checkpoint/base.js +1 -6
- package/dist/graph/state.d.ts +9 -7
- package/dist/prebuilt/agent_executor.cjs +4 -4
- package/dist/prebuilt/agent_executor.d.ts +13 -2
- package/dist/prebuilt/agent_executor.js +5 -5
- package/dist/prebuilt/chat_agent_executor.cjs +4 -4
- package/dist/prebuilt/chat_agent_executor.d.ts +4 -0
- package/dist/prebuilt/chat_agent_executor.js +4 -4
- package/dist/prebuilt/index.d.ts +2 -2
- package/dist/prebuilt/index.js +2 -2
- package/dist/prebuilt/tool_executor.cjs +2 -2
- package/dist/prebuilt/tool_executor.d.ts +1 -1
- package/dist/prebuilt/tool_executor.js +2 -2
- package/dist/pregel/index.cjs +4 -4
- package/dist/pregel/index.js +6 -6
- package/dist/pregel/read.cjs +1 -1
- package/dist/pregel/read.js +1 -1
- package/dist/pregel/reserved.cjs +4 -5
- package/dist/pregel/reserved.d.ts +3 -3
- package/dist/pregel/reserved.js +3 -4
- package/dist/pregel/validate.cjs +1 -1
- package/dist/pregel/validate.js +2 -2
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -198,10 +198,26 @@ const _getAction = (state: { messages: Array<BaseMessage> }): AgentAction => {
|
|
|
198
198
|
};
|
|
199
199
|
};
|
|
200
200
|
|
|
201
|
-
|
|
201
|
+
// Define the function that calls the model
|
|
202
|
+
const callModel = async (
|
|
203
|
+
state: { messages: Array<BaseMessage> },
|
|
204
|
+
config?: RunnableConfig
|
|
205
|
+
) => {
|
|
206
|
+
const { messages } = state;
|
|
207
|
+
const response = await newModel.invoke(messages, config);
|
|
208
|
+
// We return a list, because this will get added to the existing list
|
|
209
|
+
return {
|
|
210
|
+
messages: [response],
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const callTool = async (
|
|
215
|
+
state: { messages: Array<BaseMessage> },
|
|
216
|
+
config?: RunnableConfig
|
|
217
|
+
) => {
|
|
202
218
|
const action = _getAction(state);
|
|
203
219
|
// We call the tool_executor and get back a response
|
|
204
|
-
const response = await toolExecutor.invoke(action);
|
|
220
|
+
const response = await toolExecutor.invoke(action, config);
|
|
205
221
|
// We use the response to create a FunctionMessage
|
|
206
222
|
const functionMessage = new FunctionMessage({
|
|
207
223
|
content: response,
|
|
@@ -315,7 +331,6 @@ Langchain Expression Language allows you to easily define chains (DAGs) but does
|
|
|
315
331
|
|
|
316
332
|
## Examples
|
|
317
333
|
|
|
318
|
-
|
|
319
334
|
### ChatAgentExecutor: with function calling
|
|
320
335
|
|
|
321
336
|
This agent executor takes a list of messages as input and outputs a list of messages.
|
|
@@ -331,6 +346,12 @@ This agent executor uses existing LangChain agents.
|
|
|
331
346
|
|
|
332
347
|
- [Getting Started Notebook](https://github.com/langchain-ai/langgraphjs/blob/main/examples/agent_executor/base.ipynb): Walks through creating this type of executor from scratch
|
|
333
348
|
|
|
349
|
+
### Multi-agent Examples
|
|
350
|
+
|
|
351
|
+
- [Multi-agent collaboration](https://github.com/langchain-ai/langgraphjs/blob/main/examples/multi_agent/multi-agent-collaboration.ipynb): how to create two agents that work together to accomplish a task
|
|
352
|
+
- [Multi-agent with supervisor](https://github.com/langchain-ai/langgraphjs/blob/main/examples/multi_agent/agent_supervisor.ipynb): how to orchestrate individual agents by using an LLM as a "supervisor" to distribute work
|
|
353
|
+
- [Hierarchical agent teams](https://github.com/langchain-ai/langgraphjs/blob/main/examples/multi_agent/hierarchical_agent_teams.ipynb): how to orchestrate "teams" of agents as nested graphs that can collaborate to solve a problem
|
|
354
|
+
|
|
334
355
|
## Documentation
|
|
335
356
|
|
|
336
357
|
There are only a few new APIs to use.
|
package/dist/checkpoint/base.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseCheckpointSaver = exports.
|
|
3
|
+
exports.BaseCheckpointSaver = exports.emptyCheckpoint = void 0;
|
|
4
4
|
function emptyCheckpoint() {
|
|
5
5
|
return {
|
|
6
6
|
v: 1,
|
|
@@ -11,18 +11,13 @@ function emptyCheckpoint() {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
exports.emptyCheckpoint = emptyCheckpoint;
|
|
14
|
-
var CheckpointAt;
|
|
15
|
-
(function (CheckpointAt) {
|
|
16
|
-
CheckpointAt["END_OF_STEP"] = "end_of_step";
|
|
17
|
-
CheckpointAt["END_OF_RUN"] = "end_of_run";
|
|
18
|
-
})(CheckpointAt || (exports.CheckpointAt = CheckpointAt = {}));
|
|
19
14
|
class BaseCheckpointSaver {
|
|
20
15
|
constructor() {
|
|
21
16
|
Object.defineProperty(this, "at", {
|
|
22
17
|
enumerable: true,
|
|
23
18
|
configurable: true,
|
|
24
19
|
writable: true,
|
|
25
|
-
value: CheckpointAt.END_OF_RUN
|
|
20
|
+
value: "end_of_run" /* CheckpointAt.END_OF_RUN */
|
|
26
21
|
});
|
|
27
22
|
}
|
|
28
23
|
get configSpecs() {
|
|
@@ -35,7 +35,7 @@ export interface Checkpoint {
|
|
|
35
35
|
versionsSeen: Record<string, Record<string, number>>;
|
|
36
36
|
}
|
|
37
37
|
export declare function emptyCheckpoint(): Checkpoint;
|
|
38
|
-
export declare enum CheckpointAt {
|
|
38
|
+
export declare const enum CheckpointAt {
|
|
39
39
|
END_OF_STEP = "end_of_step",
|
|
40
40
|
END_OF_RUN = "end_of_run"
|
|
41
41
|
}
|
package/dist/checkpoint/base.js
CHANGED
|
@@ -7,18 +7,13 @@ export function emptyCheckpoint() {
|
|
|
7
7
|
versionsSeen: {},
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
|
-
export var CheckpointAt;
|
|
11
|
-
(function (CheckpointAt) {
|
|
12
|
-
CheckpointAt["END_OF_STEP"] = "end_of_step";
|
|
13
|
-
CheckpointAt["END_OF_RUN"] = "end_of_run";
|
|
14
|
-
})(CheckpointAt || (CheckpointAt = {}));
|
|
15
10
|
export class BaseCheckpointSaver {
|
|
16
11
|
constructor() {
|
|
17
12
|
Object.defineProperty(this, "at", {
|
|
18
13
|
enumerable: true,
|
|
19
14
|
configurable: true,
|
|
20
15
|
writable: true,
|
|
21
|
-
value: CheckpointAt.END_OF_RUN
|
|
16
|
+
value: "end_of_run" /* CheckpointAt.END_OF_RUN */
|
|
22
17
|
});
|
|
23
18
|
}
|
|
24
19
|
get configSpecs() {
|
package/dist/graph/state.d.ts
CHANGED
|
@@ -4,14 +4,16 @@ import { Graph } from "./graph.js";
|
|
|
4
4
|
import { BaseCheckpointSaver } from "../checkpoint/base.js";
|
|
5
5
|
import { Pregel } from "../pregel/index.js";
|
|
6
6
|
export declare const START = "__start__";
|
|
7
|
-
export interface StateGraphArgs<
|
|
8
|
-
channels:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export interface StateGraphArgs<Channels extends Record<string, any>> {
|
|
8
|
+
channels: {
|
|
9
|
+
[K in keyof Channels]: {
|
|
10
|
+
value: BinaryOperator<Channels[K]> | null;
|
|
11
|
+
default?: () => Channels[K];
|
|
12
|
+
};
|
|
13
|
+
};
|
|
12
14
|
}
|
|
13
|
-
export declare class StateGraph<
|
|
15
|
+
export declare class StateGraph<Channels extends Record<string, any>> extends Graph<Channels> {
|
|
14
16
|
channels: Record<string, BaseChannel>;
|
|
15
|
-
constructor(fields: StateGraphArgs<
|
|
17
|
+
constructor(fields: StateGraphArgs<Channels>);
|
|
16
18
|
compile(checkpointer?: BaseCheckpointSaver): Pregel;
|
|
17
19
|
}
|
|
@@ -43,18 +43,18 @@ function createAgentExecutor({ agentRunnable, tools, inputSchema, }) {
|
|
|
43
43
|
}
|
|
44
44
|
return "continue";
|
|
45
45
|
};
|
|
46
|
-
const runAgent = async (data) => {
|
|
47
|
-
const agentOutcome = await agentRunnable.invoke(data);
|
|
46
|
+
const runAgent = async (data, config) => {
|
|
47
|
+
const agentOutcome = await agentRunnable.invoke(data, config);
|
|
48
48
|
return {
|
|
49
49
|
agentOutcome,
|
|
50
50
|
};
|
|
51
51
|
};
|
|
52
|
-
const executeTools = async (data) => {
|
|
52
|
+
const executeTools = async (data, config) => {
|
|
53
53
|
const agentAction = data.agentOutcome;
|
|
54
54
|
if (!agentAction || "returnValues" in agentAction) {
|
|
55
55
|
throw new Error("Agent has not been run yet");
|
|
56
56
|
}
|
|
57
|
-
const output = await toolExecutor.invoke(agentAction);
|
|
57
|
+
const output = await toolExecutor.invoke(agentAction, config);
|
|
58
58
|
return {
|
|
59
59
|
steps: [[agentAction, output]],
|
|
60
60
|
};
|
|
@@ -1,10 +1,21 @@
|
|
|
1
|
+
import { AgentAction, AgentFinish } from "@langchain/core/agents";
|
|
2
|
+
import { BaseMessage } from "@langchain/core/messages";
|
|
1
3
|
import { Runnable } from "@langchain/core/runnables";
|
|
2
4
|
import { Tool } from "@langchain/core/tools";
|
|
3
5
|
import { ToolExecutor } from "./tool_executor.js";
|
|
4
6
|
import { StateGraphArgs } from "../graph/state.js";
|
|
5
7
|
import { Pregel } from "../pregel/index.js";
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
+
type Step = [AgentAction | AgentFinish, string];
|
|
9
|
+
interface AgentStateBase {
|
|
10
|
+
agentOutcome?: AgentAction | AgentFinish;
|
|
11
|
+
steps: Array<Step>;
|
|
12
|
+
}
|
|
13
|
+
export interface AgentExecutorState extends AgentStateBase {
|
|
14
|
+
input: string;
|
|
15
|
+
chatHistory?: BaseMessage[];
|
|
16
|
+
}
|
|
17
|
+
type AgentChannels<T extends AgentExecutorState> = StateGraphArgs<AgentExecutorState | T>["channels"];
|
|
18
|
+
export declare function createAgentExecutor<T extends AgentExecutorState>({ agentRunnable, tools, inputSchema, }: {
|
|
8
19
|
agentRunnable: Runnable;
|
|
9
20
|
tools: Array<Tool> | ToolExecutor;
|
|
10
21
|
inputSchema?: AgentChannels<T>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RunnableLambda } from "@langchain/core/runnables";
|
|
1
|
+
import { RunnableLambda, } from "@langchain/core/runnables";
|
|
2
2
|
import { ToolExecutor } from "./tool_executor.js";
|
|
3
3
|
import { StateGraph } from "../graph/state.js";
|
|
4
4
|
import { END } from "../index.js";
|
|
@@ -40,18 +40,18 @@ export function createAgentExecutor({ agentRunnable, tools, inputSchema, }) {
|
|
|
40
40
|
}
|
|
41
41
|
return "continue";
|
|
42
42
|
};
|
|
43
|
-
const runAgent = async (data) => {
|
|
44
|
-
const agentOutcome = await agentRunnable.invoke(data);
|
|
43
|
+
const runAgent = async (data, config) => {
|
|
44
|
+
const agentOutcome = await agentRunnable.invoke(data, config);
|
|
45
45
|
return {
|
|
46
46
|
agentOutcome,
|
|
47
47
|
};
|
|
48
48
|
};
|
|
49
|
-
const executeTools = async (data) => {
|
|
49
|
+
const executeTools = async (data, config) => {
|
|
50
50
|
const agentAction = data.agentOutcome;
|
|
51
51
|
if (!agentAction || "returnValues" in agentAction) {
|
|
52
52
|
throw new Error("Agent has not been run yet");
|
|
53
53
|
}
|
|
54
|
-
const output = await toolExecutor.invoke(agentAction);
|
|
54
|
+
const output = await toolExecutor.invoke(agentAction, config);
|
|
55
55
|
return {
|
|
56
56
|
steps: [[agentAction, output]],
|
|
57
57
|
};
|
|
@@ -41,9 +41,9 @@ function createFunctionCallingExecutor({ model, tools, }) {
|
|
|
41
41
|
return "continue";
|
|
42
42
|
};
|
|
43
43
|
// Define the function that calls the model
|
|
44
|
-
const callModel = async (state) => {
|
|
44
|
+
const callModel = async (state, config) => {
|
|
45
45
|
const { messages } = state;
|
|
46
|
-
const response = await newModel.invoke(messages);
|
|
46
|
+
const response = await newModel.invoke(messages, config);
|
|
47
47
|
// We return a list, because this will get added to the existing list
|
|
48
48
|
return {
|
|
49
49
|
messages: [response],
|
|
@@ -68,10 +68,10 @@ function createFunctionCallingExecutor({ model, tools, }) {
|
|
|
68
68
|
log: "",
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
|
-
const callTool = async (state) => {
|
|
71
|
+
const callTool = async (state, config) => {
|
|
72
72
|
const action = _getAction(state);
|
|
73
73
|
// We call the tool_executor and get back a response
|
|
74
|
-
const response = await toolExecutor.invoke(action);
|
|
74
|
+
const response = await toolExecutor.invoke(action, config);
|
|
75
75
|
// We use the response to create a FunctionMessage
|
|
76
76
|
const functionMessage = new messages_1.FunctionMessage({
|
|
77
77
|
content: response,
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Tool } from "@langchain/core/tools";
|
|
2
|
+
import { BaseMessage } from "@langchain/core/messages";
|
|
2
3
|
import { ToolExecutor } from "./tool_executor.js";
|
|
4
|
+
export type FunctionCallingExecutorState = {
|
|
5
|
+
messages: Array<BaseMessage>;
|
|
6
|
+
};
|
|
3
7
|
export declare function createFunctionCallingExecutor<Model extends object>({ model, tools, }: {
|
|
4
8
|
model: Model;
|
|
5
9
|
tools: Array<Tool> | ToolExecutor;
|
|
@@ -38,9 +38,9 @@ export function createFunctionCallingExecutor({ model, tools, }) {
|
|
|
38
38
|
return "continue";
|
|
39
39
|
};
|
|
40
40
|
// Define the function that calls the model
|
|
41
|
-
const callModel = async (state) => {
|
|
41
|
+
const callModel = async (state, config) => {
|
|
42
42
|
const { messages } = state;
|
|
43
|
-
const response = await newModel.invoke(messages);
|
|
43
|
+
const response = await newModel.invoke(messages, config);
|
|
44
44
|
// We return a list, because this will get added to the existing list
|
|
45
45
|
return {
|
|
46
46
|
messages: [response],
|
|
@@ -65,10 +65,10 @@ export function createFunctionCallingExecutor({ model, tools, }) {
|
|
|
65
65
|
log: "",
|
|
66
66
|
};
|
|
67
67
|
};
|
|
68
|
-
const callTool = async (state) => {
|
|
68
|
+
const callTool = async (state, config) => {
|
|
69
69
|
const action = _getAction(state);
|
|
70
70
|
// We call the tool_executor and get back a response
|
|
71
|
-
const response = await toolExecutor.invoke(action);
|
|
71
|
+
const response = await toolExecutor.invoke(action, config);
|
|
72
72
|
// We use the response to create a FunctionMessage
|
|
73
73
|
const functionMessage = new FunctionMessage({
|
|
74
74
|
content: response,
|
package/dist/prebuilt/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { createAgentExecutor } from "./agent_executor.js";
|
|
2
|
-
export { createFunctionCallingExecutor } from "./chat_agent_executor.js";
|
|
1
|
+
export { type AgentExecutorState, createAgentExecutor, } from "./agent_executor.js";
|
|
2
|
+
export { type FunctionCallingExecutorState, createFunctionCallingExecutor, } from "./chat_agent_executor.js";
|
|
3
3
|
export { type ToolExecutorArgs, type ToolInvocationInterface, ToolExecutor, } from "./tool_executor.js";
|
package/dist/prebuilt/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { createAgentExecutor } from "./agent_executor.js";
|
|
2
|
-
export { createFunctionCallingExecutor } from "./chat_agent_executor.js";
|
|
1
|
+
export { createAgentExecutor, } from "./agent_executor.js";
|
|
2
|
+
export { createFunctionCallingExecutor, } from "./chat_agent_executor.js";
|
|
3
3
|
export { ToolExecutor, } from "./tool_executor.js";
|
|
@@ -47,7 +47,7 @@ class ToolExecutor extends runnables_1.RunnableBinding {
|
|
|
47
47
|
return acc;
|
|
48
48
|
}, {});
|
|
49
49
|
}
|
|
50
|
-
async _execute(toolInvocation,
|
|
50
|
+
async _execute(toolInvocation, config) {
|
|
51
51
|
if (!(toolInvocation.tool in this.toolMap)) {
|
|
52
52
|
return this.invalidToolMsgTemplate
|
|
53
53
|
.replace("{requestedToolName}", toolInvocation.tool)
|
|
@@ -55,7 +55,7 @@ class ToolExecutor extends runnables_1.RunnableBinding {
|
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
57
|
const tool = this.toolMap[toolInvocation.tool];
|
|
58
|
-
const output = await tool.invoke(toolInvocation.toolInput);
|
|
58
|
+
const output = await tool.invoke(toolInvocation.toolInput, config);
|
|
59
59
|
return output;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -22,6 +22,6 @@ export declare class ToolExecutor extends RunnableBinding<ToolExecutorInputType,
|
|
|
22
22
|
toolMap: Record<string, Tool>;
|
|
23
23
|
invalidToolMsgTemplate: string;
|
|
24
24
|
constructor(fields: ToolExecutorArgs);
|
|
25
|
-
_execute(toolInvocation: ToolInvocationInterface,
|
|
25
|
+
_execute(toolInvocation: ToolInvocationInterface, config?: RunnableConfig): Promise<string>;
|
|
26
26
|
}
|
|
27
27
|
export {};
|
|
@@ -44,7 +44,7 @@ export class ToolExecutor extends RunnableBinding {
|
|
|
44
44
|
return acc;
|
|
45
45
|
}, {});
|
|
46
46
|
}
|
|
47
|
-
async _execute(toolInvocation,
|
|
47
|
+
async _execute(toolInvocation, config) {
|
|
48
48
|
if (!(toolInvocation.tool in this.toolMap)) {
|
|
49
49
|
return this.invalidToolMsgTemplate
|
|
50
50
|
.replace("{requestedToolName}", toolInvocation.tool)
|
|
@@ -52,7 +52,7 @@ export class ToolExecutor extends RunnableBinding {
|
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
54
54
|
const tool = this.toolMap[toolInvocation.tool];
|
|
55
|
-
const output = await tool.invoke(toolInvocation.toolInput);
|
|
55
|
+
const output = await tool.invoke(toolInvocation.toolInput, config);
|
|
56
56
|
return output;
|
|
57
57
|
}
|
|
58
58
|
}
|
package/dist/pregel/index.cjs
CHANGED
|
@@ -256,7 +256,7 @@ class Pregel extends runnables_1.Runnable {
|
|
|
256
256
|
}
|
|
257
257
|
// save end of step checkpoint
|
|
258
258
|
if (this.checkpointer &&
|
|
259
|
-
this.checkpointer.at ===
|
|
259
|
+
this.checkpointer.at === "end_of_step" /* CheckpointAt.END_OF_STEP */) {
|
|
260
260
|
checkpoint = await (0, base_js_1.createCheckpoint)(checkpoint, channels);
|
|
261
261
|
this.checkpointer.put(config, checkpoint);
|
|
262
262
|
}
|
|
@@ -266,7 +266,7 @@ class Pregel extends runnables_1.Runnable {
|
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
// save end of run checkpoint
|
|
269
|
-
if (this.checkpointer && this.checkpointer.at ===
|
|
269
|
+
if (this.checkpointer && this.checkpointer.at === "end_of_run" /* CheckpointAt.END_OF_RUN */) {
|
|
270
270
|
checkpoint = await (0, base_js_1.createCheckpoint)(checkpoint, channels);
|
|
271
271
|
this.checkpointer.put(config, checkpoint);
|
|
272
272
|
}
|
|
@@ -342,7 +342,7 @@ pendingWrites, config, forStep) {
|
|
|
342
342
|
const pendingWritesByChannel = {};
|
|
343
343
|
// Group writes by channel
|
|
344
344
|
for (const [chan, val] of pendingWrites) {
|
|
345
|
-
for (const c in reserved_js_1.
|
|
345
|
+
for (const c in reserved_js_1.ReservedChannelsMap) {
|
|
346
346
|
if (chan === c) {
|
|
347
347
|
throw new Error(`Can't write to reserved channel ${chan}`);
|
|
348
348
|
}
|
|
@@ -355,7 +355,7 @@ pendingWrites, config, forStep) {
|
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
357
|
// Update reserved channels
|
|
358
|
-
pendingWritesByChannel[reserved_js_1.
|
|
358
|
+
pendingWritesByChannel[reserved_js_1.ReservedChannelsMap.isLastStep] = [
|
|
359
359
|
forStep + 1 === config.recursionLimit,
|
|
360
360
|
];
|
|
361
361
|
const updatedChannels = new Set();
|
package/dist/pregel/index.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import { Runnable, _coerceToRunnable, patchConfig, } from "@langchain/core/runnables";
|
|
3
3
|
import { IterableReadableStream } from "@langchain/core/utils/stream";
|
|
4
4
|
import { EmptyChannelError, createCheckpoint, emptyChannels, } from "../channels/base.js";
|
|
5
|
-
import {
|
|
5
|
+
import { emptyCheckpoint, } from "../checkpoint/base.js";
|
|
6
6
|
import { ChannelBatch, ChannelInvoke } from "./read.js";
|
|
7
7
|
import { validateGraph } from "./validate.js";
|
|
8
|
-
import {
|
|
8
|
+
import { ReservedChannelsMap } from "./reserved.js";
|
|
9
9
|
import { mapInput, mapOutput } from "./io.js";
|
|
10
10
|
import { ChannelWrite } from "./write.js";
|
|
11
11
|
import { CONFIG_KEY_READ, CONFIG_KEY_SEND } from "../constants.js";
|
|
@@ -251,7 +251,7 @@ export class Pregel extends Runnable {
|
|
|
251
251
|
}
|
|
252
252
|
// save end of step checkpoint
|
|
253
253
|
if (this.checkpointer &&
|
|
254
|
-
this.checkpointer.at === CheckpointAt.END_OF_STEP) {
|
|
254
|
+
this.checkpointer.at === "end_of_step" /* CheckpointAt.END_OF_STEP */) {
|
|
255
255
|
checkpoint = await createCheckpoint(checkpoint, channels);
|
|
256
256
|
this.checkpointer.put(config, checkpoint);
|
|
257
257
|
}
|
|
@@ -261,7 +261,7 @@ export class Pregel extends Runnable {
|
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
// save end of run checkpoint
|
|
264
|
-
if (this.checkpointer && this.checkpointer.at === CheckpointAt.END_OF_RUN) {
|
|
264
|
+
if (this.checkpointer && this.checkpointer.at === "end_of_run" /* CheckpointAt.END_OF_RUN */) {
|
|
265
265
|
checkpoint = await createCheckpoint(checkpoint, channels);
|
|
266
266
|
this.checkpointer.put(config, checkpoint);
|
|
267
267
|
}
|
|
@@ -336,7 +336,7 @@ pendingWrites, config, forStep) {
|
|
|
336
336
|
const pendingWritesByChannel = {};
|
|
337
337
|
// Group writes by channel
|
|
338
338
|
for (const [chan, val] of pendingWrites) {
|
|
339
|
-
for (const c in
|
|
339
|
+
for (const c in ReservedChannelsMap) {
|
|
340
340
|
if (chan === c) {
|
|
341
341
|
throw new Error(`Can't write to reserved channel ${chan}`);
|
|
342
342
|
}
|
|
@@ -349,7 +349,7 @@ pendingWrites, config, forStep) {
|
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
351
|
// Update reserved channels
|
|
352
|
-
pendingWritesByChannel[
|
|
352
|
+
pendingWritesByChannel[ReservedChannelsMap.isLastStep] = [
|
|
353
353
|
forStep + 1 === config.recursionLimit,
|
|
354
354
|
];
|
|
355
355
|
const updatedChannels = new Set();
|
package/dist/pregel/read.cjs
CHANGED
|
@@ -58,7 +58,7 @@ class ChannelRead extends runnables_1.RunnableLambda {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
exports.ChannelRead = ChannelRead;
|
|
61
|
-
const defaultRunnableBound = new runnables_1.RunnablePassthrough();
|
|
61
|
+
const defaultRunnableBound = /* #__PURE__ */ new runnables_1.RunnablePassthrough();
|
|
62
62
|
class ChannelInvoke extends runnables_1.RunnableBinding {
|
|
63
63
|
constructor(fields) {
|
|
64
64
|
const { channels, triggers, when } = fields;
|
package/dist/pregel/read.js
CHANGED
|
@@ -54,7 +54,7 @@ export class ChannelRead extends RunnableLambda {
|
|
|
54
54
|
return read(this.channel);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
const defaultRunnableBound = new RunnablePassthrough();
|
|
57
|
+
const defaultRunnableBound = /* #__PURE__ */ new RunnablePassthrough();
|
|
58
58
|
export class ChannelInvoke extends RunnableBinding {
|
|
59
59
|
constructor(fields) {
|
|
60
60
|
const { channels, triggers, when } = fields;
|
package/dist/pregel/reserved.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
})(ReservedChannels || (exports.ReservedChannels = ReservedChannels = {}));
|
|
3
|
+
exports.ReservedChannelsMap = void 0;
|
|
4
|
+
exports.ReservedChannelsMap = {
|
|
5
|
+
isLastStep: "isLastStep",
|
|
6
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
isLastStep
|
|
3
|
-
}
|
|
1
|
+
export declare const ReservedChannelsMap: {
|
|
2
|
+
isLastStep: string;
|
|
3
|
+
};
|
package/dist/pregel/reserved.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
})(ReservedChannels || (ReservedChannels = {}));
|
|
1
|
+
export const ReservedChannelsMap = {
|
|
2
|
+
isLastStep: "isLastStep",
|
|
3
|
+
};
|
package/dist/pregel/validate.cjs
CHANGED
|
@@ -63,7 +63,7 @@ function validateGraph({ nodes, channels, input, output, hidden, interrupt, }) {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
for (const chan in reserved_js_1.
|
|
66
|
+
for (const chan in reserved_js_1.ReservedChannelsMap) {
|
|
67
67
|
if (!(chan in newChannels)) {
|
|
68
68
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
69
|
newChannels[chan] = new last_value_js_1.LastValue();
|
package/dist/pregel/validate.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LastValue } from "../channels/last_value.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ReservedChannelsMap } from "./reserved.js";
|
|
3
3
|
export function validateGraph({ nodes, channels, input, output, hidden, interrupt, }) {
|
|
4
4
|
const newChannels = channels;
|
|
5
5
|
const subscribedChannels = new Set();
|
|
@@ -60,7 +60,7 @@ export function validateGraph({ nodes, channels, input, output, hidden, interrup
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
for (const chan in
|
|
63
|
+
for (const chan in ReservedChannelsMap) {
|
|
64
64
|
if (!(chan in newChannels)) {
|
|
65
65
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
66
|
newChannels[chan] = new LastValue();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/langgraph",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-rc.0",
|
|
4
4
|
"description": "LangGraph",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -32,14 +32,11 @@
|
|
|
32
32
|
"author": "LangChain",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@langchain/
|
|
36
|
-
"@langchain/core": "^0.1.15",
|
|
37
|
-
"@langchain/openai": "^0.0.12",
|
|
38
|
-
"langchain": "^0.1.3",
|
|
39
|
-
"zod": "^3.22.4"
|
|
35
|
+
"@langchain/core": "^0.1.22"
|
|
40
36
|
},
|
|
41
37
|
"devDependencies": {
|
|
42
38
|
"@jest/globals": "^29.5.0",
|
|
39
|
+
"@langchain/community": "^0.0.17",
|
|
43
40
|
"@langchain/openai": "^0.0.12",
|
|
44
41
|
"@swc/core": "^1.3.90",
|
|
45
42
|
"@swc/jest": "^0.2.29",
|
|
@@ -56,12 +53,14 @@
|
|
|
56
53
|
"eslint-plugin-prettier": "^4.2.1",
|
|
57
54
|
"jest": "^29.5.0",
|
|
58
55
|
"jest-environment-node": "^29.6.4",
|
|
56
|
+
"langchain": "^0.1.3",
|
|
59
57
|
"prettier": "^2.8.3",
|
|
60
58
|
"release-it": "^15.10.1",
|
|
61
59
|
"rollup": "^4.5.2",
|
|
62
60
|
"ts-jest": "^29.1.0",
|
|
63
61
|
"tsx": "^4.7.0",
|
|
64
|
-
"typescript": "<5.2.0"
|
|
62
|
+
"typescript": "<5.2.0",
|
|
63
|
+
"zod": "^3.22.4"
|
|
65
64
|
},
|
|
66
65
|
"publishConfig": {
|
|
67
66
|
"access": "public",
|