將 Gemini Enterprise 代理程式與 Google Workspace 整合

1. 事前準備

7zN3mxxU73oY8Gi.png

什麼是 Gemini Enterprise?

Gemini Enterprise 是進階代理平台,可讓全體員工在各種工作流程中,充分運用 Google AI 的優勢。團隊可在單一的安全環境中探索、建立、分享及執行 AI 代理。

  • 使用進階模型:使用者可立即使用 Google 最強大的多模態 AI (包括 Gemini),解決複雜的業務難題。
  • 運用專用代理:套件包含 Google 提供的現成代理,可用於研究、編寫程式碼和記筆記,立即發揮效益。
  • 賦能每位員工:提供無程式碼和專業程式碼選項,讓各部門員工都能建構及管理自訂代理,自動執行工作流程。
  • 資料代理:代理可安全連結至公司內部資料和第三方應用程式,確保回覆內容符合情境且準確。
  • 集中管理:管理員可以查看及稽核所有代理活動,確保組織符合嚴格的安全性和法規遵循標準。
  • 透過生態系統擴充:平台與廣大的合作夥伴應用程式和服務供應商網路整合,可將自動化功能擴充至不同系統。

127f2ed7d484722c.png

什麼是 Google Workspace?

Google Workspace 是一套雲端式效率提升與協作解決方案,專為個人、學校和企業設計:

  • 通訊:專業電子郵件服務 (Gmail)、視訊會議 (Meet) 和團隊訊息 (Chat)。
  • 內容創作:用於撰寫文件 (Google 文件)、建立試算表 (Google 試算表) 和設計簡報 (Google 簡報) 的工具。
  • 整理:共用日曆 (Google 日曆) 和數位筆記 (Google Keep)。
  • 儲存空間:集中式雲端空間,可安全儲存及共用檔案 (雲端硬碟)。
  • 管理:Workspace 管理控制台提供管理控制項,可管理使用者和安全性設定。

有哪些自訂整合功能?

Google Workspace 和 Gemini Enterprise 形成強大的意見回饋循環,Workspace 提供即時資料和協作情境,Gemini Enterprise 則提供模型、代理推論和自動化智慧工作流程所需的協調機制。

  • 智慧連線能力:Google 代管的資料儲存庫、API 和 MCP 伺服器 (Google 代管和自訂),可讓代理安全順暢地存取 Workspace 資料,並代表使用者採取行動。
  • 自訂代理:團隊可使用無程式碼設計工具或專業程式碼架構,建構專用代理,並以管理員控管的 Workspace 資料和動作為基準。
  • 原生整合:Workspace 外掛程式可透過專屬 UI 元件或背景程序,在 AI 系統與 Chat 和 Gmail 等應用程式之間架起橋梁。這樣一來,代理就能根據使用者的實際情況,提供即時且符合情境的協助。

Google Workspace 具備強大的生產力生態系統,Gemini Enterprise 則提供先進的代理功能,兩者結合後,組織就能透過自訂且以資料為依據的 AI 代理,直接在團隊日常使用的工具中自動執行複雜的工作流程,進而翻轉營運模式。

必要條件

如要在自己的環境中完成所有步驟,您需要:

建構目標

在本程式碼實驗室中,我們將建構三種解決方案,並將 Gemini Enterprise AI 代理與 Google Workspace 緊密整合。他們會示範可用於與資料、動作和 UI 互動的架構模式。

無程式碼自訂代理

使用者可以透過這個代理,以自然語言搜尋資料及執行 Workspace 動作。這項功能仰賴下列元素:

  • 模型:Gemini。
  • 資料和動作:Google Workspace (日曆、Gmail、雲端硬碟、NotebookLM) 的 Gemini Enterprise 資料儲存庫、Google 搜尋。
  • 代理建構工具:Gemini Enterprise Agent Designer。
  • 代理主機:Gemini Enterprise。
  • 使用者介面:Gemini Enterprise 網頁應用程式。

90e42539e5959634.png60e62437ce29a818.png

Pro-code 自訂代理

使用者可以透過這個代理,使用自訂工具和規則,以自然語言搜尋資料及執行 Workspace 動作。這項功能仰賴下列元素:

  • 模型:Gemini。
  • 資料和動作:Gemini Enterprise 資料儲存庫,適用於 Google Workspace (日曆、Gmail、雲端硬碟、NotebookLM)、Google 搜尋、Google 代管的 Agent Search Model Context Protocol (MCP) 伺服器、自訂工具函式,用於傳送 Google Chat 即時通訊訊息 (透過 Google Chat API)。
  • 代理建構工具:Agent Development Kit (ADK)。
  • 代理主機:Agent Runtime。
  • 使用者介面:Gemini Enterprise 網頁應用程式。

1647ebff031c42e7.pnga8087d2351e77fb4.png

預設代理做為 Google Workspace 外掛程式

使用者可透過這個代理,在 Workspace 應用程式 UI 中,以自然語言搜尋 Workspace 資料。這項功能仰賴下列元素:

  • 模型:Gemini。
  • 資料:Google Workspace (日曆、Gmail、雲端硬碟、NotebookLM) 的 Gemini Enterprise 資料儲存庫、Google 搜尋。
  • 代理主機:Gemini Enterprise。
  • 使用者介面:Chat 和 Gmail 的 Google Workspace 外掛程式 (可輕鬆擴充至日曆、雲端硬碟、文件、試算表和簡報)。
  • Google Workspace 外掛程式:Apps Script、Gemini Enterprise API、情境 (使用者中繼資料、所選 Gmail 郵件)。

c8c63fb3f324fecf.pngd33b8cb50ee251b7.png

學習目標

  • Gemini Enterprise 與 Google Workspace 之間的整合點,可啟用資料和動作。
  • 無程式碼和專業程式碼選項,可建構託管於 Gemini Enterprise 的自訂代理。
  • 使用者可透過 Gemini Enterprise 網頁應用程式和 Google Workspace 應用程式存取代理。

輕鬆存取這個程式碼實驗室

82JGvYaTp8dhuvv.png

2. 做好準備

複習概念

Gemini Enterprise 應用程式

Gemini Enterprise 應用程式可為使用者提供搜尋結果、動作和代理。在 API 的情境中,「應用程式」和「引擎」這兩個詞可以交替使用。應用程式必須連結至資料儲存庫,才能使用其中的資料提供搜尋結果、答案或動作。

Gemini Enterprise 網頁應用程式

