Defining a Tool
Use the@tool decorator on any function:
- Extracts the function name as the tool name
- Parses the docstring as the tool description
- Generates a JSON Schema from the type hints
- Makes the tool available to any agent
Using Tools with Agents
Pass tools when creating an agent:Decorator Options
The@tool decorator accepts several options to customize behavior:
All Options
| Option | Type | Default | Description |
|---|---|---|---|
name | str | Function name | Tool name shown to the model |
description | str | From docstring | Tool description shown to the model |
strict | bool | False | Enable strict parameter validation |
instructions | str | None | Usage instructions added to system prompt |
add_instructions | bool | True | Whether to add instructions to system prompt |
show_result | bool | False | Show tool result in agent streaming output |
stop_after_tool_call | bool | False | Stop the agent loop after calling this tool |
requires_confirmation | bool | False | Pause and require user confirmation before executing |
requires_user_input | bool | False | Pause and request user input before executing |
pre_hook | Callable | None | Function to run before tool execution |
post_hook | Callable | None | Function to run after tool execution |
tool_hooks | List[Callable] | None | List of hook functions |
cache_results | bool | False | Cache results for identical arguments |
cache_ttl | int | 3600 | Cache time-to-live in seconds |
How Tool Calling Works
When you give tools to an agent, the following happens during execution:- The model receives the tool definitions as JSON Schema
- If the model decides to call a tool, it returns a
tool_callsresponse with the function name and arguments - Definable executes the function with the provided arguments
- The result is sent back to the model as a tool message
- The model incorporates the result and continues