Hey team, I'd love an update on this issue: <https...
# agents
c
Hey team, I'd love an update on this issue: https://github.com/livekit/agents-js/issues/733. Zod v4 support.
r
@bitter-ghost-46918 do you know if there are any plans to update to Zod v4?
b
Yes, I will work on it this week
c
Thanks @bitter-ghost-46918, another thing, I noticed Livekit tool schema doesn't allow zod's
.optional()
do you know why? It only supports serializable json schemas.
b
.optional()
should work out of the box for function tools. Yyou can just append it to a field, e.g.
z.string().optional()
. Could you clarify what you’re trying to achieve?
c
this is what I mean @bitter-ghost-46918, this block throws a TS error:
Copy code
export const weatherTool = llm.tool({
  description: `...`,
  parameters: z.object({
    location: z
      .string()
      .optional()
      .describe('The city or location for weather and activity planning'),
  }),
This is the error:
Copy code
No overload matches this call.
  Overload 1 of 2, '({ description, parameters, execute, }: { description: string; parameters?: ToolInputSchema<JSONObject>; execute: ToolExecuteFunction<JSONObject, unknown, unknown>; }): FunctionTool<...>', gave the following error.
    Type 'ZodObject<{ location: ZodOptional<ZodString>; }, "strip", ZodTypeAny, { location?: string | undefined; }, { location?: string | undefined; }>' is not assignable to type 'ToolInputSchema<JSONObject>'.
      Type 'ZodObject<{ location: ZodOptional<ZodString>; }, "strip", ZodTypeAny, { location?: string | undefined; }, { location?: string | undefined; }>' is not assignable to type 'ZodObject<any, any, any, JSONObject, JSONObject>'.
        Type '{ location?: string | undefined; }' is not assignable to type 'JSONObject'.
          Property 'location' is incompatible with index signature.
            Type 'string | undefined' is not assignable to type 'JSONValue'.
              Type 'undefined' is not assignable to type 'JSONValue'.
  Overload 2 of 2, '({ id, config, }: { id: string; config: Record<string, unknown>; }): ProviderDefinedTool', gave the following error.
    Object literal may only specify known properties, and 'description' does not exist in type '{ id: string; config: Record<string, unknown>; }'.ts(2769)
tool_context.d.ts(106, 5): The expected type comes from property 'parameters' which is declared here on type '{ description: string; parameters?: ToolInputSchema<JSONObject>; execute: ToolExecuteFunction<JSONObject, unknown, unknown>; }'
This happens because the tools definition expects a Json Zod schema:
Copy code
export type JSONValue = null | string | number | boolean | JSONObject | JSONArray;

export type JSONArray = JSONValue[];

export type JSONObject = {
  [key: string]: JSONValue;
};

export function tool<
  Parameters extends JSONObject = Record<string, never>,
  UserData = UnknownUserData,
  Result = unknown,
>({
However, zod's
.optional
allows undefined, other AI frameworks like mastra.ai allows optional in zod schemas, because naturally some fields are not required for LLMs, and they need to know, but for some reason Livekit only allows json schemas and
undefined
is not a valid json value.
b
Ok I'll take a look, thanks for catching this!
🙌 1
We just release 1.0.15, which should support zod V4 now!
🎉 1
c
Thanks @bitter-ghost-46918 ! Faster than I thought!
🎉 2