Gemini Enterprise 網頁應用程式與 Gemini Enterprise 應用程式相關聯,是集中式的 AI 基地,員工可透過單一對話介面搜尋分散的公司資料、執行專門的 AI 代理來處理複雜的工作流程,以及生成專業級內容,同時享有企業級隱私權。

初始化及存取資源

在本節中,您將透過偏好的網路瀏覽器存取及設定下列資源。

Gemini Enterprise 應用程式

在新分頁中開啟 Google Cloud 控制台,然後按照下列步驟操作:

  1. 選取專案。
  2. 在 Google Cloud 搜尋欄位中,搜尋並選取「Gemini Enterprise」,然後點選「+ 建立應用程式」。如果沒有 Gemini Enterprise 授權,系統會提示您啟用 30 天免費試用授權。

  1. 將「App name」設為 codelab。
  2. 系統會根據名稱產生 ID,並顯示在欄位下方,請複製這個 ID。
  3. 將「多區域」設為 global (Global)。
  4. 點選「建立」。

8712ada39377205e.png

  1. 應用程式建立完成後,系統會自動將您重新導向至「Gemini Enterprise」>「總覽」。
  2. 在「取得完整存取權」下方,按一下「設定身分」。
  3. 在新畫面中,選取「使用 Google Identity」,然後點選「確認員工身分」。

3209c156eff4ba43.png

  1. 系統會儲存設定,並自動將您重新導向至「Gemini Enterprise」>「總覽」。
  2. 前往「Configurations」(設定)。
  3. 在「功能管理」分頁,開啟「啟用代理設計工具」,然後點選「儲存」。

f0cd9da419b41cb6.png

Gemini Enterprise 網頁應用程式

在新分頁中,從 Cloud 控制台開啟 Gemini Enterprise,然後按照下列步驟操作:

  1. 按一下名為 codelab 的應用程式。
  2. 複製顯示的網址,以便在後續步驟中前往 Gemini Enterprise 網頁應用程式。

b46ee6176744565d.png

3. 無程式碼自訂代理

使用者可以透過這個代理,以自然語言搜尋資料及執行 Workspace 動作。這項功能仰賴下列元素:

  • 模型:Gemini。
  • 資料和動作:Google Workspace (日曆、Gmail、雲端硬碟、NotebookLM) 的 Gemini Enterprise 資料儲存庫、Google 搜尋。
  • 代理建構工具:Gemini Enterprise Agent Designer。
  • 代理主機:Gemini Enterprise。
  • 使用者介面:Gemini Enterprise 網頁應用程式。

複習概念

Gemini

Gemini 是 Google 的多模態 LLM。這項技術可協助使用者充分發揮潛力,進而激發想像力、拓展好奇心,並提高工作效率。

Gemini Enterprise 資料儲存庫

Gemini Enterprise 資料儲存庫是一種實體,包含從第一方資料來源 (例如 Google Workspace) 或第三方應用程式 (例如 Jira 或 Salesforce) 擷取的資料。包含第三方應用程式資料的資料儲存庫,也稱為資料連接器。

Gemini Enterprise Agent Designer

Gemini Enterprise Agent Designer 是互動式低程式碼/無程式碼平台,可供您在 Gemini Enterprise 建立、管理和啟動單步驟和多步驟代理。

查看解決方案架構

e77aafb772502aaf.png

啟用 API

如要使用 Gemini Enterprise Workspace 資料儲存庫,必須啟用下列 API:

  1. 在 Google Cloud 控制台中,啟用 Calendar、Gmail 和 People API:

573322606b715a69.png

  1. 依序點選「選單」圖示 ☰ >「API 和服務」>「已啟用的 API 和服務」,然後確認清單中包含「Google 日曆 API」、「Gmail API」和「People API」。

如要使用 Gemini Enterprise Workspace 的日曆和 Gmail 動作,必須設定同意畫面:

  1. 在 Google Cloud 控制台中,依序點選「選單」圖示 ☰ >「Google Auth 平台」>「品牌宣傳」。

  1. 按一下 [開始使用]。
  2. 在「應用程式資訊」部分,將「應用程式名稱」設為 Codelab。
  3. 在「User support email」(使用者支援電子郵件) 中,選擇支援電子郵件地址,方便使用者在同意聲明方面有任何疑問時與您聯絡。
  4. 點選 [下一步]。
  5. 在「Audience」(目標對象) 下方,選取「Internal」(內部)。
  6. 點選 [下一步]。
  7. 在「Contact Information」(聯絡資訊) 下方,輸入可接收專案異動通知的電子郵件地址。
  8. 點選 [下一步]。
  9. 在「Finish」(完成) 部分,請詳閱《Google API 服務使用者資料政策》,然後選取「我同意《Google API 服務:使用者資料政策》」。
  10. 依序點選「繼續」和「建立」。

578c2b38219b2f7b.png

  1. 系統會儲存設定,並自動將您重新導向至「Google Auth Platform」>「Overview」。
  2. 前往「資料存取權」。
  3. 按一下「新增或移除範圍」。
  4. 複製下列範圍,並貼到「手動新增範圍」欄位。
https://www.googleapis.com/auth/calendar.readonly
https://www.googleapis.com/auth/calendar.events
https://www.googleapis.com/auth/calendar.calendars
https://www.googleapis.com/auth/gmail.send
https://www.googleapis.com/auth/gmail.readonly
  1. 依序點選「新增至表格」、「更新」和「儲存」。

874b1dda14e8f379.png

詳情請參閱「設定 OAuth 同意畫面」完整指南。

建立 OAuth 用戶端憑證

為 Gemini Enterprise 建立新的 OAuth 用戶端,以便驗證使用者:

  1. 在 Google Cloud 控制台中,依序點選「選單」圖示 ☰ >「Google Auth 平台」>「用戶端」。

  1. 按一下「+ 建立用戶端」。
  2. 「應用程式類型」請選取「網頁應用程式」。
  3. 將「Name」(名稱) 設為 codelab。
  4. 略過「已授權的 JavaScript 來源」。
  5. 在「已授權的重新導向 URI」部分,點選「新增 URI」並輸入 https://vertexaisearch.cloud.google.com/oauth-redirect。
  6. 點選「建立」。
  7. 畫面上會顯示對話方塊,列出新建立的 OAuth 用戶端 ID 和密鑰。請將這項資訊儲存在安全的地方。

a46e5ebfb851aea5.png

建立資料儲存庫

您必須建立資料儲存庫,才能將 Gemini Enterprise 連結至 Workspace 資料。

