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

# Arize

> 集成 Agno 与 Arize Phoenix 以发送追踪日志并深入了解您的代理性能。

## 集成 Agno 与 Arize Phoenix

[Arize Phoenix](https://phoenix.arize.com/) 是一个强大的平台，用于监控和分析 AI 模型。通过将 Agno 与 Arize Phoenix 集成，您可以利用 OpenInference 发送追踪日志，并深入了解您的代理性能。

## 前提条件

1. **安装依赖**

   确保您已安装必要的软件包：

   ```bash theme={null}
   pip install arize-phoenix openai openinference-instrumentation-agno opentelemetry-sdk opentelemetry-exporter-otlp
   ```

2. **设置 Arize Phoenix 账户**

   * 在 [Arize Phoenix](https://phoenix.arize.com/) 创建一个账户。
   * 从 Arize Phoenix 控制面板获取您的 API 密钥。

3. **设置环境变量**

   配置您的环境，包含 Arize Phoenix API 密钥：

   ```bash theme={null}
   export ARIZE_PHOENIX_API_KEY=<your-key>
   ```

## 发送追踪日志到 Arize Phoenix

* ### 示例：将 Arize Phoenix 与 OpenInference 一起使用

  此示例演示了如何使用 OpenInference 对 Agno 代理进行插桩，并将追踪日志发送到 Arize Phoenix。

```python theme={null}
import asyncio
import os

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.yfinance import YFinanceTools
from phoenix.otel import register

# 设置 Arize Phoenix 的环境变量
os.environ["PHOENIX_CLIENT_HEADERS"] = f"api_key={os.getenv('ARIZE_PHOENIX_API_KEY')}"
os.environ["PHOENIX_COLLECTOR_ENDPOINT"] = "https://app.phoenix.arize.com"

# 配置 Phoenix Tracer
tracer_provider = register(
    project_name="agno-stock-price-agent",  # 默认为 'default'
    auto_instrument=True,  # 自动使用已安装的 OpenInference 插桩
)

# 创建并配置代理
agent = Agent(
    name="Stock Price Agent",
    model=OpenAIChat(id="gpt-4o-mini"),
    tools=[YFinanceTools()],
    instructions="You are a stock price agent. Answer questions in the style of a stock analyst.",
    debug_mode=True,
)

# 使用代理
agent.print_response("What is the current price of Tesla?")
```

现在，前往 [phoenix cloud](https://app.phoenix.arize.com)，查看由您的代理创建的追踪日志。您可以直接从 Arize Phoenix 控制面板可视化执行流程、监控性能和调试问题。

<Frame caption="Arize Phoenix Trace">
  <img src="https://mintcdn.com/ikun/QKpfPChraOG28GfC/images/arize-phoenix-trace.png?fit=max&auto=format&n=QKpfPChraOG28GfC&q=85&s=e6a345cb1c55cf71c9d9ce9a4db6a891" style={{ borderRadius: '10px', width: '100%', maxWidth: '800px' }} alt="arize-agno observability" width="2160" height="1239" data-path="images/arize-phoenix-trace.png" />
</Frame>

* ### 示例：本地 Collector 设置

  对于本地开发，您可以使用以下命令运行本地 Collector：

```bash theme={null}
phoenix serve
```

```python theme={null}
import os

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.yfinance import YFinanceTools
from phoenix.otel import register

# 设置本地 Collector 端点
os.environ["PHOENIX_COLLECTOR_ENDPOINT"] = "http://localhost:6006"

# 配置 Phoenix Tracer
tracer_provider = register(
    project_name="agno-stock-price-agent",  # 默认为 'default'
    auto_instrument=True,  # 自动使用已安装的 OpenInference 插桩
)

# 创建并配置代理
agent = Agent(
    name="Stock Price Agent",
    model=OpenAIChat(id="gpt-4o-mini"),
    tools=[YFinanceTools()],
    instructions="You are a stock price agent. Answer questions in the style of a stock analyst.",
    debug_mode=True,
)

# 使用代理
agent.print_response("What is the current price of Tesla?")
```

## 注意事项

* **环境变量**: 确保您的环境变量（API 密钥和 Collector 端点）已正确设置。
* **本地开发**: 在开发过程中，请使用 `phoenix serve` 启动本地 Collector。

通过遵循这些步骤，您可以有效地将 Agno 与 Arize Phoenix 集成，从而实现对 AI 代理的全面可观测性和监控。
