Arize AX:为 ADK 提供的可观测性(Observability)功能¶
Arize AX 这是一个功能齐全的 AI 可观测性(AI Observability)与评估平台,由……提供。 Arize AI 适用于生产团队、基于人工智能技术的公司以及各类企业。该解决方案既可作为托管型云服务使用,也可由企业自行部署;同时为基于 Google ADK 的应用程序提供全面的追踪、评估与监控功能。要开始使用,请先注册一个账户。 免费账户.
如果您希望采用开源技术来进行本地开发、实验,或实现单容器自托管(即无需依赖外部服务器即可运行应用程序),可以了解一下相关解决方案。 Arize Phoenix 与 ADK 的集成.Arise的 代理评估指南 和 大语言模型(LLM)评估指南 展示团队如何使用追踪数据(traces)来评估代理(agents)的决策、工具调用(tool calls)以及模型行为(model behavior)。
概述¶
Arize AX 可以使用相关功能自动从 Google ADK 中收集追踪数据(即系统日志或调试信息)。 OpenInference 工具集(用于性能分析和代码调试)这使您能够:
- 跟踪代理之间的交互(即代理之间的通信或数据交换行为) - 自动记录每次代理运行的详细信息(包括运行时间、使用的工具、发送的模型请求以及收到的响应结果),同时附带相关上下文数据和元数据。
- 评估性能 - 使用自定义或预先构建的评估工具来分析代理的行为,并通过实验来测试不同的代理配置。
- 在生产环境中进行监控(即对系统的运行状态进行实时监测)。 - 设置实时仪表板和警报,以监控系统性能。
- 调试问题 - 分析详细的日志记录,以便快速识别性能瓶颈、工具调用失败的情况以及代理程序的任何异常行为。

安装¶
安装所需的软件包:
设置¶
1. 配置环境变量¶
请设置您的 Google API 密钥:
2. 将您的应用程序连接到 Arize AX。¶
from arize.otel import register
# Register with 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 the automatic instrumentor from OpenInference
from openinference.instrumentation.google_adk import GoogleADKInstrumentor
# Finish automatic instrumentation
GoogleADKInstrumentor().instrument(tracer_provider=tracer_provider)
观察;留意¶
现在您的跟踪功能已经设置完成,所有来自 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 the current weather report for a specified city.
Args:
city (str): The name of the city for which to retrieve the weather report.
Returns:
dict: status and result or error msg.
"""
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-flash-latest",
description="Agent to answer questions using weather tools.",
instruction="You must use the 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 the 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())
在 Arize AX 中查看结果¶