在新分頁中,從 Cloud 控制台開啟 Gemini Enterprise,然後按照下列步驟操作:

  1. 按一下名為 codelab 的應用程式。
  2. 點按導覽選單中的「連結的資料儲存庫」。
  3. 點選「+ 新增資料儲存庫」。
  4. 在「Source」(來源) 搜尋「Google 日曆」,然後點選「Select」(選取)。
  5. 在「動作」部分,輸入先前步驟儲存的用戶端 ID 和用戶端密鑰,然後點選「確認你的身分」,並按照步驟驗證及授權 OAuth 用戶端。
  6. 啟用「建立日曆活動」和「更新日曆活動」動作。
  7. 按一下「繼續」。

a1d76e70edec0cf.png

  1. 在「設定」部分,將「資料連接器名稱」設為 calendar。
  2. 點選「建立」。
  3. 系統會自動將您重新導向至「連結的資料儲存庫」,您可以在這裡查看新加入的資料儲存庫。

建立 Google Gmail 資料儲存庫:

  1. 點選「+ 新增資料儲存庫」。
  2. 在「Source」(來源) 中搜尋「Google Gmail」,然後按一下「Select」(選取)。
  3. 在「動作」部分,輸入先前步驟儲存的用戶端 ID 和用戶端密鑰,然後點選「確認你的身分」。
  4. 啟用「傳送電子郵件」動作。
  5. 按一下「繼續」。
  6. 在「設定」部分,將「資料連接器名稱」設為 gmail。
  7. 點選「建立」。
  8. 系統會自動將您重新導向至「連結的資料儲存庫」,您可以在這裡查看新加入的資料儲存庫。

建立 Google 雲端硬碟資料儲存庫:

  1. 點選「+ 新增資料儲存庫」。
  2. 在「Source」(來源) 中搜尋「Google Drive」(Google 雲端硬碟),然後按一下「Select」(選取)。
  3. 在「資料」部分,選取「全部」,然後按一下「繼續」。
  4. 在「設定」部分,將「資料連接器名稱」設為 drive。
  5. 點選「建立」。
  6. 系統會自動將您重新導向至「連結的資料儲存庫」,您可以在這裡查看新加入的資料儲存庫。

建立 NotebookLM 資料儲存庫:

  1. 點選「+ 新增資料儲存庫」。
  2. 在「Source」(來源) 中搜尋「NotebookLM」,然後按一下「Select」(選取)。
  3. 在「設定」部分,將「資料連接器名稱」設為 notebooklm。
  4. 點選「建立」。
  5. 系統會自動將您重新導向至「連結的資料儲存庫」,您可以在這裡查看新加入的資料儲存庫。

幾分鐘後,所有已連結的資料儲存庫 (NotebookLM 除外) 狀態都會顯示為「運作中」。如果看到任何錯誤,可以點選資料來源查看錯誤詳情。

ceba9eb2480a2696.png

測試資料儲存庫

執行一些測試查詢,確認資料儲存庫正確擷取資料。

開啟先前複製的 Gemini Enterprise 網頁應用程式網址:

  1. 依序點選「選單」圖示 ☰ >「發起新即時通訊」。
  2. 在新的即時通訊訊息欄位頁尾,點選「連接器」圖示,然後啟用所有連接器。
  3. 現在可以嘗試與連接器相關的提示。例如,在對話中輸入 Do I have any meetings today?,然後按下 enter 鍵。
  4. 接著,請試著輸入 How many emails did I receive today?,然後按下 enter 鍵。
  5. 最後,輸入 Give me the title of the last Drive file I created 並按下 enter 鍵。

90e42539e5959634.png

建立自訂代理

在 Gemini Enterprise 網頁應用程式中,使用 Agent Designer 建立新代理:

  1. 依序點選「選單」圖示 ☰ >「+ 新增代理」。
  2. 在對話中輸入 An agent that always sends pirate-themed emails but use normal English otherwise,然後按下 enter 鍵。

2803c1dedd20433e.png

  1. Agent Designer 會根據提示詞草擬代理,並在編輯器中開啟。
  2. 按一下「Create」(建立)

試用自訂代理

測試新代理,看看它如何回答問題及執行動作。

  1. 在 Gemini Enterprise 網頁應用程式中,與新建立的代理對話:
  2. 依序點選「選單」圖示 ☰ >「代理」。
  3. 在「您的代理」下方選取代理。
  4. 在新的即時通訊訊息欄位頁尾,點選「連接器」圖示,然後點選「郵件」的「啟用動作」,並按照指示授權代理
  5. 在對話中輸入 Send an email to someone@example.com saying I'll see them at Cloud Next, generate some subject and body yourself,然後按下 enter 鍵。您可以將範例電子郵件地址替換為自己的電子郵件地址。
  6. 按一下 ✔️ 即可傳送電子郵件。

60e62437ce29a818.pngd4fb65d14fdf27da.png

4. Pro-code 自訂代理

使用者可以透過這個代理,使用自訂工具和規則,以自然語言搜尋資料及執行 Workspace 動作。這項功能仰賴下列元素:

  • 模型:Gemini。
  • 資料和動作:Gemini Enterprise 資料儲存庫,適用於 Google Workspace (日曆、Gmail、雲端硬碟、NotebookLM)、Google 搜尋、Google 代管的 Agent Search Model Context Protocol (MCP) 伺服器、自訂工具函式,用於傳送 Google Chat 即時通訊訊息 (透過 Google Chat API)。
  • 代理建構工具:Agent Development Kit (ADK)。
  • 代理主機:Agent Runtime。
  • 使用者介面:Gemini Enterprise 網頁應用程式。

我們會使用自備功能,將其整合至 Gemini Enterprise,因此需要完成部署、註冊和設定步驟。

複習概念

Gemini Enterprise Agent Platform

Gemini Enterprise Agent Platform (原稱 Vertex AI) 是開放式的全方位平台,可協助企業快速建構、擴充、管理及最佳化調整企業級代理,並以自家企業資料為基準。

4670fcf7a826af4d.png

Agent Development Kit (ADK)

Agent Development Kit (ADK) 是一套專門的工具和框架,提供預先建構的推論、記憶體管理和工具整合模組,可簡化自主 AI 代理的建立程序。

Model Context Protocol (MCP)

Model Context Protocol (MCP) 是一項開放標準,旨在透過通用的「隨插即用」介面,在 AI 應用程式與各種資料來源或工具之間,實現流暢、安全的整合。

函式工具

函式工具是預先定義的可執行常式,AI 模型可觸發這類工具來執行特定動作,或從外部系統擷取即時資料,擴充功能,不限於生成文字。

查看解決方案架構

43df337e0f3d64e8.png

