Documentation Index
Fetch the complete documentation index at: https://spacesail.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
This example demonstrates how to handle different types of events during agent run streaming. It shows how to capture and process content events, tool call started events, and tool call completed events.
Code
from typing import Iterator, List
from agno.agent import (
Agent,
RunContentEvent,
RunOutputEvent,
ToolCallCompletedEvent,
ToolCallStartedEvent,
)
from agno.models.anthropic import Claude
from agno.tools.duckduckgo import DuckDuckGoTools
agent = Agent(
model=Claude(id="claude-sonnet-4-20250514"),
tools=[DuckDuckGoTools()],
markdown=True,
)
run_response: Iterator[RunOutputEvent] = agent.run(
"Whats happening in USA and Canada?", stream=True
)
response: List[str] = []
for chunk in run_response:
if isinstance(chunk, RunContentEvent):
response.append(chunk.content) # type: ignore
elif isinstance(chunk, ToolCallStartedEvent):
response.append(
f"Tool call started: {chunk.tool.tool_name} with args: {chunk.tool.tool_args}" # type: ignore
)
elif isinstance(chunk, ToolCallCompletedEvent):
response.append(
f"Tool call completed: {chunk.tool.tool_name} with result: {chunk.tool.result}" # type: ignore
)
print("\n".join(response))
Usage
Create a virtual environment
Open the Terminal and create a python virtual environment.python3 -m venv .venv
source .venv/bin/activate
Install libraries
pip install -U agno anthropic ddgs
Export your ANTHROPIC API key
export ANTHROPIC_API_KEY="your_anthropic_api_key_here"
Create a Python file
Create a Python file and add the above code.touch run_response_events.py
Run Agent
python run_response_events.py
Find All Cookbooks
Explore all the available cookbooks in the Agno repository. Click the link below to view the code on GitHub:Agno Cookbooks on GitHub