MartinBM
Convex Communityโ€ข8mo agoโ€ข
1 reply
MartinB

Invalid schema for tool in convex agent.

I migrated away from ai sdk to using the agent from convex however as soon as I add any tools it throws an error.

I've checked and can't seem to find an issue with my code. Please help.

error:

responseBody: '{\n  "error": {\n    "message": "Invalid schema for function \'getUserPreferences\': schema must be a JSON Schema of \'type: \\"object\\"\', got \'type: \\"string\\"\'.",\n    "type": "invalid_request_error",\n    "param": "tools[0].function.parameters",\n    "code": "invalid_function_parameters"\n  }\n}', isRetryable: false, data: {
    error: {
      message: 'Invalid schema for function \'getUserPreferences\': schema must be a JSON Schema of \'type: "object"\', got \'type: "string"\'.',
      type: 'invalid_request_error',
      param: 'tools[0].function.parameters',
      code: 'invalid_function_parameters'
    }


 "dependencies": {
        "@ai-sdk/openai": "^1.3.23",
        "@convex-dev/agent": "^0.1.15",
        "ai": "^4.3.19",
        "convex": "^1.25.4",
        "convex-helpers": "^0.1.96",
        "date-fns": "^4.1.0",
        "openai": "^5.9.0"
},


import { openai } from "@ai-sdk/openai";
import { Agent } from "@convex-dev/agent";
import { components } from "../convex/_generated/api";
import { z } from "zod";
import { tool } from "ai";

export const assistantAgent = new Agent(components.agent, {
    chat: openai("gpt-4.1-nano-2025-04-14"),
    instructions: `You are a helpful assistant`,
    tools: {
        getUserPreferences: tool({
            description: "Get clothing preferences for a user",
            parameters: z.object({
                search: z.string().describe("Which preferences are requested"),
            }),
            execute: async (args) => {
                console.log("getting user preferences", args);
                return {
                    information: `The user likes to look stylish`,
                };
            },
        }),
    },
});
Was this page helpful?