本页面介绍了如何通过 Agent Gateway 路由 Gemini Enterprise 流量。Agent Gateway 是 Gemini Enterprise Agent Platform 生态系统的核心网络和安全组件。它为所有智能体交互提供安全且可管控的连接,无论这些交互是发生在智能体与工具之间,还是发生在智能体之间。
准备工作
- 确保您熟悉 Gemini Enterprise 概念。
- 了解 Agent Gateway。 请注意,Agent Gateway 仅支持在 Agent-to-Anywhere(出站流量)模式下使用 Gemini Enterprise。不支持入站流量。
- 部署 Gemini Enterprise 应用(也称为引擎)。 本页面中的过程假定您已部署应用。如需了解详情,请参阅创建应用。
规划位置和 Agent Registry 映射
在部署 Agent Gateway 之前,请选择要部署网关的区域以及要注册资源的 Agent Registry。请注意以下要求:
位置映射:在与 Gemini Enterprise 应用位置对应的特定区域部署 Agent Gateway,以确保正确路由。
注册表映射:将 Agent Gateway 与网关所在项目和区域中的区域级 Agent Registry 实例相关联。如需详细了解部署模式,请参阅规划 Agent Gateway 部署。
| Gemini Enterprise 应用位置 | 所需的 Agent Gateway 区域 | Agent Gateway 所需的 Agent Registry 实例 |
|---|---|---|
global |
us-central1 |
us-central1 (//agentregistry.googleapis.com/projects/PROJECT_ID/locations/us-central1) |
us |
us-central1 |
us-central1 (//agentregistry.googleapis.com/projects/PROJECT_ID/locations/us-central1) |
eu |
europe-west1 |
europe-west1 (//agentregistry.googleapis.com/projects/PROJECT_ID/locations/europe-west1) |
如果您的 Gemini Enterprise 应用和 Agent Gateway 位于不同的项目中,请参阅将 Gemini Enterprise 连接到跨项目 Agent Gateway。
通过 Agent Gateway 路由 Gemini Enterprise 流量
网关会将查询时流量从您的应用路由到以下资源:
- 您从 Agent Registry 导入的 MCP 服务器和 A2A 智能体,如本过程后面部分所述。
- 您配置为使用 Agent Gateway VPC 出站流量的自定义 MCP 服务器。如需了解详情,请参阅设置具有 VPC 连接的自定义 MCP 服务器数据存储区的前提条件。
- 由 Agent Registry 提供支持的操作连接器。
网关不会路由以下流量:
- 通过网址连接且不使用 Agent Gateway VPC 出站流量的自定义 MCP 服务器的流量。
- 流向您未从 Agent Registry 导入的 A2A 智能体的流量。
- 生成模型推理调用、数据存储区检索、内置助理工具和连接器提取流量。
您可以使用授权政策来保护网关路由的流量。
如需通过 Agent Gateway 路由 Gemini Enterprise 流量,请执行以下步骤:
创建 Agent Gateway 资源,并确保您遵循在上一部分中选择的区域和注册表。如需查看相关说明,请参阅设置 Agent Gateway。
验证网关配置。使用 Network Services API 检索 Agent Gateway 配置并检查设置。
curl -X GET \ -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \ "https://networkservices.googleapis.com/v1/projects/PROJECT_ID/locations/AGENT_GATEWAY_REGION/agentGateways/AGENT_GATEWAY_NAME"
以下是正确配置的网关的示例输出:
{ "name": "projects/my-ge-project/locations/us-central1/agentGateways/my-egress-gateway", "description": "A full configuration for Agent Gateway for Gemini Enterprise egress", "googleManaged": { "governedAccessPath": "AGENT_TO_ANYWHERE" }, "protocols": [ "MCP" ], "registries": [ "//agentregistry.googleapis.com/projects/my-ge-project/locations/us-central1" ] }使用
UpdateEngineAPI 将网关绑定到 Gemini Enterprise 应用。请注意,完成此步骤后,所有现有智能体流量都会立即通过指定的 Agent Gateway 进行路由。控制台
在 Google Cloud 控制台中,前往 Gemini Enterprise 页面。
点击要与 Agent Gateway 关联的应用的名称。
点击安全。
在配置标签页的Agent Gateway 配置下,输入网关的完整资源名称。请使用以下格式:
projects/PROJECT_ID/locations/LOCATION/agentGateways/AGENT_GATEWAY_NAME。点击保存。
REST
使用以下请求更新应用。
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -H "X-Goog-User-Project: PROJECT_ID" \ -d '{ "agentGatewaySetting": { "defaultEgressAgentGateway": { "name": "projects/PROJECT_ID/locations/AGENT_GATEWAY_REGION/agentGateways/AGENT_GATEWAY_NAME" } } }' \ "https://ENDPOINT_LOCATION-discoveryengine.googleapis.com/v1/projects/PROJECT_NUMBER/locations/GE_APP_LOCATION/collections/default_collection/engines/GE_APP_ID?updateMask=agentGatewaySetting.defaultEgressAgentGateway.name"
替换以下内容:
PROJECT_ID:项目 ID。AGENT_GATEWAY_REGION:Agent Gateway 的区域。AGENT_GATEWAY_NAME:Agent Gateway 的名称。ENDPOINT_LOCATION:与GE_APP_LOCATION匹配的 API 端点的多区域前缀。指定global、us或eu。例如,eu应用使用eu-discoveryengine.googleapis.com。对于global应用,系统也支持不带前缀的discoveryengine.googleapis.com。PROJECT_NUMBER:项目编号。GE_APP_LOCATION:Gemini Enterprise 应用所在的位置。指定global、us或eu。GE_APP_ID:Gemini Enterprise 应用的 ID。
如需验证应用配置,请使用以下命令检索配置并检查设置:
curl -s -X GET \ -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \ -H "X-Goog-User-Project: PROJECT_ID" \ -H "Content-Type: application/json" \ "https://ENDPOINT_LOCATION-discoveryengine.googleapis.com/v1/projects/PROJECT_NUMBER/locations/GE_APP_LOCATION/collections/default_collection/engines/GE_APP_ID" \ | jq '{name: .name, displayName: .displayName, agentGatewaySetting: .agentGatewaySetting}'替换以下内容:
PROJECT_ID:项目 ID。ENDPOINT_LOCATION:与GE_APP_LOCATION匹配的 API 端点的多区域前缀。指定global、us或eu。PROJECT_NUMBER:项目编号。GE_APP_LOCATION:Gemini Enterprise 应用所在的位置。指定global、us或eu。GE_APP_ID:Gemini Enterprise 应用的 ID。
以下是正确配置的应用的示例输出:
{ "name": "projects/PROJECT_NUMBER/locations/GE_APP_LOCATION/collections/default_collection/engines/GE_APP_ID", "displayName": "GE_APP_ID", "agentGatewaySetting": { "defaultEgressAgentGateway": { "name": "projects/PROJECT_ID/locations/AGENT_GATEWAY_REGION/agentGateways/AGENT_GATEWAY_NAME" } } }
虽然现在已为 Gemini Enterprise 应用启用出站流量治理,但应用不会自动知道它可以与 Agent Registry 中的哪些外部资源进行交互。
您必须将所选智能体、端点和 MCP 服务器明确导入 Gemini Enterprise 应用。导入的资源必须使用其基于注册表的确切资源名称进行引用。如需查看相关说明,请参阅以下指南:
如需验证出站流量是否正常运行,请执行以下步骤:
- 打开 Gemini Enterprise Web 应用。
- 提交旨在触发外部工具的查询(例如,“请提供 GitHub 中近期问题的列表”)。
- 监控执行情况,确保成功检索到响应。 在后台,Gemini Enterprise 智能体会打包请求,通过 Agent Gateway(强制执行所有已配置的授权政策)路由请求,并从目的地检索响应。
将 Gemini Enterprise 连接到跨项目 Agent Gateway
平台团队通常会在治理项目中托管一个中央 Agent Gateway 和 Agent Registry,而应用团队则会在单独的使用方项目中运行 Gemini Enterprise 应用。
请按照此过程将一个项目 (GE_PROJECT_ID) 中的 Gemini Enterprise 应用绑定到另一个项目 (AGENT_GATEWAY_PROJECT_ID) 中的 Agent Gateway。在开始之前,请在与应用位置匹配的区域(global 或 us 应用为 us-central1;eu 应用为 europe-west1)中部署 Agent Gateway,如规划位置和 Agent Registry 映射以及设置 Agent Gateway 中所述。
配置跨项目绑定
在网关项目中授予跨项目 Identity and Access Management (IAM) 角色
向 Gemini Enterprise 项目的 Discovery Engine 服务代理授予读取和绑定到网关及其代理注册表的权限(
roles/networkservices.viewer、roles/agentregistry.viewer和networkservices.agentGateways.use,包含在roles/compute.networkUser或自定义角色中):gcloud projects add-iam-policy-binding "AGENT_GATEWAY_PROJECT_ID" \ --member="serviceAccount:service-GE_PROJECT_NUMBER@gcp-sa-discoveryengine." \ --role="roles/networkservices.viewer" gcloud projects add-iam-policy-binding "AGENT_GATEWAY_PROJECT_ID" \ --member="serviceAccount:service-GE_PROJECT_NUMBER@gcp-sa-discoveryengine." \ --role="roles/compute.networkUser" gcloud projects add-iam-policy-binding "AGENT_GATEWAY_PROJECT_ID" \ --member="serviceAccount:service-GE_PROJECT_NUMBER@gcp-sa-discoveryengine." \ --role="roles/agentregistry.viewer"
向 Gemini Enterprise Workload Identity 主体集授予对网关项目的 Agent Registry 的访问权限(如果您的网关使用 Model Armor 或 Sensitive Data Protection,请授予
roles/modelarmor.user和roles/dlp.user):gcloud projects add-iam-policy-binding "AGENT_GATEWAY_PROJECT_ID" \ --member="principalSet://agents.global.org-ORGANIZATION_ID.system.id.goog/attribute.platformContainer/discoveryengine/projects/GE_PROJECT_NUMBER" \ --role="roles/agentregistry.viewer" # Optional: required only if your gateway uses Model Armor or Sensitive Data Protection gcloud projects add-iam-policy-binding "AGENT_GATEWAY_PROJECT_ID" \ --member="principalSet://agents.global.org-ORGANIZATION_ID.system.id.goog/attribute.platformContainer/discoveryengine/projects/GE_PROJECT_NUMBER" \ --role="roles/modelarmor.user" gcloud projects add-iam-policy-binding "AGENT_GATEWAY_PROJECT_ID" \ --member="principalSet://agents.global.org-ORGANIZATION_ID.system.id.goog/attribute.platformContainer/discoveryengine/projects/GE_PROJECT_NUMBER" \ --role="roles/dlp.user"
替换以下内容:
AGENT_GATEWAY_PROJECT_ID:托管 Agent Gateway 的项目 ID。GE_PROJECT_NUMBER:托管 Gemini Enterprise 应用的项目编号。ORGANIZATION_ID:您的组织 ID。
如果您的网关将授权委托给 Identity-Aware Proxy (IAP) 授权扩展,请在 IAM Unified Access Policies (UAP) 中使用
iap.googleapis.com/resources.egressViaIAP授权此主账号集(或为旧版 V1 政策授予roles/iap.egressor)。请参阅创建 IAM 代理政策和使用 Service Extensions 委托授权。等待大约 60 秒,让 IAM 更改生效,然后再继续。
将 Gemini Enterprise 应用绑定到跨项目网关
将 Gemini Enterprise 应用绑定到其他项目中的网关时,
UpdateEngine会拒绝已列出其他项目注册表的网关。暂时清除网关上的registries,绑定应用,然后恢复registries:# 1. Clear registries on the central gateway (skip if the gateway has no registries yet) curl -sS -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -H "X-Goog-User-Project: AGENT_GATEWAY_PROJECT_ID" \ -d '{"registries": []}' \ "https://networkservices.googleapis.com/v1/projects/AGENT_GATEWAY_PROJECT_ID/locations/AGENT_GATEWAY_REGION/agentGateways/AGENT_GATEWAY_NAME?updateMask=registries" # 2. Bind the Gemini Enterprise app cross-project to the gateway curl -sS -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -H "X-Goog-User-Project: GE_PROJECT_ID" \ -d '{ "agentGatewaySetting": { "defaultEgressAgentGateway": { "name": "projects/AGENT_GATEWAY_PROJECT_NUMBER/locations/AGENT_GATEWAY_REGION/agentGateways/AGENT_GATEWAY_NAME" } } }' \ "https://ENDPOINT_LOCATION-discoveryengine.googleapis.com/v1/projects/GE_PROJECT_NUMBER/locations/GE_APP_LOCATION/collections/default_collection/engines/GE_APP_ID?updateMask=agentGatewaySetting.defaultEgressAgentGateway.name" # 3. Restore registries on the central gateway curl -sS -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -H "X-Goog-User-Project: AGENT_GATEWAY_PROJECT_ID" \ -d '{ "registries": [ "//agentregistry.googleapis.com/projects/AGENT_GATEWAY_PROJECT_NUMBER/locations/AGENT_GATEWAY_REGION" ] }' \ "https://networkservices.googleapis.com/v1/projects/AGENT_GATEWAY_PROJECT_ID/locations/AGENT_GATEWAY_REGION/agentGateways/AGENT_GATEWAY_NAME?updateMask=registries"
替换以下内容:
AGENT_GATEWAY_PROJECT_NUMBER:网关项目编号。AGENT_GATEWAY_REGION:网关及其单个区域级 Agent Registry 实例的区域(us-central1对应global或us应用;europe-west1对应eu应用,如规划位置和 Agent Registry 映射中所列)。在网关上仅配置一个注册表。 如果eu应用导入REGISTRY_MCP连接器,请使用locations/global而不是locations/europe-west1作为该单一注册表,因为 Agent Gateway 和 Discovery Engine 连接器验证都接受global。AGENT_GATEWAY_NAME:网关名称。GE_PROJECT_ID、ENDPOINT_LOCATION、GE_APP_LOCATION和GE_APP_ID:您的 Gemini Enterprise 项目 ID、API 端点前缀(global、us或eu)、应用位置和应用 ID。
选择让自定义连接器使用跨项目网关出站流量
使用
:setUpDataConnector为网关项目的智能体注册表中的资源创建自定义 MCP 数据连接器时,请在actionConfig.actionParams中将use_agent_gateway_egress设置为true:"actionConfig": { "isActionConfigured": true, "createBapConnection": true, "actionParams": { "auth_type": "NO_AUTH", "instance_uri": "MCP_SERVER_URL", "mcp_server_source": "REGISTRY_MCP", "registry_mcp_server_name": "projects/AGENT_GATEWAY_PROJECT_ID/locations/REGISTRY_LOCATION/mcpServers/MCP_SERVER_ID", "use_agent_gateway_egress": true, "agent_gateway_engine": "projects/GE_PROJECT_ID/locations/GE_APP_LOCATION/collections/default_collection/engines/GE_APP_ID" } }
将
MCP_SERVER_URL、REGISTRY_LOCATION(与网关的单个注册表匹配:us-central1对应global和us应用;global对应eu应用,以同时满足 Agent Gateway 和 Discovery Engine 连接器验证)以及MCP_SERVER_ID替换为网关项目的 Agent Registry 中目标资源的值。 在:setUpDataConnector期间设置agent_gateway_engine会自动将创建的数据存储区关联到该 Gemini Enterprise 应用。如需在已关联的连接器上启用网关出站流量,请调用PATCH .../dataConnector?updateMask=actionConfig.actionParams,并将use_agent_gateway_egress设置为true;更新会保留现有的mcp_server_source和registry_mcp_server_name,并且不会将连接器重新关联到其他应用。如需查看完整的导入说明,请参阅从 Agent Registry 导入 MCP 服务器和从 Agent Registry 导入 A2A 智能体。
验证跨项目绑定和流量
验证跨项目应用绑定
检查 Gemini Enterprise 应用,并确认
agentGatewaySetting.defaultEgressAgentGateway.name引用了网关项目中的网关:curl -sS -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "X-Goog-User-Project: GE_PROJECT_ID" \ "https://ENDPOINT_LOCATION-discoveryengine.googleapis.com/v1/projects/GE_PROJECT_NUMBER/locations/GE_APP_LOCATION/collections/default_collection/engines/GE_APP_ID" \ | jq '{name: .name, displayName: .displayName, agentGatewaySetting: .agentGatewaySetting}'
验证已恢复的网关注册表
确认
registries已填充到中央网关:curl -sS -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "X-Goog-User-Project: AGENT_GATEWAY_PROJECT_ID" \ "https://networkservices.googleapis.com/v1/projects/AGENT_GATEWAY_PROJECT_ID/locations/AGENT_GATEWAY_REGION/agentGateways/AGENT_GATEWAY_NAME" \ | jq '{name: .name, registries: .registries}'
验证跨项目出站流量
打开 Gemini Enterprise Web 应用,发送调用导入的工具或代理的查询,然后在网关项目中查看 Agent Gateway 请求日志:
gcloud logging read \ 'logName:"networkservices.googleapis.com%2Fgateway_requests"' \ --project="AGENT_GATEWAY_PROJECT_ID" \ --freshness="30m" \ --limit=10 \ --format="table(timestamp,httpRequest.status,jsonPayload.agentGatewayInfo.mcpInfo.method,jsonPayload.authzPolicyInfo.result)"
确认请求返回 HTTP
200且authzPolicyInfo.result为ALLOWED。
排查跨项目绑定问题
| 症状 | 原因 | 解决方法 |
|---|---|---|
UpdateEngine 失败,并显示 HTTP 400 FAILED_PRECONDITION。 |
网关在关联时已列出跨项目注册表。 | 清除网关上的 registries,调用 UpdateEngine 绑定应用,然后恢复 registries。 |
网关绑定或注册表发现失败,并显示 HTTP 403。 |
Discovery Engine 服务代理在网关项目中缺少 roles/networkservices.viewer、roles/agentregistry.viewer 或 networkservices.agentGateways.use。 |
在网关项目中,向 service-GE_PROJECT_NUMBER@gcp-sa-discoveryengine. 授予第 1 步中的角色,然后等待 60 秒。 |
网关日志在查询时显示 HTTP 403。 |
网关的授权政策或 IAP UAP 未授权跨项目 Workload Identity Gemini Enterprise 工作负载身份主账号集。 | 在网关政策或 UAP 中向 principalSet://agents.global.org-ORGANIZATION_ID.system.id.goog/attribute.platformContainer/discoveryengine/projects/GE_PROJECT_NUMBER 授权。 |
限制 Gemini Enterprise 仅绑定到已获批准的 Agent Gateway
您可以创建自定义组织政策限制条件,以限制 Gemini Enterprise 应用是否可以绑定到任何或所有 Agent Gateway。
创建自定义组织政策限制条件
此示例创建了一个自定义限制条件,用于阻止 Gemini Enterprise 应用与 Agent Gateway 之间的所有绑定。
代理到任意目的地
如需为“代理到任意位置”模式(出站流量)定义自定义限制条件,请创建一个名为
constraint-agent-gateway-egress.yaml的文件。以下示例展示了如何通过禁止任何绑定来强制执行严格的网络隔离。
condition字段指定,如果指定了 Agent Gateway 资源(字段存在且不为空),则操作会被拒绝。name: organizations/ORGANIZATION_ID/customConstraints/custom.disallowGeminiEnterpriseAgentGatewayBinding resource_types:
- discoveryengine.googleapis.com/Engine condition: >- has(resource.agentGatewaySetting.defaultEgressAgentGateway.name) && resource.agentGatewaySetting.defaultEgressAgentGateway.name != '' actionType: DENY displayName: "Disallow all Agent Gateway Bindings for Discovery Engines" description: "To enforce strict network isolation, Discovery Engines are not permitted to bind to any Agent Gateway."
- ORGANIZATION_ID:您的组织 ID。
- PROJECT_ID:您的项目 ID。
- REGION:在其中创建网关的区域。
- AGENT_GATEWAY_NAME:您的网关名称。
应用自定义限制条件。
gcloud org-policies set-custom-constraint EGRESS_CONSTRAINT_PATH
将 EGRESS_CONSTRAINT_PATH 替换为上一步中创建的自定义限制条件文件的完整路径。
创建组织政策以强制执行限制条件。如需定义组织政策,请创建一个名为
policy-agent-gateway-egress.yaml的政策 YAML 文件。在此示例中,我们在项目级层强制执行此限制条件,但您也可以在组织或文件夹级层设置此限制条件。name: projects/PROJECT_ID/policies/custom.disallowGeminiEnterpriseAgentGatewayBinding spec: rules:
- enforce: true
强制执行组织政策。
gcloud org-policies set-policy EGRESS_POLICY_PATH
将 EGRESS_POLICY_PATH 替换为上一步中创建的组织政策 YAML 文件的完整路径。该政策最长需要 15 分钟才能生效。
替换以下内容:
将 PROJECT_ID 替换为您的项目 ID。
如需详细了解如何使用自定义组织政策限制条件,请参阅创建自定义限制条件。
后续步骤
Codelab:使用 Agent Platform 治理智能体工作负载
了解如何在 Gemini Enterprise Agent Platform 上使用 Agent Gateway 治理智能体工作负载。