Bug Description
When using @convex-dev/agent@0.3.2 with zod@3.25.76, any agent with tools fails to run with:
TypeError: Cannot read properties of undefined (reading '_zod')
Environment
@convex-dev/agent: 0.3.2
zod: 3.25.76
ai: 5.0.110
@ai-sdk/provider-utils: 3.0.18
convex: 1.29.3
Reproduction
- Create an agent with any tool using
createTool:
import { Agent, createTool } from "@convex-dev/agent";
import { z } from "zod";
const myTool = createTool({
description: "Test tool",
args: z.object({
input: z.string(),
}),
handler: async (ctx, args) => {
return "result";
},
});
export const myAgent = new Agent(components.agent, {
name: "Test Agent",
tools: { myTool },
// ...
});
- Try to run the agent
- Error occurs during tool schema validation
Root Cause
The @ai-sdk/provider-utils package checks for Zod 4 schemas using:
function isZod4Schema(zodSchema) {
return "_zod" in zodSchema;
}
However, the zodSchema parameter is undefined when it reaches this check, causing the error.
Expected Behavior
Agents with tools should work with Zod 3.25.76, which is listed as a supported peer dependency in @ai-sdk/provider-utils.
Workaround Attempted
- Tried
zod@3.22.4 - bundling fails (missing zod/v4 export)
- Tried
zod@3.23.8 - same _zod error
- Tried
@convex-dev/agent@0.5.0-alpha.1 - same error
- Tried
zod/v3 import - Convex bundler doesn't resolve it correctly
Bug Description
When using
@convex-dev/agent@0.3.2withzod@3.25.76, any agent with tools fails to run with:Environment
@convex-dev/agent: 0.3.2zod: 3.25.76ai: 5.0.110@ai-sdk/provider-utils: 3.0.18convex: 1.29.3Reproduction
createTool:Root Cause
The
@ai-sdk/provider-utilspackage checks for Zod 4 schemas using:However, the
zodSchemaparameter isundefinedwhen it reaches this check, causing the error.Expected Behavior
Agents with tools should work with Zod 3.25.76, which is listed as a supported peer dependency in
@ai-sdk/provider-utils.Workaround Attempted
zod@3.22.4- bundling fails (missingzod/v4export)zod@3.23.8- same_zoderror@convex-dev/agent@0.5.0-alpha.1- same errorzod/v3import - Convex bundler doesn't resolve it correctly