查看原始碼

agent.py

下列程式碼會向 Gemini Enterprise 驗證、初始化 Agent Search MCP 和 Chat API 工具,並定義代理的行為。

  1. 驗證:使用輔助函式 _get_access_token_from_context 擷取 Gemini Enterprise 插入的驗證權杖 (CLIENT_AUTH_NAME)。這個權杖非常重要,可確保安全呼叫 Agent Search MCP 和 Google Chat 工具等下游服務。
  2. 設定工具:初始化 vertexai_mcp (連至 Agent Search Model Context Protocol (MCP) 伺服器的工具集) 和 send_direct_message 工具。這樣一來,代理就能搜尋連結的資料儲存庫,並傳送 Google Chat 即時通訊訊息。
  3. 代理定義:使用 gemini-2.5-flash 模型定義 root_agent。指令會指示代理優先使用搜尋工具進行資訊檢索,並使用 send_direct_message 工具執行動作,有效以企業資料為基準。
...
MODEL = "gemini-2.5-flash"

# Gemini Enterprise authentication injects a bearer token into the ToolContext state.
# The key pattern is "CLIENT_AUTH_NAME_<random_digits>".
# We dynamically parse this token to authenticate our MCP and API calls.
CLIENT_AUTH_NAME = "enterprise-ai"

VERTEXAI_SEARCH_TIMEOUT = 15.0

def get_project_id():
    """Fetches the consumer project ID from the environment natively."""
    _, project = google.auth.default()
    if project:
        return project
    raise Exception(f"Failed to resolve GCP Project ID from environment.")

def find_serving_config_path():
    """Dynamically finds the default serving config in the engine."""
    project_id = get_project_id()
    engines = discoveryengine_v1.EngineServiceClient().list_engines(
        parent=f"projects/{project_id}/locations/global/collections/default_collection"
    )
    for engine in engines:
        # engine.name natively contains the numeric Project Number
        return f"{engine.name}/servingConfigs/default_serving_config"
    raise Exception(f"No Discovery Engines found in project {project_id}")

def _get_access_token_from_context(tool_context: ToolContext) -> str:
    """Helper method to dynamically parse the intercepted bearer token from the context state."""
    escaped_name = re.escape(CLIENT_AUTH_NAME)
    pattern = re.compile(fr"^{escaped_name}_\d+$")
    # Handle ADK varying state object types (Raw Dict vs ADK State)
    state_dict = tool_context.state.to_dict() if hasattr(tool_context.state, 'to_dict') else tool_context.state
    matching_keys = [k for k in state_dict.keys() if pattern.match(k)]
    if matching_keys:
        return state_dict.get(matching_keys[0])
    raise Exception(f"No bearer token found in ToolContext state matching pattern {pattern.pattern}")

def auth_header_provider(tool_context: ToolContext) -> dict[str, str]:
    token = _get_access_token_from_context(tool_context)
    return {"Authorization": f"Bearer {token}"}

def send_direct_message(email: str, message: str, tool_context: ToolContext) -> dict:
    """Sends a Google Chat Direct Message (DM) to a specific user by email address."""
    chat_client = chat_v1.ChatServiceClient(
        credentials=Credentials(token=_get_access_token_from_context(tool_context))
    )

    # 1. Setup the DM space or find existing one
    person = chat_v1.User(
        name=f"users/{email}",
        type_=chat_v1.User.Type.HUMAN
    )
    membership = chat_v1.Membership(member=person)
    space_req = chat_v1.Space(space_type=chat_v1.Space.SpaceType.DIRECT_MESSAGE)
    setup_request = chat_v1.SetUpSpaceRequest(
        space=space_req,
        memberships=[membership]
    )
    space_response = chat_client.set_up_space(request=setup_request)
    space_name = space_response.name
    
    # 2. Send the message
    msg = chat_v1.Message(text=message)
    message_request = chat_v1.CreateMessageRequest(
        parent=space_name,
        message=msg
    )
    message_response = chat_client.create_message(request=message_request)
    
    return {"status": "success", "message_id": message_response.name, "space": space_name}

agentsearch_mcp = McpToolset(
    connection_params=StreamableHTTPConnectionParams(
        url="https://discoveryengine.googleapis.com/mcp",
        timeout=VERTEXAI_SEARCH_TIMEOUT,
        sse_read_timeout=VERTEXAI_SEARCH_TIMEOUT
    ),
    tool_filter=['search'],
    # The auth_header_provider dynamically injects the bearer token from the ToolContext
    # into the MCP call for authentication.
    header_provider=auth_header_provider
)

# Answer nicely the following user queries:
#  - Please find my meetings for today, I need their titles and links
#  - What is the latest Drive file I created?
#  - What is the latest Gmail message I received?
#  - Please send the following message to someone@example.com: Hello, this is a test message.

root_agent = LlmAgent(
    model=MODEL,
    name='enterprise_ai',
    instruction=f"""
        You are a helpful assistant that always uses the MCP search tool to answer the user's message, unless the user asks you to send a message to someone.
        If the user asks you to send a message to someone, use the send_direct_message tool to send the message.
        You MUST unconditionally use the MCP search tool to find answer, even if you believe you already know the answer or believe the MCP search tool does not contain the data.
        The MCP search tool accesses the user's data through datastores including Google Drive, Google Calendar, and Gmail.
        Only use the MCP search tool with servingConfig and query parameters, do not use any other parameters.
        Always use the servingConfig {find_serving_config_path()} while using the MCP search tool.
    """,
    tools=[agentsearch_mcp, FunctionTool(send_direct_message)]
)

啟用 API

這項解決方案需要啟用其他 API:

  1. 在 Google Cloud 控制台中,啟用 Agent Platform、Cloud Resource Manager 和 Google Chat API:

4f02a36b050bab00.png

  1. 依序點選「選單」圖示 ☰ >「API 和服務」>「已啟用的 API 和服務」,然後確認清單中包含「Vertex AI API」、「Cloud Resource Manager API」和「Google Chat API」。

解決方案需要額外的資料存取權:

  1. 在 Google Cloud 控制台中,依序點選「選單」圖示 ☰ >「Google Auth 平台」>「資料存取」。

  1. 按一下「新增或移除範圍」。
  2. 複製下列範圍,並貼到「手動新增範圍」欄位。
  3. 依序點選「新增至表格」、「更新」和「儲存」。
https://www.googleapis.com/auth/cloud-platform
https://www.googleapis.com/auth/chat.messages.create
https://www.googleapis.com/auth/chat.spaces.create
  1. 依序點選「新增至表格」、「更新」和「儲存」。

