Variable MessagesAnnotationConst

MessagesAnnotation: AnnotationRoot

Prebuilt state annotation that combines returned messages. Can handle standard messages and special modifiers like RemoveMessage instances.

Specifically, importing and using the prebuilt MessagesAnnotation like this:

Example

import { MessagesAnnotation, StateGraph } from "@langchain/langgraph";

const graph = new StateGraph(MessagesAnnotation)
.addNode(...)
...

Is equivalent to initializing your state manually like this:

Example

import { BaseMessage } from "@langchain/core/messages";
import { Annotation, StateGraph, messagesStateReducer } from "@langchain/langgraph";

export const StateAnnotation = Annotation.Root({
messages: Annotation<BaseMessage[]>({
reducer: messagesStateReducer,
default: () => [],
}),
});

const graph = new StateGraph(StateAnnotation)
.addNode(...)
...