langchain.js
    Preparing search index...

    Type Alias InferAgentState<T>

    InferAgentState: InferSchemaInput<InferAgentType<T, "State">> & InferMiddlewareStates<
        InferAgentType<T, "Middleware">,
    >

    Helper type to infer the full merged state from an agent, including:

    • The agent's own state schema (if provided via stateSchema)
    • All middleware states

    This matches the state type returned by invoke and used throughout the agent.

    Type Parameters

    • T
    const middleware = createMiddleware({
    name: "counter",
    stateSchema: z.object({ count: z.number() }),
    });

    const agent = createAgent({
    model: "gpt-4",
    tools: [],
    stateSchema: z.object({ userId: z.string() }),
    middleware: [middleware],
    });

    type State = InferAgentState<typeof agent>;
    // { userId: string; count: number }