56fbba733139acfe.png

更新 OAuth 用戶端憑證

解決方案需要額外的授權重新導向 URI:

  1. 在 Google Cloud 控制台中,依序點選「選單」圖示 ☰ >「Google Auth 平台」>「用戶端」。

  1. 按一下客戶名稱 codelab。
  2. 在「已授權的重新導向 URI」部分,點選「新增 URI」,然後輸入 https://vertexaisearch.cloud.google.com/static/oauth/oauth.html。
  3. 按一下「儲存」。

deed597aa54fec91.png

啟用 Agent Search MCP

  1. 在終端機中執行:
gcloud beta services mcp enable discoveryengine.googleapis.com \
     --project=$(gcloud config get-value project)

設定 Chat 應用程式

設定 Google Chat 應用程式的基本資訊。

  1. 在 Google Cloud 控制台的搜尋欄位中搜尋 Google Chat API,然後依序點選「Google Chat API」、「管理」和「設定」。

  1. 將「應用程式名稱」和「說明」設為 Gemini Enterprise。
  2. 將「Avatar URL」設為 https://developers.google.com/workspace/add-ons/images/quickstart-app-avatar.png。
  3. 取消選取「啟用互動功能」,然後在顯示的互動視窗對話方塊中按一下「停用」。
  4. 選取「將錯誤記錄至 Logging」。
  5. 按一下「儲存」。

90cb612e51bce4e6.png

在 Agent Runtime 部署代理

將代理部署至 Agent Runtime 基礎架構。

  1. 下載這個 GitHub 存放區。

  1. 在終端機中開啟 solutions/enterprise-ai-agent 目錄,然後執行:
# 1. Create and activate a new virtual environment
python3 -m venv .venv
source .venv/bin/activate

# 2. Install poetry and project dependencies
pip install poetry
poetry install

# 3. Deploy the agent
adk deploy agent_engine \
  --project=$(gcloud config get-value project) \
  --region=us-central1 \
  --display_name="Enterprise AI" \
  enterprise_ai

eafd2f9c4fbf305.png

  1. 在記錄中看到「Deploying to agent runtime...」這行時,請開啟新的終端機,並執行下列指令,將必要權限新增至 Vertex AI Reasoning Engine 服務代理:
# 1. Get the current Project ID
PROJECT_ID=$(gcloud config get-value project)

# 2. Extract the Project Number for that ID
PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format='value(projectNumber)')

# 3. Construct the Service Account name
SERVICE_ACCOUNT="service-${PROJECT_NUMBER}@gcp-sa-aiplatform-re.iam.gserviceaccount.com"

# 4. Apply the IAM policy binding
gcloud projects add-iam-policy-binding $PROJECT_ID \
     --member="serviceAccount:$SERVICE_ACCOUNT" \
     --role="roles/discoveryengine.viewer"
  1. 等待 adk deploy 指令執行完畢,然後從綠色的指令輸出內容,複製新部署代理的資源名稱。

d098fe1347d6581b.png

在 Gemini Enterprise 註冊代理

將部署的代理註冊至 Gemini Enterprise,使用者就能存取。

在新分頁中,從 Cloud 控制台開啟 Gemini Enterprise,然後按照下列步驟操作:

  1. 按一下名為 codelab 的應用程式。
  2. 在導覽選單中,點選「代理」。
  3. 點選「+ 新增代理」。
  4. 在「透過 Agent Runtime 建立的自訂代理」部分,點選「新增」。系統隨即會顯示「授權」部分。
  5. 按一下「新增授權」。
  6. 將「Authorization name」(授權名稱) 設為 enterprise-ai。系統會根據名稱產生 ID,並顯示在欄位下方,請複製這個 ID。
  7. 將「Client ID」(用戶端 ID) 設為與先前步驟中建立及更新的 OAuth 用戶端相同的值。
  8. 將「Client secret」(用戶端密鑰) 設為與先前步驟中建立及更新的 OAuth 用戶端相同的值。
  9. 將「Token URI」設為 https://oauth2.googleapis.com/token。
  10. 將 <CLIENT_ID> 替換為先前步驟中建立及更新的 OAuth 用戶端 ID,然後將「Authorization URI」設為下列值。
https://accounts.google.com/o/oauth2/v2/auth?client_id=<CLIENT_ID>&redirect_uri=https%3A%2F%2Fvertexaisearch.cloud.google.com%2Fstatic%2Foauth%2Foauth.html&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar.calendars%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar.events%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.send%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fchat.messages.create%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fchat.spaces.create&include_granted_scopes=true&response_type=code&access_type=offline&prompt=consent
  1. 依序點選「完成」和「下一步」。系統會顯示「Configuration」(設定) 區段。
  2. 將「代理名稱」和「代理說明」設為 Enterprise AI。
  3. 將「Agent Runtime 推論引擎」設為先前步驟複製的推論引擎資源名稱。格式如下:
projects/<PROJECT_ID>/locations/<LOCATION>/reasoningEngines/<REASONING_ENGINE_ID>
  1. 按一下「建立」,新加入的代理會列在「代理」下方。

試用代理

與自訂代理對話,驗證流程。

  1. 在 Gemini Enterprise 網頁應用程式中,與新註冊的代理對話:
  2. 依序點選「選單」圖示 ☰ >「代理」。
  3. 在「貴組織」下方選取代理。
  4. 在對話中輸入 Please find my meetings for today, I need their titles and links,然後按下 enter 鍵。
  5. 按一下「授權」,然後按照授權流程操作。

ed61cf654cbcd76c.png

  1. 代理會根據使用者帳戶,回覆日曆活動清單。
  2. 在對話中輸入 Please send a Chat message to someone@example.com with the following text: Hello!,然後按下 enter 鍵。
  3. 代理會回覆確認訊息。

1647ebff031c42e7.pnga8087d2351e77fb4.png

5. 預設代理做為 Google Workspace 外掛程式

使用者可以透過 Workspace 應用程式 UI,使用自然語言搜尋 Workspace 資料。這項功能仰賴下列元素:

  • 模型:Gemini。
  • 資料:Google Workspace (日曆、Gmail、雲端硬碟、NotebookLM) 的 Gemini Enterprise 資料儲存庫、Google 搜尋。
  • 代理主機:Gemini Enterprise。
  • 使用者介面:Chat 和 Gmail 的 Google Workspace 外掛程式 (可輕鬆擴充至日曆、雲端硬碟、文件、試算表和簡報)。
  • Google Workspace 外掛程式:Apps Script、Gemini Enterprise API、情境 (使用者中繼資料、所選 Gmail 郵件)。

