diff --git a/langgraph/src/graph/index.ts b/langgraph/src/graph/index.ts index 05cea1b5..c0f69bea 100644 --- a/langgraph/src/graph/index.ts +++ b/langgraph/src/graph/index.ts @@ -8,5 +8,6 @@ export { export { MessageGraph, messagesStateReducer, - MessagesState, + type MessagesState, + createMessagesState, } from "./message.js"; diff --git a/langgraph/src/graph/message.ts b/langgraph/src/graph/message.ts index 10e9438f..b8f64043 100644 --- a/langgraph/src/graph/message.ts +++ b/langgraph/src/graph/message.ts @@ -77,9 +77,11 @@ export class MessageGraph extends StateGraph< } } -export const MessagesState = Annotation.Root({ +export const createMessagesState = () => Annotation.Root({ messages: Annotation({ reducer: messagesStateReducer, default: () => [], }), }); + +export type MessagesState = ReturnType['State']; diff --git a/langgraph/src/prebuilt/react_agent_executor.ts b/langgraph/src/prebuilt/react_agent_executor.ts index 62bcea7b..4860bac0 100644 --- a/langgraph/src/prebuilt/react_agent_executor.ts +++ b/langgraph/src/prebuilt/react_agent_executor.ts @@ -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 6378eac3..fdd71090 100644 --- a/langgraph/src/prebuilt/tool_node.ts +++ b/langgraph/src/prebuilt/tool_node.ts @@ -17,7 +17,7 @@ export type ToolNodeOptions = { }; export class ToolNode< - T extends BaseMessage[] | typeof MessagesState.State + T extends BaseMessage[] | MessagesState > 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[] | MessagesState, 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[] | MessagesState ): "tools" | typeof END { const message = Array.isArray(state) ? state[state.length - 1] diff --git a/langgraph/src/web.ts b/langgraph/src/web.ts index af1529e2..3965df73 100644 --- a/langgraph/src/web.ts +++ b/langgraph/src/web.ts @@ -8,7 +8,8 @@ export { MessageGraph, messagesStateReducer, Annotation, - MessagesState, + createMessagesState, + type MessagesState, type StateType, type UpdateType, type CompiledGraph,