Tool Call Limit

Use tool call limit to control the number of tool calls an agent can make.

tool_call_limit.py
"""
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,
    )

Register both requested tools

Before running, replace tools=[YFinanceTools()] with:

tools=[YFinanceTools(enable_company_news=True)],

The default toolkit exposes the stock-price tool but leaves company news disabled. Keep tool_call_limit=1 to demonstrate the limit with both tools available. The prompt requests price before news; the model chooses its calls, and the limit restricts execution rather than guaranteeing that order.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno openai yfinance

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

Run the example

Save the code above as tool_call_limit.py, then run:

python tool_call_limit.py

Full source: cookbook/02_agents/04_tools/tool_call_limit.py