透過 Agent Gateway 轉送 Gemini Enterprise 流量

本頁說明如何透過 Agent Gateway 轉送 Gemini Enterprise 流量。Agent Gateway 是 Gemini Enterprise Agent Platform 生態系統的核心網路和安全元件,無論是代理與工具之間,還是代理與代理之間的互動,都能安全且受控管地連線。

事前準備

  • 請務必熟悉 Gemini Enterprise 概念。
  • 瞭解 Agent Gateway。請注意,Agent Gateway 僅支援 Gemini Enterprise 的「代理到任何位置」(輸出) 模式。不支援輸入流量。
  • 部署 Gemini Enterprise 應用程式 (也稱為引擎)。本頁程序假設您已部署應用程式。詳情請參閱「建立應用程式」。

規劃位置和 Agent Registry 對應

部署 Agent Gateway 之前,請先選擇要部署閘道的區域,以及要註冊資源的 Agent Registry。請注意下列要求:

  • 位置對應:在與 Gemini Enterprise 應用程式位置對應的特定區域部署 Agent Gateway,確保路由正確。

  • 登錄檔對應:將 Agent Gateway 與位於相同專案和區域的區域 Agent Registry 執行個體建立關聯。如需部署模式的詳細指南,請參閱「規劃 Agent Gateway 部署作業」。

表:Gemini Enterprise 應用程式位置和 Agent Registry 對應關係
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 流量

閘道會將應用程式的查詢時間流量轉送至下列資源:

閘道不會轉送下列流量:

  • 透過網址連線至自訂 MCP 伺服器的流量,不使用 Agent Gateway 虛擬私有雲輸出。
  • 傳送至 A2A 代理的流量,但這些代理並非從 Agent Registry 匯入。
  • 生成式模型推論呼叫、資料儲存庫檢索、內建助理工具,以及連接器擷取流量。

您可以使用授權政策,保護閘道轉送的流量。

如要透過 Agent Gateway 轉送 Gemini Enterprise 流量,請按照下列步驟操作:

  1. 建立 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"
      ]
    }
    
  2. 使用 UpdateEngine API 將閘道繫結至 Gemini Enterprise 應用程式。請注意,完成這個步驟後,所有現有的代理流量會立即透過指定的 Agent Gateway 轉送。

    控制台

    1. 前往 Google Cloud 控制台的「Gemini Enterprise」頁面。

      Gemini Enterprise

    2. 按一下要與 Agent Gateway 建立關聯的應用程式名稱。

    3. 點按「安全性」。

    4. 在「Configuration」(設定) 分頁的「Agent Gateway configuration」(Agent Gateway 設定) 下方,輸入閘道的完整資源名稱。請使用以下格式:projects/PROJECT_ID/locations/LOCATION/agentGateways/AGENT_GATEWAY_NAME。

    5. 按一下「儲存」。

    REST

    1. 使用下列要求更新應用程式。

      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。
    2. 如要驗證應用程式設定,請使用下列指令擷取設定並檢查:

      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"
        }
      }
      }
      
  3. 雖然 Gemini Enterprise 應用程式已啟用輸出管理功能,但不會自動得知可與代理登錄檔中的哪些外部資源互動。

    您必須明確將所選代理、端點和 MCP 伺服器匯入 Gemini Enterprise 應用程式。匯入的資源必須使用確切的註冊資源名稱參照。如需操作說明,請參閱下列指南:

  4. 如要確認輸出功能是否正常運作,請按照下列步驟操作:

    1. 開啟 Gemini Enterprise 網頁應用程式。
    2. 提交查詢,觸發外部工具 (例如「提供 GitHub 最近的問題清單」)。
    3. 監控執行作業,確保成功擷取回應。在幕後,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」。

