tool_call_limit.py
Run the Example
1
Set up your virtual environment
2
Install dependencies
3
Export your OpenAI API key
4
Run the example
Save the code above as
tool_call_limit.py, then run:Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Use tool call limit to control the number of tool calls an agent can make.
"""
Tool Call Limit
=============================
This cookbook shows how to use tool call limit to control the number of tool calls an agent can make.
"""
from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.tools.yfinance import YFinanceTools
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
model=OpenAIResponses(id="gpt-5-mini"),
tools=[YFinanceTools()],
tool_call_limit=1,
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
# It should only call the first tool and fail to call the second tool.
agent.print_response(
"Find me the current price of TSLA, then after that find me the latest news about Tesla.",
stream=True,
)
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Install dependencies
uv pip install -U agno openai yfinance
Export your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
Run the example
tool_call_limit.py, then run:python tool_call_limit.py
Was this page helpful?