diff --git a/langgraph/src/graph/messages_state.ts b/langgraph/src/graph/messages_annotation.ts similarity index 85% rename from langgraph/src/graph/messages_state.ts rename to langgraph/src/graph/messages_annotation.ts index 5c91b7c8..9f299365 100644 --- a/langgraph/src/graph/messages_state.ts +++ b/langgraph/src/graph/messages_annotation.ts @@ -4,7 +4,7 @@ import { BaseMessage } from "@langchain/core/messages"; import { Annotation } from "./annotation.js"; import { messagesStateReducer } from "./message.js"; -export const MessagesState = Annotation.Root({ +export const MessagesAnnotation = Annotation.Root({ messages: Annotation({ reducer: messagesStateReducer, default: () => [], diff --git a/langgraph/src/index.ts b/langgraph/src/index.ts index f57f4e4f..5a2c0920 100644 --- a/langgraph/src/index.ts +++ b/langgraph/src/index.ts @@ -6,4 +6,4 @@ import { initializeAsyncLocalStorageSingleton } from "./setup/async_local_storag initializeAsyncLocalStorageSingleton(); export * from "./web.js"; -export { MessagesState } from "./graph/messages_state.js"; +export { MessagesAnnotation } from "./graph/messages_annotation.js"; diff --git a/langgraph/src/prebuilt/react_agent_executor.ts b/langgraph/src/prebuilt/react_agent_executor.ts index 27a8e952..c28e3ce3 100644 --- a/langgraph/src/prebuilt/react_agent_executor.ts +++ b/langgraph/src/prebuilt/react_agent_executor.ts @@ -21,7 +21,7 @@ import { import { ChatPromptTemplate } from "@langchain/core/prompts"; import { BaseCheckpointSaver } from "../checkpoint/base.js"; import { END, START, StateGraph } from "../graph/index.js"; -import { MessagesState } from "../graph/messages_state.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"; @@ -40,7 +40,7 @@ export type N = typeof START | "agent" | "tools"; export type CreateReactAgentParams = { llm: BaseChatModel; tools: - | ToolNode + | ToolNode | (StructuredToolInterface | RunnableToolLike)[]; messageModifier?: | SystemMessage diff --git a/langgraph/src/prebuilt/tool_node.ts b/langgraph/src/prebuilt/tool_node.ts index 5ff3fdbb..9cb6bf7e 100644 --- a/langgraph/src/prebuilt/tool_node.ts +++ b/langgraph/src/prebuilt/tool_node.ts @@ -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/messages_state.js"; +import { MessagesAnnotation } from "../graph/messages_annotation.js"; export type ToolNodeOptions = { name?: string; @@ -17,7 +17,7 @@ export type ToolNodeOptions = { }; export class ToolNode< - T extends BaseMessage[] | typeof MessagesState.State + T extends BaseMessage[] | typeof MessagesAnnotation.State > extends RunnableCallable { /** A node that runs the tools requested in the last AIMessage. It can be used @@ -41,9 +41,9 @@ export class ToolNode< } private async run( - input: BaseMessage[] | typeof MessagesState.State, + input: BaseMessage[] | typeof MessagesAnnotation.State, config: RunnableConfig - ): Promise { + ): Promise { const message = Array.isArray(input) ? input[input.length - 1] : input.messages[input.messages.length - 1]; @@ -92,7 +92,7 @@ export class ToolNode< } export function toolsCondition( - state: BaseMessage[] | typeof MessagesState.State + state: BaseMessage[] | typeof MessagesAnnotation.State ): "tools" | typeof END { const message = Array.isArray(state) ? state[state.length - 1]