@langchain/langgraph 0.0.4 → 0.0.6

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.
@@ -60,11 +60,23 @@ class Graph {
60
60
  writable: true,
61
61
  value: void 0
62
62
  });
63
+ Object.defineProperty(this, "compiled", {
64
+ enumerable: true,
65
+ configurable: true,
66
+ writable: true,
67
+ value: false
68
+ });
63
69
  this.nodes = {};
64
70
  this.edges = new Set();
65
71
  this.branches = {};
66
72
  }
73
+ warnIfCompiled(message) {
74
+ if (this.compiled) {
75
+ console.warn(message);
76
+ }
77
+ }
67
78
  addNode(key, action) {
79
+ this.warnIfCompiled(`Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
68
80
  if (this.nodes[key]) {
69
81
  throw new Error(`Node \`${key}\` already present.`);
70
82
  }
@@ -74,6 +86,7 @@ class Graph {
74
86
  this.nodes[key] = (0, runnables_1._coerceToRunnable)(action);
75
87
  }
76
88
  addEdge(startKey, endKey) {
89
+ this.warnIfCompiled(`Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
77
90
  if (startKey === exports.END) {
78
91
  throw new Error("END cannot be a start node");
79
92
  }
@@ -90,6 +103,7 @@ class Graph {
90
103
  this.edges.add([startKey, endKey]);
91
104
  }
92
105
  addConditionalEdges(startKey, condition, conditionalEdgeMapping) {
106
+ this.warnIfCompiled("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.");
93
107
  if (!this.nodes[startKey]) {
94
108
  throw new Error(`Need to addNode \`${startKey}\` first`);
95
109
  }
@@ -111,12 +125,14 @@ class Graph {
111
125
  this.branches[startKey].push(new Branch(condition, conditionalEdgeMapping));
112
126
  }
113
127
  setEntryPoint(key) {
128
+ this.warnIfCompiled("Setting the entry point of a graph that has already been compiled. This will not be reflected in the compiled graph.");
114
129
  if (!this.nodes[key]) {
115
130
  throw new Error(`Need to addNode \`${key}\` first`);
116
131
  }
117
132
  this.entryPoint = key;
118
133
  }
119
134
  setFinishPoint(key) {
135
+ this.warnIfCompiled("Setting a finish point of a graph that has already been compiled. This will not be reflected in the compiled graph.");
120
136
  this.addEdge(key, exports.END);
121
137
  }
122
138
  compile(checkpointer) {
@@ -185,6 +201,7 @@ class Graph {
185
201
  }
186
202
  }
187
203
  }
204
+ this.compiled = true;
188
205
  }
189
206
  }
190
207
  exports.Graph = Graph;
@@ -18,7 +18,9 @@ export declare class Graph<RunInput = any, RunOutput = any> {
18
18
  edges: Set<[string, string]>;
19
19
  branches: Record<string, Branch[]>;
20
20
  entryPoint?: string;
21
+ compiled: boolean;
21
22
  constructor();
23
+ private warnIfCompiled;
22
24
  addNode(key: string, action: RunnableLike<RunInput, RunOutput>): void;
23
25
  addEdge(startKey: string, endKey: string): void;
24
26
  addConditionalEdges(startKey: string, condition: CallableFunction, conditionalEdgeMapping?: Record<string, string>): void;
@@ -57,11 +57,23 @@ export class Graph {
57
57
  writable: true,
58
58
  value: void 0
59
59
  });
60
+ Object.defineProperty(this, "compiled", {
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true,
64
+ value: false
65
+ });
60
66
  this.nodes = {};
61
67
  this.edges = new Set();
62
68
  this.branches = {};
63
69
  }
70
+ warnIfCompiled(message) {
71
+ if (this.compiled) {
72
+ console.warn(message);
73
+ }
74
+ }
64
75
  addNode(key, action) {
76
+ this.warnIfCompiled(`Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
65
77
  if (this.nodes[key]) {
66
78
  throw new Error(`Node \`${key}\` already present.`);
67
79
  }
@@ -71,6 +83,7 @@ export class Graph {
71
83
  this.nodes[key] = _coerceToRunnable(action);
72
84
  }
73
85
  addEdge(startKey, endKey) {
86
+ this.warnIfCompiled(`Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
74
87
  if (startKey === END) {
75
88
  throw new Error("END cannot be a start node");
76
89
  }
@@ -87,6 +100,7 @@ export class Graph {
87
100
  this.edges.add([startKey, endKey]);
88
101
  }
89
102
  addConditionalEdges(startKey, condition, conditionalEdgeMapping) {
103
+ this.warnIfCompiled("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.");
90
104
  if (!this.nodes[startKey]) {
91
105
  throw new Error(`Need to addNode \`${startKey}\` first`);
92
106
  }
