> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Metrics

> Inspect per-message, run, and session metrics after a YFinance tool call on a Postgres-backed agent.

```python metrics.py theme={null}
"""
Metrics
=============================

Metrics.
"""

from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.openai import OpenAIResponses
from agno.tools.yfinance import YFinanceTools
from rich.pretty import pprint

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    tools=[YFinanceTools()],
    markdown=True,
    session_id="test-session-metrics",
    db=PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai"),
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    # Get the run response directly from the non-streaming call
    run_response = agent.run("What is the stock price of NVDA")
    print("Tool execution completed successfully!")

    # Print metrics per message
    if run_response and run_response.messages:
        for message in run_response.messages:
            if message.role == "assistant":
                if message.content:
                    print(
                        f"Message: {message.content[:100]}..."
                    )  # Truncate for readability
                elif message.tool_calls:
                    print(f"Tool calls: {len(message.tool_calls)} tool call(s)")
                print("---" * 5, "Message Metrics", "---" * 5)
                if message.metrics:
                    pprint(message.metrics)
                else:
                    print("No metrics available for this message")
                print("---" * 20)

    # Print the run metrics
    print("---" * 5, "Run Metrics", "---" * 5)
    if run_response and run_response.metrics:
        pprint(run_response.metrics)
    else:
        print("No run metrics available")

    # Print the session metrics
    print("---" * 5, "Session Metrics", "---" * 5)
    try:
        session_metrics = agent.get_session_metrics()
        if session_metrics:
            pprint(session_metrics)
        else:
            print("No session metrics available")
    except Exception as e:
        print(f"Error getting session metrics: {e}")
```

## Run the Example

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno "psycopg[binary]" openai sqlalchemy yfinance
```

**2. Export your OpenAI API key**

```bash Mac/Linux theme={null}
export OPENAI_API_KEY="your_openai_api_key_here"
```

```bash Windows theme={null}
$Env:OPENAI_API_KEY="your_openai_api_key_here"
```

<Snippet file="run-pgvector-step.mdx" />

**3. Run the example**

Save the code above as `metrics.py`, then run:

```bash theme={null}
python metrics.py
```

Full source: [cookbook/02\_agents/14\_advanced/metrics.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/02_agents/14_advanced/metrics.py)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.