langchain.js
    Preparing search index...

    Variable MessagesAnnotationConst

    MessagesAnnotation: AnnotationRoot<
        {
            messages: BinaryOperatorAggregate<
                BaseMessage<MessageStructure, MessageType>[],
                Messages,
            >;
        },
    > = ...

    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:

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

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

    Is equivalent to initializing your state manually like this:

    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(...)
    ...