Google Workspace 外掛程式會透過 StreamAssist API 連結至 Gemini Enterprise。

複習概念

Google Workspace 外掛程式

Google Workspace 外掛程式是自訂應用程式,可擴充一或多個 Google Workspace 應用程式 (Gmail、Chat、日曆、文件、雲端硬碟、Meet、試算表和簡報)。

Apps Script

Apps Script 是由 Google 雲端硬碟支援的雲端式 JavaScript 平台,可讓您整合及自動執行各項 Google 產品的工作。

Google Workspace 卡片架構

Google Workspace 的資訊卡架構可讓開發人員建立豐富的互動式使用者介面。可讓您建構井然有序且美觀的資訊卡,其中可包含文字、圖片、按鈕和其他小工具。這些資訊卡可提供結構化資訊,並讓使用者直接在 Workspace 應用程式中快速執行操作,提升使用者體驗。

查看解決方案架構

1798c39f7aaed8fc.png

查看原始碼

appsscript.json

下列設定定義了外掛程式的觸發條件和權限。

  1. 定義外掛程式:告知 Google Workspace,這項專案是 Chat 和 Gmail 的外掛程式。
  2. 情境觸發條件:如果是 Gmail,則會設定 contextualTrigger,在使用者開啟電子郵件訊息時觸發 onAddonEvent。這樣外掛程式才能「查看」電子郵件內容。
  3. 權限:列出外掛程式執行所需的oauthScopes,例如讀取目前電子郵件、執行指令碼,以及連線至外部服務 (例如 Gemini Enterprise API) 的權限。
...
"addOns": {
    "common": {
      "name": "Enterprise AI",
      "logoUrl": "https://developers.google.com/workspace/add-ons/images/quickstart-app-avatar.png"
    },
    "chat": {},
    "gmail": {
      "contextualTriggers": [
        {
          "unconditional": {},
          "onTriggerFunction": "onAddonEvent"
        }
      ]
    }
  },
  "oauthScopes": [
    "https://www.googleapis.com/auth/script.external_request",
    "https://www.googleapis.com/auth/discoveryengine.assist.readwrite",
    "https://www.googleapis.com/auth/gmail.addons.execute",
    "https://www.googleapis.com/auth/gmail.addons.current.message.readonly"
  ]
...

Chat.gs

下列程式碼會處理傳入的 Google Chat 即時通訊訊息。

  1. 接收訊息:onMessage 函式是訊息互動的進入點。
  2. 管理情境:將 space.name (Chat 聊天室 ID) 儲存至使用者屬性。這樣一來,當代理準備好回覆時,就能準確知道要將訊息張貼到哪個對話。
  3. 委派給代理:呼叫 requestAgent,將使用者的訊息傳遞至處理 API 通訊的核心邏輯。
...
// Service that handles Google Chat operations.

// Handle incoming Google Chat message events, actions will be taken via Google Chat API calls
function onMessage(event) {
  if (isInDebugMode()) {
    console.log(`MESSAGE event received (Chat): ${JSON.stringify(event)}`);
  }
  // Extract data from the event.
  const chatEvent = event.chat;
  setChatConfig(chatEvent.messagePayload.space.name);

  // Request AI agent to answer the message
  requestAgent(chatEvent.messagePayload.message);
  // Respond with an empty response to the Google Chat platform to acknowledge execution
  return null; 
}

// --- Utility functions ---

// The Chat direct message (DM) space associated with the user
const SPACE_NAME_PROPERTY = "DM_SPACE_NAME"

// Sets the Chat DM space name for subsequent operations.
function setChatConfig(spaceName) {
  const userProperties = PropertiesService.getUserProperties();
  userProperties.setProperty(SPACE_NAME_PROPERTY, spaceName);
  console.log(`Space is set to ${spaceName}`);
}

// Retrieved the Chat DM space name to sent messages to.
function getConfiguredChat() {
  const userProperties = PropertiesService.getUserProperties();
  return userProperties.getProperty(SPACE_NAME_PROPERTY);
}

// Finds the Chat DM space name between the Chat app and the given user.
function findChatAppDm(userName) {
  return Chat.Spaces.findDirectMessage(
    { 'name': userName },
    {'Authorization': `Bearer ${getAddonCredentials().getAccessToken()}`}
  ).name;
}

// Creates a Chat message in the configured space.
function createMessage(message) {
  const spaceName = getConfiguredChat();
  console.log(`Creating message in space ${spaceName}...`);
  return Chat.Spaces.Messages.create(
    message,
    spaceName,
    {},
    {'Authorization': `Bearer ${getAddonCredentials().getAccessToken()}`}
  ).name;
}

Sidebar.gs

下列程式碼會建構 Gmail 側欄,並擷取電子郵件內容。

  1. 建構 UI:createSidebarCard 使用 Workspace Card Service 建構視覺介面。這會建立一個簡單的版面配置,其中包含文字輸入區域和「傳送訊息」按鈕。
  2. 擷取電子郵件內容:在 handleSendMessage 中,程式碼會檢查使用者目前是否正在查看電子郵件 (event.gmail.messageId)。如果是,就會安全擷取電子郵件的主旨和內文,並附加至使用者的提示。
  3. 顯示結果:代理回覆後,程式碼會更新側欄資訊卡,顯示回覆內容。
...
// Service that handles Gmail operations.

// Triggered when the user opens the Gmail Add-on or selects an email.
function onAddonEvent(event) {
  // If this was triggered by a button click, handle it
  if (event.parameters && event.parameters.action === 'send') {
    return handleSendMessage(event);
  }

  // Otherwise, just render the default initial sidebar
  return createSidebarCard();
}

// Creates the standard Gmail sidebar card consisting of a text input and send button.
// Optionally includes an answer section if a response was generated.
function createSidebarCard(optionalAnswerSection) {
  const card = CardService.newCardBuilder();
  const actionSection = CardService.newCardSection();

  // Create text input for the user's message
  const messageInput = CardService.newTextInput()
    .setFieldName("message")
    .setTitle("Message")
    .setMultiline(true);

  // Create action for sending the message
  const sendAction = CardService.newAction()
    .setFunctionName('onAddonEvent')
    .setParameters({ 'action': 'send' });

  const sendButton = CardService.newTextButton()
    .setText("Send message")
    .setTextButtonStyle(CardService.TextButtonStyle.FILLED)
    .setOnClickAction(sendAction);

  actionSection.addWidget(messageInput);
  actionSection.addWidget(CardService.newButtonSet().addButton(sendButton));

  card.addSection(actionSection);

  // Attach the response at the bottom if we have one
  if (optionalAnswerSection) {
    card.addSection(optionalAnswerSection);
  }

  return card.build();
}

