Tool Call Limit

Demonstrates constraining how many tool calls a Team can make in a single run.

tool_call_limit.py
"""
Tool Call Limit
===============

Demonstrates constraining how many tool calls a Team can make in a single run.
"""

from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.team import Team
from agno.tools import tool


@tool()
def lookup_product_price(product_name: str) -> str:
    """Get a static price for supported products."""
    catalog = {
        "camera": "$699 USD",
        "drone": "$899 USD",
        "laptop": "$1,249 USD",
    }
    return catalog.get(product_name.lower(), "This product is not in the catalog")


@tool()
def lookup_shipping_time(country: str) -> str:
    """Get a static shipping time by destination."""
    shipping_times = {
        "us": "3-5 business days",
        "eu": "5-7 business days",
        "asia": "7-14 business days",
    }
    return shipping_times.get(country.lower(), "Unknown shipping zone")


# ---------------------------------------------------------------------------
# Create Members
# ---------------------------------------------------------------------------
order_agent = Agent(
    name="Order Planner",
    model=OpenAIResponses(id="gpt-5-mini"),
    instructions=[
        "Create accurate order summaries for the requested products.",
        "If info is missing, ask for clarification.",
    ],
)

# ---------------------------------------------------------------------------
# Create Team
# ---------------------------------------------------------------------------
orders_team = Team(
    name="Order Team",
    model=OpenAIResponses(id="gpt-5-mini"),
    members=[order_agent],
    tools=[lookup_product_price, lookup_shipping_time],
    tool_call_limit=1,
    instructions=[
        "You are a retail assistant.",
        "Use tools only when needed and keep responses concise.",
        "Remember that only one tool call is allowed in this run.",
    ],
    markdown=True,
)


# ---------------------------------------------------------------------------
# Run Team
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    orders_team.print_response(
        "For the camera sale, tell me the price and shipping time to EU.",
        stream=True,
    )

Leader and member budgets

The limit counts the leader's tool calls, including delegation. It does not establish a shared budget across every member's internal tools. With a limit of one, the leader cannot execute both local lookups in the prompt; a supported answer must acknowledge missing information or ask for another run. Prices and shipping times are fixed dictionaries in this script.

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

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/03_teams/03_tools/tool_call_limit.py