defineTool
Function: defineTool()
defineTool<
TArgs,TResult>(options):Tool<TArgs,TResult>
Defined in: src/tools/tools.ts:1053
Ergonomic builder for Tool. Equivalent to constructing an object
literal with schema + execute, but flatter and safer — the name
- description live alongside the executor so they can't drift.
Type Parameters
TArgs
TArgs = Record<string, unknown>
TResult
TResult = unknown
Parameters
options
DefineToolOptions<TArgs, TResult>
Returns
Tool<TArgs, TResult>
Example
const weather = defineTool<{ city: string }, string>({
name: 'weather',
description: 'Get current weather for a city',
inputSchema: {
type: 'object',
properties: { city: { type: 'string' } },
required: ['city'],
},
execute: async ({ city }) => `${city}: 72°F sunny`,
});
const agent = Agent.create({ provider }).tool(weather).build();