Skip to content

Commit 0424f3c

Browse files
committed
Update package dependencies and refactor GraphRunner
The package dependencies "@langchain/community", "@langchain/core", and "@langchain/openai" have been updated to newer versions. In the GraphRunner code, 'agentState' was refactored into 'schema', and some rewording was applied to comments for clarity. These changes aim to keep the package dependencies up-to-date and improve the readability and management of the code.
1 parent dd71339 commit 0424f3c

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

package-lock.json

+15-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
"update scripts": "npx npm-check-updates -u"
1919
},
2020
"dependencies": {
21-
"@langchain/community": "^0.0.46",
22-
"@langchain/core": "^0.1.55",
21+
"@langchain/community": "^0.0.47",
22+
"@langchain/core": "^0.1.57",
2323
"@langchain/langgraph": "0.0.12",
24-
"@langchain/openai": "^0.0.26",
24+
"@langchain/openai": "^0.0.28",
2525
"yaml": "^2.4.1",
2626
"yargs": "^17.7.2"
2727
},

src/agents/GraphRunner.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { AIMessage, BaseMessage, HumanMessage } from "@langchain/core/messages";
66
import { PromptTemplate } from "@langchain/core/prompts";
77
import { Runnable, RunnableConfig, RunnableLambda } from "@langchain/core/runnables";
88
import { END, StateGraph } from "@langchain/langgraph";
9+
import { BinaryOperator } from "@langchain/langgraph/dist/channels/binop";
910
import { createFunctionCallingExecutor } from "@langchain/langgraph/prebuilt";
1011
import { Pregel } from "@langchain/langgraph/pregel";
1112

@@ -171,21 +172,21 @@ export class GraphRunner extends Runnable<GraphRunnerInput, GraphRunnerOutput> {
171172
}
172173
});
173174

174-
const agentState = {
175+
const schema: {
176+
messages: {
177+
value: BinaryOperator<unknown> | null;
178+
default?: () => unknown;
179+
}
180+
} = {
175181
messages: {
176182
value: (x: BaseMessage[], y: BaseMessage[]) => x.concat(y),
177183
default: () => [],
178184
},
179-
viewstate: {
180-
value: (x: Record<any, any>, y: Record<any, any>) => ({...x, ...y}),
181-
default: () => {
182-
},
183-
},
184185
};
185186

186187
// Define a new graph
187188
const workflow = new StateGraph({
188-
channels: agentState,
189+
channels: schema,
189190
});
190191

191192
// Define the nodes
@@ -209,12 +210,12 @@ export class GraphRunner extends Runnable<GraphRunnerInput, GraphRunnerOutput> {
209210

210211
// Define the edges between the nodes
211212
nodes.forEach((node, index) => {
212-
// If this is the first agent, set it as the entry point
213+
// If this is the first agent, set it as the entry point.
213214
if (index === 0) {
214215
workflow.setEntryPoint(node.name!);
215216
}
216217

217-
// If this is the last node, set it as the finish point
218+
// If this is the last node, set it as the finish point.
218219
if (index === nodes.length - 1) {
219220
workflow.setFinishPoint(node.name!);
220221
}
@@ -247,7 +248,7 @@ export class GraphRunner extends Runnable<GraphRunnerInput, GraphRunnerOutput> {
247248

248249
} else {
249250

250-
// If not the last node, add the edge to the next node
251+
// If not the last node, add the edge to the next node.
251252
if (index < nodes.length - 1) {
252253
if (node.isExit) {
253254
workflow.addEdge(node.name!, END);

0 commit comments

Comments
 (0)