@@ -108,12 +122,14 @@ export class Graph {
108
122
  this.branches[startKey].push(new Branch(condition, conditionalEdgeMapping));
109
123
  }
110
124
  setEntryPoint(key) {
125
+ this.warnIfCompiled("Setting the entry point of a graph that has already been compiled. This will not be reflected in the compiled graph.");
111
126
  if (!this.nodes[key]) {
112
127
  throw new Error(`Need to addNode \`${key}\` first`);
113
128
  }
114
129
  this.entryPoint = key;
115
130
  }
116
131
  setFinishPoint(key) {
132
+ this.warnIfCompiled("Setting a finish point of a graph that has already been compiled. This will not be reflected in the compiled graph.");
117
133
  this.addEdge(key, END);
118
134
  }
119
135
  compile(checkpointer) {
@@ -182,5 +198,6 @@ export class Graph {
182
198
  }
183
199
  }
184
200
  }
201
+ this.compiled = true;
185
202
  }
186
203
  }
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StateGraph = exports.START = exports.Graph = exports.END = void 0;
3
+ exports.MessageGraph = exports.StateGraph = exports.START = exports.Graph = exports.END = void 0;
4
4
  var graph_js_1 = require("./graph.cjs");
5
5
  Object.defineProperty(exports, "END", { enumerable: true, get: function () { return graph_js_1.END; } });
6
6
  Object.defineProperty(exports, "Graph", { enumerable: true, get: function () { return graph_js_1.Graph; } });
7
7
  var state_js_1 = require("./state.cjs");
8
8
  Object.defineProperty(exports, "START", { enumerable: true, get: function () { return state_js_1.START; } });
9
9
  Object.defineProperty(exports, "StateGraph", { enumerable: true, get: function () { return state_js_1.StateGraph; } });
10
+ var message_js_1 = require("./message.cjs");
11
+ Object.defineProperty(exports, "MessageGraph", { enumerable: true, get: function () { return message_js_1.MessageGraph; } });
@@ -1,2 +1,3 @@
1
1
  export { END, Graph } from "./graph.js";
2
2
  export { type StateGraphArgs, START, StateGraph } from "./state.js";
3
+ export { MessageGraph } from "./message.js";
@@ -1,2 +1,3 @@
1
1
  export { END, Graph } from "./graph.js";
2
2
  export { START, StateGraph } from "./state.js";
3
+ export { MessageGraph } from "./message.js";
@@ -56,7 +56,7 @@ function createAgentExecutor({ agentRunnable, tools, inputSchema, }) {
56
56
  }
57
57
  const output = await toolExecutor.invoke(agentAction, config);
58
58
  return {
59
- steps: [[agentAction, output]],
59
+ steps: [{ action: agentAction, observation: output }],
60
60
  };
61
61
  };
62
62
  // Define a new graph
@@ -53,7 +53,7 @@ export function createAgentExecutor({ agentRunnable, tools, inputSchema, }) {
53
53
  }
54
54
  const output = await toolExecutor.invoke(agentAction, config);
55
55
  return {
56
- steps: [[agentAction, output]],
56
+ steps: [{ action: agentAction, observation: output }],
57
57
  };
58
58
  };
59
59
  // Define a new graph
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "LangGraph",
5
5
  "type": "module",
6
6
  "engines": {
@@ -37,12 +37,12 @@
37
37
  "author": "LangChain",
38
38
  "license": "MIT",
39
39
  "dependencies": {
40
- "@langchain/core": "^0.1.22"
40
+ "@langchain/core": "^0.1.27"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@jest/globals": "^29.5.0",
44
- "@langchain/community": "^0.0.17",
45
- "@langchain/openai": "^0.0.12",
44
+ "@langchain/community": "^0.0.27",
45
+ "@langchain/openai": "^0.0.14",
46
46
  "@langchain/scripts": "~0.0",
47
47
  "@swc/core": "^1.3.90",
48
48
  "@swc/jest": "^0.2.29",
@@ -59,7 +59,7 @@
59
59
  "eslint-plugin-prettier": "^4.2.1",
60
60
  "jest": "^29.5.0",
61
61
  "jest-environment-node": "^29.6.4",
62
- "langchain": "^0.1.3",
62
+ "langchain": "^0.1.17",
63
63
  "prettier": "^2.8.3",
64
64
  "release-it": "^15.10.1",
65
65
  "rollup": "^4.5.2",