Skip to main content

Function: defineZodTool()

defineZodTool<TSchema, TFn>(definition): ZodToolDefinition<TSchema, Awaited<ReturnType<TFn>>>

Defined in: packages/core/src/utils/tools.ts:506

Define a tool from a Zod schema; execute's parameters and the result type are inferred.

Type Parameters​

TSchema​

TSchema extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> = ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

TFn​

TFn extends (params, options?) => unknown = (params, options?) => unknown

Parameters​

definition​

object & ToolDurability<InferOutput<TSchema>, Awaited<ReturnType<TFn>>> & ToolPresentation<InferOutput<TSchema>>

Returns​

ZodToolDefinition<TSchema, Awaited<ReturnType<TFn>>>

Example​

const weatherTool = defineZodTool({
name: 'get_weather',
description: 'Get weather for a location',
inputSchema: z.object({
location: z.string().describe('City name'),
units: z.enum(['celsius', 'fahrenheit']).optional()
}),
execute: async (params) => {
// params is { location: string, units?: 'celsius' | 'fahrenheit' }
return { temp: 22, condition: 'sunny' };
}
});