team_streaming_metrics.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
team_streaming_metrics.py, then run:Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Capture metrics from team streaming responses.
"""
Team Streaming Metrics
=============================
Demonstrates how to capture metrics from team streaming responses.
Use yield_run_output=True to receive a TeamRunOutput at the end of the stream.
"""
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.run.team import TeamRunOutput
from agno.team import Team
from rich.pretty import pprint
# ---------------------------------------------------------------------------
# Create Members
# ---------------------------------------------------------------------------
assistant = Agent(
name="Assistant",
model=OpenAIChat(id="gpt-4o-mini"),
role="Helpful assistant that answers questions.",
)
# ---------------------------------------------------------------------------
# Create Team
# ---------------------------------------------------------------------------
team = Team(
name="Streaming Team",
model=OpenAIChat(id="gpt-4o-mini"),
members=[assistant],
markdown=True,
)
# ---------------------------------------------------------------------------
# Run Team (Streaming)
# ---------------------------------------------------------------------------
if __name__ == "__main__":
response = None
for event in team.run("Count from 1 to 5.", stream=True, yield_run_output=True):
if isinstance(event, TeamRunOutput):
response = event
if response and response.metrics:
print("=" * 50)
print("STREAMING TEAM METRICS")
print("=" * 50)
pprint(response.metrics)
print("=" * 50)
print("MODEL DETAILS")
print("=" * 50)
if response.metrics.details:
for model_type, model_metrics_list in response.metrics.details.items():
print(f"\n{model_type}:")
for model_metric in model_metrics_list:
pprint(model_metric)
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
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
team_streaming_metrics.py, then run:python team_streaming_metrics.py
Was this page helpful?