langchain.js
    Preparing search index...

    Type Alias InferAgentContext<T>

    InferAgentContext: InferSchemaInput<InferAgentType<T, "Context">> & InferMiddlewareContexts<
        InferAgentType<T, "Middleware">,
    >

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

    • The agent's own context schema (if provided via contextSchema)
    • All middleware context schemas

    This matches the context type available throughout the agent runtime.

    Type Parameters

    • T
    const middleware = createMiddleware({
    name: "auth",
    contextSchema: z.object({ userId: z.string() }),
    });

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

    type Context = InferAgentContext<typeof agent>;
    // { sessionId: string; userId: string }