@tool decorator to convert any Python function into an agent-callable tool.
- Uses the function name as the tool name.
- Parses the docstring as the tool description.
- Generates a JSON Schema from type hints.
- Makes the tool available to any agent.
Decorator Options
| Option | Type | Default | Description |
|---|---|---|---|
name | str | Function name | Tool name shown to the model |
description | str | From docstring | Tool description |
strict | bool | False | Strict parameter validation |
instructions | str | None | Usage instructions added to system prompt |
show_result | bool | False | Show result in streaming output |
stop_after_tool_call | bool | False | Stop agent loop after this tool |
requires_confirmation | bool | False | Require user confirmation before executing |
pre_hook | Callable | None | Run before tool execution |
post_hook | Callable | None | Run after tool execution |
cache_results | bool | False | Cache results for identical arguments |
cache_ttl | int | 3600 | Cache TTL in seconds |
Learn More
Parameters
Type hints, descriptions, and JSON Schema.
Hooks
Run logic before and after execution.
Caching
Cache results for identical arguments.
Async Tools
Non-blocking I/O operations.
Dependencies
Inject services and state into tools.