Tools
Writing your own tools
In most production cases, you will need to write your own tools. Which is why we’re focused on provide the best tool-use experience in Agno.
The rule is simple:
- Any python function can be used as a tool by an Agent.
- Use the
@tool
decorator to modify what happens before and after this tool is called.
Any python function can be used as a tool
For example, here’s how to use a get_top_hackernews_stories
function as a tool:
hn_agent.py
Magic of the @tool decorator
To modify what happens before and after a tool is called, use the @tool
decorator. Some notable features:
show_result=True
: Show the output of the tool call in the Agent’s response. Without this flag, the result of the tool call is sent to the model for further processing.stop_after_tool_call=True
: Stop the agent after the tool call.tool_hooks
: Run custom logic before and after this tool call.cache_results=True
: Cache the tool result to avoid repeating the same call.
Here’s an example that uses all possible parameters on the @tool
decorator.
advanced_tool.py
@tool Parameters Reference
Parameter | Type | Description |
---|---|---|
name | str | Override for the function name |
description | str | Override for the function description |
show_result | bool | If True, shows the result after function call |
stop_after_tool_call | bool | If True, the agent will stop after the function call |
tool_hooks | list[Callable] | List of hooks to run before and after the function is executed |
cache_results | bool | If True, enable caching of function results |
cache_dir | str | Directory to store cache files |
cache_ttl | int | Time-to-live for cached results in seconds (default: 3600) |