I configured a tool with zod version 4 schema and wrote an execute function as follows
{
runAgentTask: tool({
description: "Runs an agent with a task.",
parameters: z.object({
task: z.string().describe("Complete task description.")
}),
execute: async (input) => {
console.log("task:", JSON.stringify(input));
// Pass the actual dynamic task from input into your main function
let agentOutput = await mainFn(input.task);
return { result: String(agentOutput ?? "") };
},
}),
};
and passed to the model as follows.
modelResult = streamText({
model: google("gemma-4-31b-it"),
messages: allMessages,
toolChoice: "auto",
tools: tools,
});
when tool executes.
actual output: task: {“description”:“…”}
expecting task: {“task”:“…”}
I asked zod community on github , they said good from zod version 4.