Skip to main content
Version: Next

CreateTool

createTool

Creates a new AI tool with the specified configuration. This function wraps the underlying AI library's tool creation with additional context management and parameter validation.

Example

const myTool = createTool({
name: 'calculate',
description: 'Performs basic arithmetic calculations',
parameters: z.object({
operation: z.enum(['add', 'subtract']),
a: z.number(),
b: z.number(),
}),
execute: async (ctx, params) => {
return params.operation === 'add'
? params.a + params.b
: params.a - params.b;
},
});
Signature
function createTool<T extends ToolParameterType, R = unknown>(options: CreateToolOptions<T, R>): void

Parameters

options

parameter