Skip to content

Agent outputType type error with [email protected]+ #187

@teetlaja

Description

@teetlaja

Describe the bug

When providing a properly-typed Zod schema as the property to an instance, TypeScript raises an error, even though the types appear compatible.
This prevents using custom Zod object schemas as the agent's output shape. outputType``Agent

Debug information

  • Agents SDK version: v0.0.10
  • Runtime environment: Node.js 22.16.0
  • Package manager: yarn
  • TypeScript version: 5.8.3
  • Zod version: 3.25.40
  • IDE: WebStorm

Repro steps

  1. Install dependencies:
    yarn add @openai/agents zod
  1. Create a file my-test.ts with the following minimal code:
    import { Agent } from '@openai/agents';
    import { z } from 'zod';

    const SimpleOutput = z.object({
      hotelName: z.string(),
      hotelWeb: z.string(),
    });

    // This line causes a TypeScript error:
    const agent = new Agent({
      name: 'test agent',
      instructions: 'Test instructions',
      outputType: SimpleOutput, // Error is reported here!
    });
  1. Observe the TypeScript error:
    TS2322: Type 'ZodObject<{ hotelName: ZodString; hotelWeb: ZodString; }, ...>' is not assignable to type 'AgentOutputType<unknown> | undefined'.
    ...
    Types have separate declarations of a private property '_cached'.

Expected behavior

The above use of a custom Zod schema should be accepted as a valid for the constructor.
It should be possible to specify any compatible Zod object to shape the output type, without TypeScript errors. outputType``Agent

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions