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

# Llama OpenAI Metrics

> Stream a Llama 4 Maverick run with YFinance tools and inspect message, run, and session metrics.

<Warning>
  This example reads `agent.run_response.messages`, but `Agent` does not expose that attribute. Update the saved file before running.
</Warning>

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

Cookbook example for `meta/llama_openai/metrics.py`.
"""

from typing import Iterator

from agno.agent import Agent, RunOutputEvent
from agno.models.meta import LlamaOpenAI
from agno.tools.yfinance import YFinanceTools
from agno.utils.pprint import pprint_run_response
from rich.pretty import pprint

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

agent = Agent(
    model=LlamaOpenAI(id="Llama-4-Maverick-17B-128E-Instruct-FP8"),
    tools=[YFinanceTools()],
    markdown=True,
)

run_stream: Iterator[RunOutputEvent] = agent.run(
    "What is the stock price of NVDA", stream=True
)
pprint_run_response(run_stream, markdown=True)

run_response = agent.get_last_run_output()

# Print metrics per message
if run_response.messages:
    for message in agent.run_response.messages:
        if message.role == "assistant":
            if message.content:
                print(f"Message: {message.content}")
            elif message.tool_calls:
                print(f"Tool calls: {message.tool_calls}")
            print("---" * 5, "Metrics", "---" * 5)
            pprint(message.metrics)
            print("---" * 20)

# Print the metrics
print("---" * 5, "Collected Metrics", "---" * 5)
pprint(run_response.metrics)
# Print the session metrics
print("---" * 5, "Session Metrics", "---" * 5)
pprint(agent.get_session_metrics())

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    pass
```

## Run the Example

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

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno llama-api-client openai yfinance
    ```
  </Step>

  <Step title="Export your Meta Llama API key">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export LLAMA_API_KEY="your_llama_api_key_here"
      ```

      ```bash Windows theme={null}
      $Env:LLAMA_API_KEY="your_llama_api_key_here"
      ```
    </CodeGroup>
  </Step>

  <Step title="Correct the message metrics loop">
    Replace `agent.run_response.messages` with `run_response.messages` in the saved file.
  </Step>

  <Step title="Run the example">
    Save the code above as `metrics.py`, then run:

    ```bash theme={null}
    python metrics.py
    ```
  </Step>
</Steps>

Full source: [cookbook/90\_models/meta/llama\_openai/metrics.py](https://github.com/agno-agi/agno/blob/main/cookbook/90_models/meta/llama_openai/metrics.py)
