Updating an Agent's Tools
Add or update tools on Agents and Teams after initialization.
Before running the examples:
pip install agno openai
export OPENAI_API_KEY="your-api-key"Tools can be added to Agents and Teams post-creation. This gives you the flexibility to add tools to an existing Agent or Team instance after initialization, which is useful for dynamic tool management or when you need to conditionally add tools based on runtime requirements.
The whole collection of tools available to an Agent or Team can also be updated by using the set_tools call. Note that this will remove any other tools already assigned to your Agent or Team and override it with the list of tools provided to set_tools.
add_tool appends to a concrete tool list. It raises RuntimeError when tools is a callable factory; use set_tools to replace that factory. For tools that vary by user or request, use a callable factory rather than mutating a shared instance during a run.
The weather and stock tools below return demonstration data, not live market or weather results.
Agent Example
Create your own tool, for example get_weather. Then call add_tool to attach it to your Agent.
import random
from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.tools import tool
@tool(stop_after_tool_call=True)
def get_weather(city: str) -> str:
"""Get the weather for a city."""
# In a real implementation, this would call a weather API
weather_conditions = ["sunny", "cloudy", "rainy", "snowy", "windy"]
random_weather = random.choice(weather_conditions)
return f"The weather in {city} is {random_weather}."
agent = Agent(
model=OpenAIResponses(id="gpt-5.2"),
markdown=True,
)
agent.print_response("What can you do?", stream=True)
agent.add_tool(get_weather)
agent.print_response("What is the weather in San Francisco?", stream=True)Team Example
Create a list of tools, and assign them to your Team with set_tools
import random
from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.team.team import Team
from agno.tools import tool
from agno.tools.calculator import CalculatorTools
agent1 = Agent(
name="Stock Searcher",
model=OpenAIResponses(id="gpt-5.2"),
)
agent2 = Agent(
name="Company Info Searcher",
model=OpenAIResponses(id="gpt-5.2"),
)
team = Team(
name="Stock Research Team",
model=OpenAIResponses(id="gpt-5.2"),
members=[agent1, agent2],
tools=[CalculatorTools()],
markdown=True,
show_members_responses=True,
)
@tool
def get_stock_price(stock_symbol: str) -> str:
"""Get the current stock price of a stock."""
return f"The current stock price of {stock_symbol} is {random.randint(100, 1000)}."
@tool
def get_stock_availability(stock_symbol: str) -> str:
"""Get the current availability of a stock."""
return f"The current stock available of {stock_symbol} is {random.randint(100, 1000)}."
team.set_tools([get_stock_price, get_stock_availability])
team.print_response("What is the current stock price of NVDA?", stream=True)
team.print_response("How much stock NVDA stock is available?", stream=True)
- The
add_toolmethod allows you to dynamically extend an Agent's or a Team's capabilities. This is particularly useful when you want to add tools based on user input or other runtime conditions. - The
set_toolsmethod allows you to override an Agent's or a Team's capabilities. Note that this will remove any existing tools previously assigned to your Agent or Team.
Developer Resources
- Creating your own tools - Write custom tools from Python functions
- Available Toolkits - Browse pre-built toolkits
- Selecting Tools - Filter which tools a toolkit exposes