适用于 ADK 的 Google Cloud Agent Platform(Express 模式)¶
Google Cloud Agent Platform 的“express mode”提供了一个免费的访问层级,适用于原型设计和开发用途,使您无需创建完整的 Google Cloud 项目即可使用 Agent Platform 的各项服务。该服务涵盖了众多强大的 Agent Platform 功能,包括:
您可以使用 Google 账户注册一个快速模式(Express Mode)账户,并获得一个 API 密钥,以便与 ADK 一起使用。您可以通过以下方式获取 API 密钥: Google Cloud Console如需更多信息,请参阅: Agent Platform 的快速模式(Express Mode).
预览版本
Agent Platform 的 Express 模式功能目前仍处于预览阶段(即尚未正式发布)。如需了解更多信息,请参阅相关文档。 发布阶段说明(Launch Stage Descriptions).
Agent Platform 的 Express 模式存在一些限制(即:Express 模式的功能或使用方式受到某些限制)。
Agent Platform 的 Express 模式项目仅有效期为 90 天,且仅提供部分服务供使用(这些服务的使用量受到限制)。例如,Agent Runtime 实例的数量被限制为 10 个,而将应用程序部署到 Agent Runtime 需要付费才能使用相应功能。若要解除这些使用量限制并使用 Agent Platform 的所有服务,请为你的 Express 模式项目添加一个计费账户。
配置代理运行时容器(Configure Agent Runtime container)¶
在使用 Agent Platform 的快速(express)模式时,请创建一个……(此处应填写具体需要创建的内容)。 AgentEngine 用于启用代理组件的管理功能;
该功能允许代理平台对代理组件(如……)进行管理。 Session 和 Memory “objects.”
采用这种方法, Session 对象被视为该结构的子元素(即该结构的组成部分)来进行处理。
AgentEngine 在运行您的代理程序之前,请确保环境变量已正确设置,具体如下所示:
GOOGLE_GENAI_USE_ENTERPRISE=TRUE
GOOGLE_API_KEY=PASTE_YOUR_ACTUAL_EXPRESS_MODE_API_KEY_HERE
接下来,使用 Agent Platform SDK 创建您的 Agent Runtime 实例。
-
导入代理平台 SDK(Import Agent Platform SDK)。
-
使用您的 API 密钥初始化代理平台客户端(Agent Platform Client),并创建一个代理引擎实例(Agent Engine Instance)。
-
从响应中获取代理运行时(Agent Runtime)的名称和 ID,以便在“Memories”和“Sessions”功能中使用这些信息。
使用 [该工具/方法] 管理会话 VertexAiSessionService¶
VertexAiSessionService
该功能与 Agent Platform Express Mode 的 API 密钥兼容;您也可以在不指定任何项目或位置的情况下直接初始化会话对象。
# Requires: pip install google-adk[gcp]
# Plus environment variable setup:
# GOOGLE_GENAI_USE_ENTERPRISE=TRUE
# GOOGLE_API_KEY=PASTE_YOUR_ACTUAL_EXPRESS_MODE_API_KEY_HERE
from google.adk.sessions import VertexAiSessionService
# The app_name used with this service should be the Reasoning Engine ID or name
APP_ID = "your-reasoning-engine-id"
# Project and location are not required when initializing with Agent Platform express mode
session_service = VertexAiSessionService(agent_engine_id=APP_ID)
# Use REASONING_ENGINE_APP_ID when calling service methods, e.g.:
# session = await session_service.create_session(app_name=APP_ID, user_id= ...)
会话服务配额(Session Service Quotas)
对于免费的 Express 模式项目, VertexAiSessionService 具有以下配额:
- 每分钟可以创建、删除或更新 10 个代理运行时(Agent Runtime)会话。
- 每分钟向代理运行时(Agent Runtime)会话中追加 30 个事件。
使用 [该工具/方法] 来管理内存 VertexAiMemoryBankService¶
The VertexAiMemoryBankService 该类与 Agent Platform 的 express 模式 API 密钥兼容。您也可以选择在不依赖任何项目或位置的情况下直接初始化内存对象。
# Requires: pip install google-adk[gcp]
# Plus environment variable setup:
# GOOGLE_GENAI_USE_ENTERPRISE=TRUE
# GOOGLE_API_KEY=PASTE_YOUR_ACTUAL_EXPRESS_MODE_API_KEY_HERE
from google.adk.memory import VertexAiMemoryBankService
# The app_name used with this service should be the Reasoning Engine ID or name
APP_ID = "your-reasoning-engine-id"
# Project and location are not required when initializing with express mode
memory_service = VertexAiMemoryBankService(agent_engine_id=APP_ID)
# Generate a memory from that session so the Agent can remember relevant details about the user
# memory = await memory_service.add_session_to_memory(session)
内存服务配额(Memory Service Quotas)
对于免费的 Express 模式项目, VertexAiMemoryBankService 具有以下配额:
- 10 每分钟创建、删除或更新代理运行时(Agent Runtime)内存资源。
- 每分钟可以从代理运行时内存银行中获取、列出或检索数据。
代码示例:使用会话(Session)和内存(Memory)功能的天气信息查询系统(Weather Information Query System)¶
这个代码示例展示了一个天气信息提供程序(weather agent),该程序同时使用了这两种技术/方法。
VertexAiSessionService 和 VertexAiMemoryBankService 为了便于上下文管理(context management),系统允许代理(agent)调用用户的偏好设置(user preferences)以及之前的对话记录(conversations)。
- 具有会话(Session)和内存(Memory)功能的天气信息代理(Weather Information Agent) 使用 Agent Platform 的 express 模式