集成 Agno 与 Arize Phoenix
Arize Phoenix 是一个强大的平台,用于监控和分析 AI 模型。通过将 Agno 与 Arize Phoenix 集成,您可以利用 OpenInference 发送追踪日志,并深入了解您的代理性能。
前提条件
-
安装依赖
确保您已安装必要的软件包:
pip install arize-phoenix openai openinference-instrumentation-agno opentelemetry-sdk opentelemetry-exporter-otlp
-
设置 Arize Phoenix 账户
-
设置环境变量
配置您的环境,包含 Arize Phoenix API 密钥:
export ARIZE_PHOENIX_API_KEY=<your-key>
发送追踪日志到 Arize Phoenix
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,查看由您的代理创建的追踪日志。您可以直接从 Arize Phoenix 控制面板可视化执行流程、监控性能和调试问题。
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 代理的全面可观测性和监控。
Responses are generated using AI and may contain mistakes.