本指南解释了如何将您的 ADK Agent 与 Google Cloud 平台(GCP)服务、在 Google Cloud Agent 平台上运行的模型以及 Agent 平台服务连接和认证。

设置 Google Cloud Agent 平台

在尝试将 Agent 连接到 Google Cloud 或 Agent 平台服务之前,请确保您已完成以下先决条件:

  • 已启用 Agent Platform API(aiplatform.googleapis.com)的 Google Cloud 项目。
  • 安装 gcloud CLI 工具。

Google Cloud 身份验证选项

在将您的 ADK Agent 连接到 Google Cloud 时,您有几种身份验证选项,如下表所示。

方法最适用场景身份验证机制环境
用户凭据本地开发和测试通过 gcloud 的应用默认凭据 (ADC)本地工作站
服务账户生产部署和 CI/CDGoogle IAM 服务账户密钥 / 工作负载身份Google Cloud(Agent Runtime, Cloud Run, GKE)或外部服务器
快速模式快速原型和测试API 密钥本地或云环境
Agent 身份(官方英文)生产部署和 CI/CDGoogle IAM 服务账户密钥 / 工作负载身份Google Cloud(Agent Runtime, Cloud Run, GKE)

本地开发的用户凭据

使用用户凭据身份验证方法连接到 Google Cloud,以便在本地开发环境中工作。

  1. 在运行 ADK Agent 应用程序 之前,使用应用默认凭据 (ADC) 对本地工作站进行身份验证:

    bash 1 行 展开 收起
    gcloud auth application-default login
  2. 设置您的环境变量以启用 Agent 平台并指定您的项目详细信息:

生产环境服务账户

在部署到安全的托管环境时,使用服务账户进行连接认证:

  1. 创建一个 服务账户,并授予它 Agent Platform User 角色。
  2. 根据部署策略向你的 Agent 应用提供凭据:
    • 在 Google Cloud 上部署(Agent Runtime, Cloud Run, GKE): 环境会自动提供凭据,无需配置密钥文件。

    • **外部运行:**生成一个 服务账户密钥文件 (.json),并配置 GOOGLE_APPLICATION_CREDENTIALS 环境变量:

      bash 1 行 展开 收起
      export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/service-account-key.json"

测试用 Agent 平台快速模式

快速模式提供简化的基于 API 密钥的设置,便于原型开发,无需完整的gcloud认证。

  1. 注册快速模式以获取 API 密钥。

  2. 设置以下环境变量:

Google Cloud 托管模型

Google Cloud Agent 平台托管了各种 AI 模型,您可以将其连接到您的 ADK Agent,包括 Gemini 模型、第三方 AI 模型、开源权重模型以及为您的组织定制调优的模型。一旦您将 ADK Agent 连接到 Google Cloud 和 Agent 平台,您就可以访问满足应用需求的 AI 模型。查看这些资源以探索并找到适合您项目的模型:

  • 获取更多关于在 ADK Agent 中使用 Gemini 模型 的信息。
  • 在 Agent 平台托管模型 中探索第三方和自定义模型选项,可用于 ADK Agent。
  • 在 Agent 平台 文档中查找 Google Cloud 提供的可用模型及模型 ID。

其他 Google Cloud 服务连接

许多 Google Cloud 服务提供 ADK 集成,并带有用于通过 ADK Agent 访问 GCP API 或资源的身份验证辅助工具。更多信息,请参见以下页面:


原文:Connect to Google Cloud and Agent Platform · 固定源版本

最后更新 2026-11-12 22:49 . history