defineZodTool
Auto-generated API reference for defineZodTool.
Function: defineZodTool()
defineZodTool<
TSchema>(config):ToolDefinition<InferZodOutput<TSchema>>
Defined in: zod.ts:67
Create a ToolDefinition whose execute args are typed from a Zod schema.
Zod is NOT bundled — pass it as a peer dependency. The toJsonSchema
callback lets you convert the Zod schema to JSON Schema for the adapter
(e.g. using zod-to-json-schema).
#Type Parameters
#TSchema
TSchema extends ZodLike<unknown>
#Parameters
#config
DefineZodToolConfig<TSchema>
#Returns
ToolDefinition<InferZodOutput<TSchema>>
#Example
import { z } from 'zod'
import { zodToJsonSchema } from 'zod-to-json-schema'
import { defineZodTool } from '@agentskit/tools'
const weatherTool = defineZodTool({
name: 'weather',
description: 'Get weather for a city',
schema: z.object({ city: z.string(), units: z.enum(['C', 'F']).optional() }),
toJsonSchema: (s) => zodToJsonSchema(s) as JSONSchema7,
execute: (args) => {
// args.city is string, args.units is 'C' | 'F' | undefined
return `Weather in ${args.city}: 22${args.units ?? 'C'}`
},
})