Team Streaming Metrics

Capture metrics from team streaming responses.

Capture metrics from team streaming responses. Use yield_run_output=True to receive a TeamRunOutput at the end of the stream.

team_streaming_metrics.py
"""
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-5.6-luna"),
    role="Helpful assistant that answers questions.",
)

# ---------------------------------------------------------------------------
# Create Team
# ---------------------------------------------------------------------------
team = Team(
    name="Streaming Team",
    model=OpenAIChat(id="gpt-5.6-luna"),
    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)

Example behavior

Consume the iterator to completion to receive the final TeamRunOutput. Its metrics describe the leader and auxiliary calls; inspect member responses separately for delegated usage. This loop discards content events, so it prints metrics rather than the counted numbers.

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

python team_streaming_metrics.py

Full source: cookbook/03_teams/22_metrics/02_team_streaming_metrics.py