// Handles clicks from the Send message button.
function handleSendMessage(event) {
  const commonEventObject = event.commonEventObject || {};
  const formInputs = commonEventObject.formInputs || {};
  const messageInput = formInputs.message;

  let userMessage = "";
  if (messageInput && messageInput.stringInputs && messageInput.stringInputs.value.length > 0) {
    userMessage = messageInput.stringInputs.value[0];
  }

  if (!userMessage || userMessage.trim().length === 0) {
    return CardService.newActionResponseBuilder()
      .setNotification(CardService.newNotification().setText("Please enter a message."))
      .build();
  }

  let finalQueryText = `USER MESSAGE TO ANSWER: ${userMessage}`;

  // If we have an email selected in Gmail, append its content as context
  if (event.gmail && event.gmail.messageId) {
    try {
      GmailApp.setCurrentMessageAccessToken(event.gmail.accessToken);
      const message = GmailApp.getMessageById(event.gmail.messageId);

      const subject = message.getSubject();
      const bodyText = message.getPlainBody() || message.getBody();

      finalQueryText += `\n\nEMAIL THE USER HAS OPENED ON SCREEN:\nSubject: ${subject}\nBody:\n---\n${bodyText}\n---`;
    } catch (e) {
      console.error("Could not fetch Gmail context: " + e);
      // Invalidate the token explicitly so the next prompt requests the missing scopes
      ScriptApp.invalidateAuth();

      CardService.newAuthorizationException()
        .setResourceDisplayName("Enterprise AI")
        .setAuthorizationUrl(ScriptApp.getAuthorizationUrl())
        .throwException();
    }
  }

  try {
    const responseText = queryAgent({ text: finalQueryText, forceNewSession: true });

    // We leverage the 'showdown' library to parse the LLM's Markdown output into HTML
    // We also substitute markdown listings with arrows and adjust newlines for clearer rendering in the sidebar
    let displayedText = substituteListingsFromMarkdown(responseText);
    displayedText = new showdown.Converter().makeHtml(displayedText).replace(/\n/g, '\n\n');

    const textParagraph = CardService.newTextParagraph();
    textParagraph.setText(displayedText);

    const answerSection = CardService.newCardSection()
      .addWidget(textParagraph);

    const updatedCard = createSidebarCard(answerSection);

    return CardService.newActionResponseBuilder()
      .setNavigation(CardService.newNavigation().updateCard(updatedCard))
      .build();

  } catch (err) {
    return CardService.newActionResponseBuilder()
      .setNotification(CardService.newNotification().setText("Error fetching response: " + err.message))
      .build();
  }
}
...

AgentHandler.gs

下列程式碼會自動調度管理對 Gemini Enterprise 的 API 呼叫。

  1. 自動調度管理 API 呼叫:queryAgent 是外掛程式和 Gemini Enterprise 之間的橋梁。它會建構要求,其中包含使用者的查詢、時區和有效工作階段 ID。
  2. 動態探索:呼叫 getAgentDataStores,找出可用的資料連接器。
  3. 串流回覆:由於代理回覆可能需要一些時間,因此會使用 streamAssist API 搭配伺服器傳送事件 (SSE)。程式碼會收集回覆片段,並重構完整答案。
...
// Service that handles Gemini Enterprise AI Agent operations.

// Submits a query to the AI agent and returns the response string synchronously
function queryAgent(input) {
  const isNewSession = input.forceNewSession || !PropertiesService.getUserProperties().getProperty(AGENT_SESSION_NAME);
  const sessionName = input.forceNewSession ? createAgentSession() : getOrCreateAgentSession();

  let systemPrompt = "SYSTEM PROMPT START Do not respond with tables but use bullet points instead.";
  if (input.forceNewSession) {
    systemPrompt += " Do not ask the user follow-up questions or converse with them as history is not kept in this interface.";
  }
  systemPrompt += " SYSTEM PROMPT END\n\n";

  const queryText = isNewSession ? systemPrompt + input.text : input.text;

  const requestPayload = {
    "session": sessionName,
    "userMetadata": { "timeZone": Session.getScriptTimeZone() },
    "query": { "text": queryText },
    "toolsSpec": { "vertexAiSearchSpec": { "dataStoreSpecs": getAgentDataStores().map(ds => { dataStore: ds }) } },
    "agentsSpec": { "agentSpecs": [{ "agentId": getAgentId() }] }
  };

  const responseContentText = UrlFetchApp.fetch(
    `https://${getLocation()}-discoveryengine.googleapis.com/v1alpha/${getReasoningEngine()}/assistants/default_assistant:streamAssist?alt=sse`,
    {
      method: 'post',
      headers: { 'Authorization': `Bearer ${ScriptApp.getOAuthToken()}` },
      contentType: 'application/json',
      payload: JSON.stringify(requestPayload),
      muteHttpExceptions: true
    }
  ).getContentText();

  if (isInDebugMode()) {
    console.log(`Response: ${responseContentText}`);
  }

  const events = responseContentText.split('\n').map(s => s.replace(/^data:\s*/, '')).filter(s => s.trim().length > 0);
  console.log(`Received ${events.length} agent events.`);

  let answerText = "";
  for (const eventJson of events) {
    if (isInDebugMode()) {
      console.log("Event: " + eventJson);
    }
    const event = JSON.parse(eventJson);

    // Ignore internal events
    if (!event.answer) {
      console.log(`Ignored: internal event`);
      continue;
    }

    // Handle text replies
    const replies = event.answer.replies || [];
    for (const reply of replies) {
      const content = reply.groundedContent.content;
      if (content) {
        if (isInDebugMode()) {
          console.log(`Processing content: ${JSON.stringify(content)}`);
        }
        if (content.thought) {
          console.log(`Ignored: thought event`);
          continue;
        }
        answerText += content.text;
      }
    }

    if (event.answer.state === "SUCCEEDED") {
      console.log(`Answer text: ${answerText}`);
      return answerText;
    } else if (event.answer.state !== "IN_PROGRESS") {
      throw new Error("Something went wrong, check the Apps Script logs for more info.");
    }
  }
  return answerText;
}

