Stop After Tool Call

Return a tool result without a further model response using stop_after_tool_call.

stop_after_tool_call.py
"""
Stop After Tool Call
=============================

Demonstrates stop after tool call.
"""

from agno.agent import Agent
from agno.tools import tool

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------


@tool(stop_after_tool_call=True)
def get_answer_to_life_universe_and_everything() -> str:
    """
    This returns the answer to the life, the universe and everything.
    """
    return "42"


agent = Agent(
    tools=[get_answer_to_life_universe_and_everything],
    markdown=True,
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    agent.print_response("What is the answer to life, the universe and everything?")

The stop flag takes effect when the model calls this tool. To make the demonstration deterministic with the default OpenAI model, add tool_choice="required" to Agent(...). The tool returns the literal string 42; the model does not write a further answer after that call.

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 stop_after_tool_call.py, then run:

python stop_after_tool_call.py

Full source: cookbook/91_tools/tool_decorator/stop_after_tool_call.py