How do tools work?
The heart of Agent execution is the LLM loop. The typical execution flow of the LLM loop is:- The agent sends the run context (system message, user message, chat history, etc) and tool definitions to the model.
- The model responds with a message or a tool call.
- If the model makes a tool call, the tool is executed and the result is returned to the model.
- The model processes the updated context, repeating this loop until it produces a final message without any tool calls.
- The agent returns this final response to the caller.
Tool definitions
Agno automatically converts your tool functions into the required tool definition format for the model. Typically this is a JSON schema that describes the parameters and return type of the tool. For example:Args section is automatically stripped from the definition, parsed and used to populate the definitions of individual properties.
When using a Pydantic model in an argument of a tool function, Agno will automatically convert the model into the required tool definition format.
For example:
Tool Execution
When the model requests a tool call, the tool is executed and the result is returned to the model.- A model can request multiple tool calls in a single response.
- When using
arunto execute the agent or team, and the model requested multiple tool calls, the tools will be executed concurrently.
When you call
arun or aprint_response, your tools will execute concurrently. If you provide synchronous functions as tools, they will execute concurrently on separate threads.Concurrent execution of tools requires a model that supports parallel function
calling. For example, OpenAI models have a
parallel_tool_calls parameter
(enabled by default) that allows multiple tool calls to be requested and
executed simultaneously.Async Execution Example
Async Execution Example
async_tools.py
gpt-5-mini makes three simultaneous tool calls to atask1, atask2 and atask3. Normally these tool calls would execute sequentially, but using the aprint_response function, they run concurrently, improving execution time.
Using a Toolkit
An Agno Toolkit provides a way to manage multiple tools with additional control over their execution.HackerNewsTools toolkit is added to the agent. This toolkit enables the agent to fetch stories from HackerNews.
Tool Built-in Parameters
Agno automatically provides special parameters to your tools that give access to the agent’s parameters, state and other variables. These parameters are injected automatically - the agent doesn’t need to know about them.Using the Run Context
You can access values from the current run via therun_context parameter: run_context.session_state, run_context.dependencies, run_context.knowledge_filters, run_context.metadata. See the RunContext schema for more information.
This allows tools to access and modify persistent data across conversations.
This is useful in cases where a tool result is relevant for the next steps of the conversation.
Add run_context as a parameter in your tool function to access the agent’s persistent state:
Using the Agent or Team
You can access theAgent or Team instance directly in your tool function by adding agent or team as a parameter. This gives you full access to the agent’s or team’s properties like model, instructions, etc.
When using
team as a parameter, make sure the tool is being used within a Team context. Similarly, use agent when the tool is used with an Agent.Media Parameters
The built-in parameterimages, videos, audio, and files allows tools to access and modify the input media to an agent.
Using the
send_media_to_model parameter, you can control whether the media is sent to the model or not and using store_media parameter, you can control whether the
media is stored in the RunOutput or not.Tool Results
Tools can return different types of results depending on their complexity and what they need to communicate back to the agent.Simple Return Types
Most tools can return simple Python types directly likestr, int, float, dict, and list:
ToolResult for Media Content
When your tool needs to return media artifacts (images, videos, audio), you must use ToolResult:
| Parameter | Type | Default | Description |
|---|---|---|---|
content | str | Required | Main text content/output from the tool |
images | Optional[List[Image]] | None | Generated image artifacts |
videos | Optional[List[Video]] | None | Generated video artifacts |
audios | Optional[List[Audio]] | None | Generated audio artifacts |
Callable Factories
Agno tools support callable factory pattern for dynamic configuration. Implement a dynamic tool factory using callables for runtime dependency injection and context-aware toolset customization.- Runtime Resolution: Tools are lazily initialized at the start of each run via signature-based injection.
-
Context Injection: Automatically maps
agent/team,run_context, andsession_stateto the factory parameters. -
Granular Scoping: Enables unique tool sets tailored specifically to the
user_idor session_id. -
Performance Optimization: Includes built-in caching (
cache_callables) to memoize toolsets based on unique session keys.
| Parameters | Purpose |
|---|---|
agent | Accesses the base agent instance/configuration. |
run_context | Provides metadata like user_id for scoping tools. |
session_state | Allows tools to be shaped by current conversation memory. |
Learn more
Equip agents with tools for external actions
Give teams shared tool capabilities
Available Toolkits
Browse 120+ pre-built toolkits
MCP Tools
Connect to Model Context Protocol servers
Reasoning Tools
Add knowledge, memory, and workflow tools
Creating your own tools
Write custom Python functions as tools