[GH-ISSUE #1668] [langchain]: Example provided in Typescript docs for "Core components" -> "Agents" has type errors #225

Open
opened 2026-02-17 17:19:26 -05:00 by yindo · 0 comments
Owner

Originally created by @Francesco-Lanciana on GitHub (Nov 30, 2025).
Original GitHub issue: https://github.com/langchain-ai/docs/issues/1668

Type of issue

issue / bug

Language

JavaScript

Description

Section: https://docs.langchain.com/oss/javascript/langchain/agents#memory

The example provided in this section, when copy pasted verbatim into a new file, gives the following type error on the stateSchema property:

No overload matches this call.
  The last overload gave the following error.
    Type 'ZodObject<{ messages: ReducedZodChannel<ZodType<BaseMessage<MessageStructure, MessageType>[], ZodTypeDef, BaseMessage<MessageStructure, MessageType>[]>, InteropZodType<...>>; userPreferences: ZodRecord<...>; }, $strip>' is not assignable to type 'AnyAnnotationRoot | InteropZodObject | undefined'.
      Type 'ZodObject<{ messages: ReducedZodChannel<ZodType<BaseMessage<MessageStructure, MessageType>[], ZodTypeDef, BaseMessage<MessageStructure, MessageType>[]>, InteropZodType<...>>; userPreferences: ZodRecord<...>; }, $strip>' is missing the following properties from type 'ZodObject<any, any, any, any, { [x: string]: any; }>': _cached, _getCached, _parse, nonstrict, and 13 more.ts(2769)
types.d.ts(274, 3): The expected type comes from property 'stateSchema' which is declared here on type 'CreateAgentParams<Record<string, any>, AnyAnnotationRoot | InteropZodObject | undefined, AnyAnnotationRoot, ResponseFormat> & { ...; }'
index.d.ts(183, 18): The last overload is declared here.

I've also been finding custom state in v1 very confusing. The migration guide [Link] says that stateSchema is now defined in middleware, but you can also define it directly on the agent. And it now seems zod is the default way to define it, but it still accepts an Annotation, e.g.

export const StateAnnotation = Annotation.Root({
    ...MessagesAnnotation.spec, // { messages: Annotation<Message[]> }
    pendingClarifications: Annotation<ClarificationItem[]>,
});

const agent = createAgent({
    ...
    stateSchema: StateAnnotation,
});

What is the difference between using zod and an Annotation?

For reference the example is:

import * as z from "zod";
import { MessagesZodState } from "@langchain/langgraph";
import { createAgent } from "langchain";
import { type BaseMessage } from "@langchain/core/messages";

const customAgentState = z.object({
  messages: MessagesZodState.shape.messages,
  userPreferences: z.record(z.string(), z.string()),
});

const CustomAgentState = createAgent({
  model: "gpt-4o",
  tools: [],
  stateSchema: customAgentState,
});
Originally created by @Francesco-Lanciana on GitHub (Nov 30, 2025). Original GitHub issue: https://github.com/langchain-ai/docs/issues/1668 ### Type of issue issue / bug ### Language JavaScript ### Description Section: https://docs.langchain.com/oss/javascript/langchain/agents#memory The example provided in this section, when copy pasted verbatim into a new file, gives the following type error on the `stateSchema` property: ``` No overload matches this call. The last overload gave the following error. Type 'ZodObject<{ messages: ReducedZodChannel<ZodType<BaseMessage<MessageStructure, MessageType>[], ZodTypeDef, BaseMessage<MessageStructure, MessageType>[]>, InteropZodType<...>>; userPreferences: ZodRecord<...>; }, $strip>' is not assignable to type 'AnyAnnotationRoot | InteropZodObject | undefined'. Type 'ZodObject<{ messages: ReducedZodChannel<ZodType<BaseMessage<MessageStructure, MessageType>[], ZodTypeDef, BaseMessage<MessageStructure, MessageType>[]>, InteropZodType<...>>; userPreferences: ZodRecord<...>; }, $strip>' is missing the following properties from type 'ZodObject<any, any, any, any, { [x: string]: any; }>': _cached, _getCached, _parse, nonstrict, and 13 more.ts(2769) types.d.ts(274, 3): The expected type comes from property 'stateSchema' which is declared here on type 'CreateAgentParams<Record<string, any>, AnyAnnotationRoot | InteropZodObject | undefined, AnyAnnotationRoot, ResponseFormat> & { ...; }' index.d.ts(183, 18): The last overload is declared here. ``` I've also been finding custom state in v1 very confusing. The migration guide [[Link](https://docs.langchain.com/oss/javascript/migrate/langchain-v1#custom-state)] says that stateSchema is now defined in middleware, but you can also define it directly on the agent. And it now seems zod is the default way to define it, but it still accepts an Annotation, e.g. ``` export const StateAnnotation = Annotation.Root({ ...MessagesAnnotation.spec, // { messages: Annotation<Message[]> } pendingClarifications: Annotation<ClarificationItem[]>, }); const agent = createAgent({ ... stateSchema: StateAnnotation, }); ``` What is the difference between using zod and an Annotation? For reference the example is: ``` import * as z from "zod"; import { MessagesZodState } from "@langchain/langgraph"; import { createAgent } from "langchain"; import { type BaseMessage } from "@langchain/core/messages"; const customAgentState = z.object({ messages: MessagesZodState.shape.messages, userPreferences: z.record(z.string(), z.string()), }); const CustomAgentState = createAgent({ model: "gpt-4o", tools: [], stateSchema: customAgentState, }); ```
yindo added the langchainexternal labels 2026-02-17 17:19:26 -05:00
yindo changed title from [langchain]: Example provided in Typescript docs for "Core components" -> "Agents" has type errors to [GH-ISSUE #1668] [langchain]: Example provided in Typescript docs for "Core components" -> "Agents" has type errors 2026-06-05 17:25:44 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/docs#225