// Gets the list of data stores configured for the agent to include in the request.
function getAgentDataStores() {
  const responseContentText = UrlFetchApp.fetch(
    `https://${getLocation()}-discoveryengine.googleapis.com/v1/${getReasoningEngine().split('/').slice(0, 6).join('/')}/dataStores`,
    {
      method: 'get',
      // Use the add on service account credentials for data store listing access
      headers: { 'Authorization': `Bearer ${getAddonCredentials().getAccessToken()}` },
      contentType: 'application/json',
      muteHttpExceptions: true
    }
  ).getContentText();
  if (isInDebugMode()) {
    console.log(`Response: ${responseContentText}`);
  }
  const dataStores = JSON.parse(responseContentText).dataStores.map(ds => ds.name);
  if (isInDebugMode()) {
    console.log(`Data stores: ${dataStores}`);
  }
  return dataStores;
}
...

啟動服務帳戶

建立專屬服務帳戶,授權外掛程式的伺服器端作業。

在 Google Cloud 控制台中,按照下列步驟操作:

  1. 依序點選「選單」圖示 ☰ >「IAM 與管理」>「服務帳戶」>「+ 建立服務帳戶」。

  1. 將「服務帳戶名稱」設為 ge-add-on。

d44d6aae29e2464c.png

  1. 按一下 [建立並繼續]。
  2. 在權限中新增「Discovery Engine 檢視者」角色。

f1374efa4f326ef5.png

  1. 依序點選「繼續」和「完成」。系統會將您重新導向至「Service accounts」(服務帳戶) 頁面,您可以在該頁面查看建立的服務帳戶。

b9496085f1404c5c.png

  1. 選取新建立的服務帳戶,然後點選「金鑰」分頁標籤。
  2. 依序點選「新增金鑰」和「建立新的金鑰」。
  3. 選取「JSON」,然後點選「建立」。

f4280f5533a08821.png

  1. 對話方塊會關閉,新建立的公開/私密金鑰組會自動以 JSON 檔案格式下載到本機環境。

建立及設定 Apps Script 專案

建立新的 Apps Script 專案,用於託管外掛程式程式碼,並設定連線屬性。

  1. 點選下方按鈕,開啟 Enterprise AI 外掛程式 Apps Script 專案:

  1. 依序點選「總覽」>「建立副本」。
  2. 在 Apps Script 專案中,依序點選「專案設定」>「編輯指令碼屬性」>「新增指令碼屬性」,新增指令碼屬性。
  3. 將 REASONING_ENGINE_RESOURCE_NAME 設為 Gemini Enterprise 應用程式資源名稱。格式如下:
# 1. Replace PROJECT_ID with the Google Cloud project ID.
# 2. Replace GE_APP_ID with the codelab app ID found in Google Cloud console > Gemini Enterprise > Apps.

projects/<PROJECT_ID>/locations/global/collections/default_collection/engines/<GE_APP_ID>
  1. 將 APP_SERVICE_ACCOUNT_KEY 設為先前步驟下載的服務帳戶檔案中的 JSON 金鑰。
  2. 按一下「儲存指令碼屬性」

部署至 Gmail 和 Chat

部署外掛程式,直接在 Gmail 和 Google Chat 中測試。

在 Apps Script 專案中,按照下列步驟操作:

  1. 依序點選「部署」>「測試部署作業」,然後點選「安裝」。這項功能現已在 Gmail 推出。
  2. 按一下「首要部署作業 ID」下方的「複製」。

2ed2df972ad92715.png

在 Google Cloud 控制台中,按照下列步驟操作:

  1. 在 Google Cloud 搜尋欄位中搜尋 Google Chat API,然後依序點選「Google Chat API」、「管理」和「設定」。

  1. 選取「啟用互動功能」。
  2. 取消選取「加入聊天室和群組對話」。
  3. 在「連線設定」下方,選取「Apps Script」。
  4. 將「部署作業 ID」設為先前步驟中複製的「首要部署作業 ID」。
  5. 在「Visibility」(瀏覽權限) 下方,選取「Make this Chat app available to specific people and groups in Your Workspace Domain」(將這個 Chat 應用程式提供給 Workspace 網域中的特定使用者和群組),然後輸入您的電子郵件地址。
  6. 按一下「儲存」。

3b7d461c423f7c51.png

試用外掛程式

與上線的外掛程式互動,確認外掛程式能擷取資料,並根據情境回答問題。

在新分頁中開啟 Google Chat,然後按照下列步驟操作:

  1. 開啟與 Chat 擴充應用程式 Gemini Enterprise 互傳的即時訊息。

3da8690d19baf2d0.png

  1. 按一下「設定」,然後完成驗證流程。
  2. 輸入 What are my meetings for today?,然後按下 enter 鍵。Gemini Enterprise Chat 擴充應用程式應會回覆結果。

c8c63fb3f324fecf.png

在新分頁開啟 Gmail,然後按照下列步驟操作:

  1. 傳送一封電子郵件給自己,主旨設為 We need to talk,內文設為 Are you available today between 8 and 9 AM?
  2. 開啟新收到的電子郵件訊息。
  3. 開啟 Enterprise AI 外掛程式側欄。
  4. 將「Message」設為 Am I?
  5. 按一下 [傳送訊息]。
  6. 答案會顯示在按鈕後方。

d33b8cb50ee251b7.png

6. 清除

刪除 Google Cloud 專案

為避免系統向您的 Google Cloud 帳戶收取本程式碼實驗室所用資源的費用,建議您刪除 Google Cloud 專案。

在 Google Cloud 控制台中,按照下列步驟操作:

  1. 依序點選「選單」圖示 ☰ >「IAM 與管理」>「設定」。

  1. 按一下「Shut down」(關閉)。
  2. 輸入專案 ID。
  3. 按一下「仍要關閉」。

3b9492d97f771b2c.png

7. 恭喜

恭喜!您打造的解決方案,能讓員工更輕鬆地結合 Gemini Enterprise 和 Google Workspace 的強大功能!

後續步驟

本程式碼實驗室僅展示最典型的用途,但您在解決方案中可能需要考慮許多擴充領域,例如:

  • 使用 Gemini CLI 和 Antigravity 等 AI 輔助開發人員工具。
  • 與其他代理框架和工具整合,例如自訂 MCP、自訂函式呼叫和生成式 UI。
  • 與其他 AI 模型整合,包括託管於 Agent Platform 等專用平台的自訂模型。
  • 與其他代理整合,這些代理可託管於 Dialogflow 等專屬平台,或由第三方透過 Cloud Marketplace 提供。
  • 在 Cloud Marketplace 發布代理,協助團隊、組織或一般使用者。

瞭解詳情

開發人員可參考許多資源,例如 YouTube 影片、說明文件網站、程式碼範例和教學課程: