Interface: Tool
@providerprotocol/ai / @providerprotocol/ai / Tool
Interface: Tool<TParams, TResult>
Section titled “Interface: Tool<TParams, TResult>”Defined in: src/types/tool.ts:115
Tool definition for LLM function calling.
Defines a tool that can be called by the LLM, including its name, description, parameter schema, and execution function.
Example
Section titled “Example”const weatherTool: Tool<{ location: string }, WeatherData> = { name: 'get_weather', description: 'Get current weather for a location', parameters: { type: 'object', properties: { location: { type: 'string', description: 'City name' } }, required: ['location'] }, run: async (params) => { return fetchWeather(params.location); }};Type Parameters
Section titled “Type Parameters”TParams
Section titled “TParams”TParams = unknown
The type of parameters the tool accepts
TResult
Section titled “TResult”TResult = unknown
The type of result the tool returns
Properties
Section titled “Properties”description
Section titled “description”description:
string
Defined in: src/types/tool.ts:120
Human-readable description for the model to understand when to use this tool
metadata?
Section titled “metadata?”
optionalmetadata:ToolMetadata
Defined in: src/types/tool.ts:142
Provider-specific metadata, namespaced by provider name.
Used for provider-specific features like prompt caching:
Example
Section titled “Example”const tool: Tool = { name: 'search_docs', description: 'Search documentation', parameters: {...}, run: async (params) => {...}, metadata: { anthropic: { cache_control: { type: 'ephemeral' } } }};name:
string
Defined in: src/types/tool.ts:117
Tool name (must be unique within an llm() instance)
parameters
Section titled “parameters”parameters:
JSONSchema
Defined in: src/types/tool.ts:123
JSON Schema defining the tool’s parameters
Methods
Section titled “Methods”approval()?
Section titled “approval()?”
optionalapproval(params):boolean|Promise<boolean>
Defined in: src/types/tool.ts:161
Optional approval handler for sensitive operations.
If provided, this function is called before the tool executes. Return false to prevent execution.
Parameters
Section titled “Parameters”params
Section titled “params”TParams
The parameters the tool would be called with
Returns
Section titled “Returns”boolean | Promise<boolean>
Whether to approve the execution
run(
params):TResult|Promise<TResult>
Defined in: src/types/tool.ts:150
Executes the tool with the provided parameters.
Parameters
Section titled “Parameters”params
Section titled “params”TParams
The parameters passed by the model
Returns
Section titled “Returns”TResult | Promise<TResult>
The tool result, synchronously or as a Promise