Creates a new FunctionTool instance.
Configuration object for the tool
// Tool with input schema
const greetTool = new FunctionTool({
name: 'greeter',
description: 'Greets a person by name',
inputSchema: {
type: 'object',
properties: { name: { type: 'string' } },
required: ['name']
},
callback: (input: any) => `Hello, ${input.name}!`
})
// Tool without input (no parameters)
const statusTool = new FunctionTool({
name: 'getStatus',
description: 'Gets system status',
callback: () => ({ status: 'operational' })
})
ReadonlynameThe unique name of the tool.
ReadonlydescriptionHuman-readable description of what the tool does.
ReadonlytoolOpenAPI JSON specification for the tool.
Executes the tool with streaming support. Handles all callback patterns (async generator, promise, sync) and converts results to ToolResultBlock.
Context information including the tool use request and invocation state
Async generator that yields ToolStreamEvents and returns a ToolResultBlock
A Tool implementation that wraps a callback function and handles all ToolResultBlock conversion.
FunctionTool allows creating tools from existing functions without needing to manually handle ToolResultBlock formatting or error handling. It supports multiple callback patterns:
All return values are automatically wrapped in ToolResultBlock, and errors are caught and returned as error ToolResultBlocks.
Example