Variable MessagesZodStateConst

MessagesZodState: z.ZodObject<{
    messages: z.ZodType<BaseMessage[], z.ZodTypeDef, Messages>;
}, "strip", z.ZodTypeAny, {
    messages: BaseMessage[];
}, {
    messages: Messages;
}>

Prebuilt state object that uses Zod to combine returned messages. This utility is synonymous with the MessagesAnnotation annotation, but uses Zod as the way to express messages state.

You can use import and use this prebuilt schema like this:

Type declaration

  • messages: z.ZodType<BaseMessage[], z.ZodTypeDef, Messages>

Type declaration

  • messages: BaseMessage[]

Type declaration

Example

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

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

Which is equivalent to initializing the schema object manually like this:

Example

import { z } from "zod";
import type { BaseMessage, BaseMessageLike } from "@langchain/core/messages";
import { StateGraph, messagesStateReducer } from "@langchain/langgraph";
import "@langchain/langgraph/zod";

const AgentState = z.object({
messages: z
.custom<BaseMessage[]>()
.default(() => [])
.langgraph.reducer(
messagesStateReducer,
z.custom<BaseMessageLike | BaseMessageLike[]>()
),
});
const graph = new StateGraph(AgentState)
.addNode(...)
...