Agent Extra Metrics
Read audio, cache, and reasoning token counts from RunMetrics.
Access audio, cache, and reasoning token counts from agent runs.
Code
import requests
from agno.agent import Agent
from agno.media import Audio
from agno.models.openai import OpenAIChat, OpenAIResponses
from agno.utils.pprint import pprint_run_response
# Fetch the audio file as raw bytes
url = "https://openaiassets.blob.core.windows.net/$web/API/docs/audio/alloy.wav"
response = requests.get(url)
response.raise_for_status()
wav_data = response.content
agent = Agent(
model=OpenAIChat(
id="gpt-audio",
modalities=["text", "audio"],
audio={"voice": "sage", "format": "wav"},
),
markdown=True,
)
run_response = agent.run(
"What's in this recording?",
audio=[Audio(content=wav_data, format="wav")],
)
pprint_run_response(run_response)
# Showing input audio and output audio tokens metrics
print(f"Input audio tokens: {run_response.metrics.audio_input_tokens}")
print(f"Output audio tokens: {run_response.metrics.audio_output_tokens}")
agent = Agent(
model=OpenAIResponses(id="gpt-5.2"),
markdown=True,
telemetry=False,
)
run_response = agent.run(
"Solve the trolley problem. Evaluate multiple ethical frameworks. Include an ASCII diagram of your solution.",
stream=False,
)
pprint_run_response(run_response)
# Showing reasoning tokens metrics
print(f"Reasoning tokens: {run_response.metrics.reasoning_tokens}")
agent = Agent(model=OpenAIResponses(id="gpt-5.2"), markdown=True, telemetry=False)
agent.run("Share a 2 sentence horror story" * 150)
run_response = agent.run("Share a 2 sentence horror story" * 150)
# Showing cached tokens metrics
print(f"Cached tokens: {run_response.metrics.cache_read_tokens}")Usage
Create a Python file
Create agent_extra_metrics.py with the code above.
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno openai requestsExport your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"Run Agent
python agent_extra_metrics.py