Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Aug 22, 2024
2 parents 9e53262 + 8c8d0a9 commit 81ebfe8
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 14 deletions.
2 changes: 1 addition & 1 deletion libs/langgraph/langchain.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const config = {
web: "web",
pregel: "pregel/index",
prebuilt: "prebuilt/index",
"checkpoint/sqlite": "checkpoint/sqlite",
"checkpoint/sqlite": "checkpoint/sqlite"
},
tsConfigPath: resolve("./tsconfig.json"),
cjsSource: "./dist-cjs",
Expand Down
2 changes: 1 addition & 1 deletion libs/langgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@langchain/anthropic": "^0.2.12",
"@langchain/community": "^0.2.25",
"@langchain/openai": "^0.2.4",
"@langchain/scripts": "^0.0.22",
"@langchain/scripts": "^0.0.23",
"@swc/core": "^1.3.90",
"@swc/jest": "^0.2.29",
"@tsconfig/recommended": "^1.0.3",
Expand Down
4 changes: 0 additions & 4 deletions libs/langgraph/src/graph/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,3 @@ export class MessageGraph extends StateGraph<
});
}
}

export interface MessagesState {
messages: BaseMessage[];
}
12 changes: 12 additions & 0 deletions libs/langgraph/src/graph/messages_annotation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */

import { BaseMessage } from "@langchain/core/messages";
import { Annotation } from "./annotation.js";
import { messagesStateReducer } from "./message.js";

export const MessagesAnnotation = Annotation.Root({
messages: Annotation<BaseMessage[]>({
reducer: messagesStateReducer,
default: () => [],
}),
});
1 change: 1 addition & 0 deletions libs/langgraph/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ import { initializeAsyncLocalStorageSingleton } from "./setup/async_local_storag
initializeAsyncLocalStorageSingleton();

export * from "./web.js";
export { MessagesAnnotation } from "./graph/messages_annotation.js";
4 changes: 2 additions & 2 deletions libs/langgraph/src/prebuilt/react_agent_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { BaseCheckpointSaver } from "@langchain/langgraph-checkpoint";
import { END, START, StateGraph } from "../graph/index.js";
import { MessagesState } from "../graph/message.js";
import { MessagesAnnotation } from "../graph/messages_annotation.js";
import { CompiledStateGraph, StateGraphArgs } from "../graph/state.js";
import { All } from "../pregel/types.js";
import { ToolNode } from "./tool_node.js";
Expand All @@ -40,7 +40,7 @@ export type N = typeof START | "agent" | "tools";
export type CreateReactAgentParams = {
llm: BaseChatModel;
tools:
| ToolNode<MessagesState>
| ToolNode<typeof MessagesAnnotation.State>
| (StructuredToolInterface | RunnableToolLike)[];
messageModifier?:
| SystemMessage
Expand Down
10 changes: 5 additions & 5 deletions libs/langgraph/src/prebuilt/tool_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { RunnableConfig, RunnableToolLike } from "@langchain/core/runnables";
import { StructuredToolInterface } from "@langchain/core/tools";
import { RunnableCallable } from "../utils.js";
import { END } from "../graph/graph.js";
import { MessagesState } from "../graph/message.js";
import { MessagesAnnotation } from "../graph/messages_annotation.js";

export type ToolNodeOptions = {
name?: string;
Expand All @@ -17,7 +17,7 @@ export type ToolNodeOptions = {
};

export class ToolNode<
T extends BaseMessage[] | MessagesState
T extends BaseMessage[] | typeof MessagesAnnotation.State
> extends RunnableCallable<T, T> {
/**
A node that runs the tools requested in the last AIMessage. It can be used
Expand All @@ -41,9 +41,9 @@ export class ToolNode<
}

private async run(
input: BaseMessage[] | MessagesState,
input: BaseMessage[] | typeof MessagesAnnotation.State,
config: RunnableConfig
): Promise<BaseMessage[] | MessagesState> {
): Promise<BaseMessage[] | typeof MessagesAnnotation.State> {
const message = Array.isArray(input)
? input[input.length - 1]
: input.messages[input.messages.length - 1];
Expand Down Expand Up @@ -92,7 +92,7 @@ export class ToolNode<
}

export function toolsCondition(
state: BaseMessage[] | MessagesState
state: BaseMessage[] | typeof MessagesAnnotation.State
): "tools" | typeof END {
const message = Array.isArray(state)
? state[state.length - 1]
Expand Down
24 changes: 23 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1959,7 +1959,7 @@ __metadata:
"@langchain/langgraph-checkpoint": 0.0.0
"@langchain/langgraph-checkpoint-sqlite": 0.0.0
"@langchain/openai": ^0.2.4
"@langchain/scripts": ^0.0.22
"@langchain/scripts": ^0.0.23
"@swc/core": ^1.3.90
"@swc/jest": ^0.2.29
"@tsconfig/recommended": ^1.0.3
Expand Down Expand Up @@ -2060,6 +2060,28 @@ __metadata:
languageName: node
linkType: hard

"@langchain/scripts@npm:^0.0.23":
version: 0.0.23
resolution: "@langchain/scripts@npm:0.0.23"
dependencies:
"@rollup/wasm-node": ^4.19.0
axios: ^1.6.7
commander: ^11.1.0
glob: ^10.3.10
lodash: ^4.17.21
readline: ^1.3.0
rimraf: ^5.0.1
rollup: ^4.5.2
ts-morph: ^21.0.1
typescript: ^5.4.5
bin:
lc-build: bin/build.js
lc_build_v2: bin/build_v2.js
notebook_validate: bin/validate_notebook.js
checksum: 975ac6fea3832353bc15b48ae5e66087dcda9e3f8be02c3f2f5c93b2545cacb803b4d160a04b33ab14da75808909de6077d775fb51d2960d9a769fc968342e54
languageName: node
linkType: hard

"@langchain/textsplitters@npm:~0.0.0":
version: 0.0.2
resolution: "@langchain/textsplitters@npm:0.0.2"
Expand Down

0 comments on commit 81ebfe8

Please sign in to comment.