設定跨專案繫結

  1. 在閘道專案中授予跨專案 Identity and Access Management (IAM) 角色

    授予 Gemini Enterprise 專案的 Discovery Engine 服務代理權限,以便讀取及繫結至閘道及其 Agent Registry (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.iam.gserviceaccount.com" \
     --role="roles/networkservices.viewer"
    
    gcloud projects add-iam-policy-binding "AGENT_GATEWAY_PROJECT_ID" \
     --member="serviceAccount:service-GE_PROJECT_NUMBER@gcp-sa-discoveryengine.iam.gserviceaccount.com" \
     --role="roles/compute.networkUser"
    
    gcloud projects add-iam-policy-binding "AGENT_GATEWAY_PROJECT_ID" \
     --member="serviceAccount:service-GE_PROJECT_NUMBER@gcp-sa-discoveryengine.iam.gserviceaccount.com" \
     --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 統一存取政策 (UAP) 中,使用 iap.googleapis.com/resources.egressViaIAP 授權這個主體集 (或為舊版 V1 政策授予 roles/iap.egressor)。請參閱「建立 IAM 代理政策」和「使用 Service Extensions 委派授權」。

    請等待約 60 秒,讓 IAM 變更生效,再繼續操作。

  2. 將 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 執行個體的區域 (global 或 us 應用程式為 us-central1;eu 應用程式為 europe-west1,如「規劃位置和 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。
  3. 選擇將自訂連接器用於跨專案閘道輸出

    使用 :setUpDataConnector 為閘道專案 Agent Registry 中的資源建立自訂 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 代理」。

驗證跨專案繫結和流量

  1. 驗證跨專案應用程式繫結

    檢查 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}'
  2. 驗證還原的閘道登錄檔

    確認中央閘道已填入 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}'
  3. 驗證跨專案輸出流量

    開啟 Gemini Enterprise 網頁應用程式,傳送查詢來叫用匯入的工具或代理,然後在閘道專案中查看 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。

排解跨專案繫結問題

表格:常見的跨專案 Gemini Enterprise 繫結問題
問題 原因 解析度
UpdateEngine 失敗,並傳回 HTTP 400 FAILED_PRECONDITION。 連結時,閘道已列出跨專案儲存庫。 清除閘道上的 registries,呼叫 UpdateEngine 繫結應用程式,然後還原 registries。
閘道繫結或登錄檔探索失敗,並顯示 HTTP 403。 Discovery Engine 服務代理缺少閘道專案的 roles/networkservices.viewer、roles/agentregistry.viewer 或 networkservices.agentGateways.use。 將步驟 1 的角色授予閘道專案中的 service-GE_PROJECT_NUMBER@gcp-sa-discoveryengine.iam.gserviceaccount.com,並等待 60 秒。
查詢時,閘道記錄顯示 HTTP 403。 閘道的授權政策或 IAP UAP 未授權跨專案 Gemini Enterprise Workload Identity 主體集。 在閘道政策或 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 之間的所有繫結。

代理至任意目的地

  1. 如要為「代理到任何位置」模式 (輸出) 定義自訂限制,請建立名為 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."
  2. 更改下列內容:

    • ORGANIZATION_ID:組織 ID。
    • PROJECT_ID:您的專案 ID。
    • REGION:建立閘道的區域。
    • AGENT_GATEWAY_NAME:閘道名稱。
  3. 套用自訂限制。

    gcloud org-policies set-custom-constraint EGRESS_CONSTRAINT_PATH
    

    將 EGRESS_CONSTRAINT_PATH 替換為上一個步驟中建立的自訂限制檔案完整路徑。

  4. 建立組織政策,強制執行限制。如要定義組織政策,請建立名為 policy-agent-gateway-egress.yaml 的政策 YAML 檔案。在本範例中,我們會在專案層級強制執行這項限制,但您也可以在組織或資料夾層級設定。

    name: projects/PROJECT_ID/policies/custom.disallowGeminiEnterpriseAgentGatewayBinding
    spec:
    rules:

    • enforce: true
  5. 將 PROJECT_ID 替換為專案 ID。

  6. 強制執行組織政策。

    gcloud org-policies set-policy EGRESS_POLICY_PATH
    

    請將 EGRESS_POLICY_PATH 替換為上一步建立的組織政策 YAML 檔案完整路徑。政策最多需要 15 分鐘才會生效。

如要進一步瞭解如何使用自訂組織政策限制,請參閱「建立自訂限制」。

後續步驟

程式碼實驗室

瞭解如何透過 Gemini Enterprise Agent Platform 的 Agent Gateway 控管代理工作負載。

指南

瞭解如何將 Agent Gateway 的授權委派給 IAP、Model Armor 或自訂授權服務。

指南

瞭解如何查看、更新、取消關聯及刪除 Agent Gateway 資源。

指南

瞭解如何監控 Agent Gateway。

疑難排解

瞭解如何排解 Agent Gateway 連線問題。