Repository navigation
Description
Hi, first of all, I want to say thank you so much for maintaining this amazing project.
Overview
I am one of OpenAI's Agents SDK maintainers, and we recently started receiving TS transpilation error reports with zod 3.25.68 and all newer versions from our users. Here’s a summary of the issue:
- Zod 3.25.67 and older versions are compatible with our SDK.
- Starting from zod 3.25.68, tsc fails for all zod-related code on the SDK user side.
- Our SDK code itself still compiles with any version of zod 3.x.
I will share the reproduction steps at the end of this report.
We need your help 🙇
Aside from quickly reporting this issue to the zod project, we would appreciate any advice you could offer to help us mitigate the issue for our users until it is resolved. Currently, we are recommending our users use zod@3.25.67 or older for their projects with our Agents SDK. If there’s anything we can do on our end, we’re happy to try it. Any information would be appreciated.
Repro steps
Here are the simplest repro steps:
Run the following commands to create package.json and install the dependencies:
npm init -y
npm i @openai/agents@0.0.10 typescript zod@3.25.67Create tsconfig.json
{
"compilerOptions": {
"outDir": "./dist",
"target": "es2022",
"noImplicitAny": true,
"module": "commonjs",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"strict": true,
"esModuleInterop": true,
"allowJs": false
},
"include": ["src/**/*"]
}Create src/index.ts:
import { Agent, tool } from '@openai/agents';
import { z } from 'zod';
const getWeather = tool({
name: 'get_weather',
description: 'Get the weather for a given city',
parameters: z.object({ city: z.string() }),
async execute({ city }) {
return `The weather in ${city} is sunny.`;
},
});
const agent = new Agent({
name: 'Haiku Agent',
instructions: 'Always respond in haiku form.',
outputType: z.object({ haiku: z.string() }),
tools: [getWeather],
});Let's start with a successful pattern. Run the TS compiler this way. This succeeds without any issues. Older versions than 3.25.67 get the same result.
npx tscContrarily, here is the failure pattern. Install zod@3.25.68 or newer:
npm i zod@3.25.68Run the TS compiler again:
npx tscYou'll see the following errors:
src/index.ts:7:3 - error TS2322: Type 'ZodObject<{ city: ZodString; }, "strip", ZodTypeAny, { city: string; }, { city: string; }>' is not assignable to type 'JsonObjectSchemaStrict<any> | JsonObjectSchemaNonStrict<any> | ZodObject<any, UnknownKeysParam, ZodTypeAny, { ...; }, { ...; }> | undefined'.
Type 'ZodObject<{ city: ZodString; }, "strip", ZodTypeAny, { city: string; }, { city: string; }>' is not assignable to type 'ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }>'.
Types have separate declarations of a private property '_cached'.
7 parameters: z.object({ city: z.string() }),
~~~~~~~~~~
node_modules/@openai/agents-core/dist/tool.d.ts:266:5
266 parameters: TParameters;
~~~~~~~~~~
The expected type comes from property 'parameters' which is declared here on type 'ToolOptions<ToolInputParameters, unknown>'
src/index.ts:7:15 - error TS2589: Type instantiation is excessively deep and possibly infinite.
7 parameters: z.object({ city: z.string() }),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/index.ts:8:9 - error TS2322: Type '({ city }: { city: any; }) => Promise<string>' is not assignable to type 'ToolExecuteFunction<JsonObjectSchemaStrict<any> | ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }> | undefined, unknown> | ToolExecuteFunction<...>'.
Type '({ city }: { city: any; }) => Promise<string>' is not assignable to type 'ToolExecuteFunction<JsonObjectSchemaStrict<any> | ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }> | undefined, unknown>'.
Types of parameters '__0' and 'input' are incompatible.
Type 'unknown' is not assignable to type '{ city: any; }'.
8 async execute({ city }) {
~~~~~~~
node_modules/@openai/agents-core/dist/tool.d.ts:274:5
274 execute: ToolExecuteFunction<TParameters, Context>;
~~~~~~~
The expected type comes from property 'execute' which is declared here on type 'ToolOptions<ToolInputParameters, unknown>'
src/index.ts:16:3 - error TS2322: Type 'ZodObject<{ haiku: ZodString; }, "strip", ZodTypeAny, { haiku: string; }, { haiku: string; }>' is not assignable to type 'AgentOutputType<unknown> | undefined'.
Type 'ZodObject<{ haiku: ZodString; }, "strip", ZodTypeAny, { haiku: string; }, { haiku: string; }>' is not assignable to type 'ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }> | JsonSchemaDefinition'.
Type 'ZodObject<{ haiku: ZodString; }, "strip", ZodTypeAny, { haiku: string; }, { haiku: string; }>' is not assignable to type 'ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }>'.
Types have separate declarations of a private property '_cached'.
16 outputType: z.object({ haiku: z.string() }),
~~~~~~~~~~
node_modules/@openai/agents-core/dist/agent.d.ts:145:5
145 outputType: TOutput;
~~~~~~~~~~
The expected type comes from property 'outputType' which is declared here on type '{ name: string; instructions?: string | ((runContext: RunContext<unknown>, agent: Agent<unknown, AgentOutputType<unknown>>) => string | Promise<string>) | undefined; ... 12 more ...; resetToolChoice?: boolean | undefined; }'
Found 4 errors in the same file, starting at: src/index.ts:7
Activity
Drop private modifier. Fixes #4903
Drop private modifier. Fixes #4903
Drop private modifier. Fixes #4903
seratch commentedon Jul 23, 2025
@colinhacks Thank you so much for looking into this issue and resolving it in 4.0.6.
I've confirmed the "_cached" property issue disappeared, but now the same code gets the following tsc error "error TS2589: Type instantiation is excessively deep and possibly infinite" with 4.0.6, 4.0.7, and 4.0.8 + "zod/v3".
Should I create a new issue for it? Also, if there is anything possibly I can do on our side to prevent this from happening for our users, I'd love to try anything for it 🙇
We don't support v4 at this moment, but just for your information, here is the error with "zod" / "zod/v4" in 4.0.6, 4.0.7, and 4.0.8:
v4.0.6 (colinhacks#4941)
seratch commentedon Jul 25, 2025
For visibility, I created a new issue for my previous comment: #4984 If there is anything I can do for resolving this on my end, please let me know.