The tool configuration object
A BaseTool instance ready for use with agents
import { createTool } from '@iqai/adk';
import { z } from 'zod';
// Tool with parameters
const calculatorTool = createTool({
name: 'calculator',
description: 'Performs basic arithmetic operations',
schema: z.object({
operation: z.enum(['add', 'subtract', 'multiply', 'divide']),
a: z.number().describe('First number'),
b: z.number().describe('Second number')
}),
fn: ({ operation, a, b }) => {
switch (operation) {
case 'add': return { result: a + b };
case 'subtract': return { result: a - b };
case 'multiply': return { result: a * b };
case 'divide': return { result: b !== 0 ? a / b : 'Cannot divide by zero' };
default: return { error: 'Unknown operation' };
}
}
});
// Tool without parameters (schema is optional)
const timestampTool = createTool({
name: 'timestamp',
description: 'Gets the current timestamp',
fn: () => ({ timestamp: Date.now() })
});
Creates a tool from a configuration object.
This is a more user-friendly alternative to FunctionTool that provides: