Skip to content

Agent Observability with Arize AX

使用 Arize AX 进行智能体可观测性

Arize AX is a production-grade observability platform for monitoring, debugging, and improving LLM applications and AI Agents at scale. It provides comprehensive tracing, evaluation, and monitoring capabilities for your Google ADK applications. To get started, sign up for a free account.

Arize AX 是一个生产级的可观测性平台,用于大规模监控、调试和改进 LLM 应用程序和 AI 智能体。它为您的 Google ADK 应用程序提供全面的跟踪、评估和监控功能。要开始使用,请注册免费账户

For an open-source, self-hosted alternative, check out Phoenix.

对于开源、自托管的替代方案,请查看 Phoenix

Overview

概述

Arize AX can automatically collect traces from Google ADK using OpenInference instrumentation, allowing you to:

Arize AX 可以使用 OpenInference 检测自动从 Google ADK 收集跟踪数据,使您能够:

  • Trace agent interactions - Automatically capture every agent run, tool call, model request, and response with context and metadata

跟踪智能体交互 - 自动捕获每个智能体运行、工具调用、模型请求和响应,包括上下文和元数据

  • Evaluate performance - Assess agent behavior using custom or pre-built evaluators and run experiments to test agent configurations

评估性能 - 使用自定义或预构建的评估器评估智能体行为,并运行实验以测试智能体配置

  • Monitor in production - Set up real-time dashboards and alerts to track performance

在生产环境中监控 - 设置实时仪表板和警报以跟踪性能

  • Debug issues - Analyze detailed traces to quickly identify bottlenecks, failed tool calls, and any unexpected agent behavior

调试问题 - 分析详细的跟踪数据以快速识别瓶颈、失败的工具调用和任何意外的智能体行为

Agent Traces

Installation

安装

Install required packages:

安装所需的包:

pip install openinference-instrumentation-google-adk google-adk arize-otel

Setup

设置

1. Configure Environment Variables

1. 配置环境变量

Set your Google API key:

设置您的 Google API 密钥:

export GOOGLE_API_KEY=[your_key_here]

2. Connect your application to Arize AX

2. 将您的应用程序连接到 Arize AX

from arize.otel import register

# Register with Arize AX
# 向 Arize AX 注册
tracer_provider = register(
    space_id="your-space-id",      # Found in app space settings page 在应用程序空间设置页面中找到
    api_key="your-api-key",        # Found in app space settings page 在应用程序空间设置页面中找到
    project_name="your-project-name"  # Name this whatever you prefer 您可以随意命名
)

# Import and configure automatic instrumentor from OpenInference
# 从 OpenInference 导入并配置自动检测器
from openinference.instrumentation.google_adk import GoogleADKInstrumentor

# Finish automatic instrumentation
# 完成自动检测
GoogleADKInstrumentor().instrument(tracer_provider=tracer_provider)

Observe

观测

Now that you have tracing setup, all Google ADK SDK requests will be streamed to Arize AX for observability and evaluation.

现在您已经设置了跟踪,所有 Google ADK SDK 请求都将流式传输到 Arize AX 进行可观测性和评估。

import nest_asyncio
nest_asyncio.apply()

from google.adk.agents import Agent
from google.adk.runners import InMemoryRunner
from google.genai import types

# Define a tool function
# 定义工具函数
def get_weather(city: str) -> dict:
    """Retrieves current weather report for a specified city.

    Args:
        city (str): The name of city for which to retrieve weather report.

    Returns:
        dict: status and result or error msg.
    """
    """检索指定城市的当前天气报告。

    参数:
        city (str): 要检索天气报告的城市名称。

    返回:
        dict: 状态和结果或错误消息。
    """
    if city.lower() == "new york":
        return {
            "status": "success",
            "report": (
                "The weather in New York is sunny with a temperature of 25 degrees"
                " Celsius (77 degrees Fahrenheit)."
            ),
        }
    else:
        return {
            "status": "error",
            "error_message": f"Weather information for '{city}' is not available.",
        }

# Create an agent with tools
# 创建带有工具的智能体
agent = Agent(
    name="weather_agent",
    model="gemini-2.0-flash-exp",
    description="Agent to answer questions using weather tools.",
    instruction="You must use available tools to find an answer.",
    tools=[get_weather]
)

app_name = "weather_app"
user_id = "test_user"
session_id = "test_session"
runner = InMemoryRunner(agent=agent, app_name=app_name)
session_service = runner.session_service

await session_service.create_session(
    app_name=app_name,
    user_id=user_id,
    session_id=session_id
)

# Run agent (all interactions will be traced)
# 运行智能体(所有交互都将被跟踪)
async for event in runner.run_async(
    user_id=user_id,
    session_id=session_id,
    new_message=types.Content(role="user", parts=[
        types.Part(text="What is the weather in New York?")]
    )
):
    if event.is_final_response():
        print(event.content.parts[0].text.strip())

View Results in Arize AX

在 Arize AX 中查看结果

Traces in Arize AX

Agent Visualization

Agent Experiments

Support and Resources

支持和资源

Arize AX 文档

Arize 社区 Slack

OpenInference 包