Function: tool()
tool<
TSchema,TFn>(name,description,inputSchema,fn,options?):ZodToolDefinition<TSchema,Awaited<ReturnType<TFn>>>
Defined in: packages/core/src/utils/tools.ts:552
defineZodTool with positional arguments.
Type Parameters
TSchema
TSchema extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
TFn
TFn extends (params, options?) => unknown
Parameters
name
string
description
string
inputSchema
TSchema
fn
TFn
options?
object & ToolDurability<InferOutput<TSchema>, Awaited<ReturnType<TFn>>> & ToolPresentation<InferOutput<TSchema>>
Returns
ZodToolDefinition<TSchema, Awaited<ReturnType<TFn>>>
Examples
const add = tool(
'add',
'Adds two numbers',
z.object({
a: z.number().describe('First number'),
b: z.number().describe('Second number'),
}),
(params) => params.a + params.b
);
With options
const riskyTool = tool(
'delete',
'Delete something',
z.object({ id: z.string() }),
async ({ id }) => ({ deleted: true }),
{ requiresApproval: true, strict: true }
);