使用 Agent Studio 建構零程式碼多代理系統

1. 總覽

傳統上,建構互動式 AI 助理需要編寫應用程式程式碼、整合工具,以及管理部署基礎架構。Google Cloud 的 Agent Studio 提供視覺化的自然語言介面,任何人都能在預覽模擬器中並排設計、指示、建立基準及測試多代理系統,完全不必編寫程式碼。

在這個適合初學者的程式碼實驗室中,您將設定個人助理代理,並將其發展為協調的多代理系統,其中包含三個專門角色:

  • 行程規劃幫手:規劃行程和每日詳細行程。
  • 科技活動搜尋:使用即時 Google 搜尋建立基準,搜尋即將舉辦的科技聚會和會議。
  • 營養師:根據飲食偏好,建議結構化飲食計畫和營養指南。

必要條件

  • 具備使用網頁應用程式和瀏覽器的基本知識
  • 對大型語言模型和 AI 代理有基本瞭解 (不需具備 Python 或程式設計背景)

課程內容

  • 如何在 Google Cloud 操作 Agent Studio 控制台
  • 如何使用自然語言指令定義代理的角色和目標
  • 如何將單體式提示重構為協調器和專門的子代理
  • 如何使用搜尋工具為代理建立基準,尋找即時事件資訊
  • 如何使用內建模擬器測試及調整代理行為

軟硬體需求

  • Google 帳戶 (如要申請工作坊抵免額,請使用個人 @gmail.com 帳戶)
  • 講師提供的研討會抵免額連結 (以及用於掃描 QR code 的手機相機),或有效的 Cloud Billing 帳戶
  • Google Chrome (建議使用無痕視窗,避免混用個人和公司帳戶)

2. 領取 Google Cloud 抵免額 (選用)

如果您是自行完成本程式碼實驗室,且符合資格,請使用本頁面的 Google Developer Program 抵免額橫幅,在不提供信用卡的情況下領取抵免額。如果您參加研討會,並從講師那裡取得活動抵免額連結,請按照本節中的活動抵免額步驟操作。

領取活動抵免額

您可以透過 Google 開發人員中心 (Google Developer Program 的一部分) 領取工作坊活動抵免額。

如要領取活動抵免額,請按照下列步驟操作:

  1. 在無痕視窗中開啟工作坊抵免額連結,並使用個人 @gmail.com 帳戶登入。
  2. 在「領取福利」資訊卡中,按一下「領取抵免額」。

Google 開發人員中心「領取福利」卡片,顯示「領取抵免額」按鈕。

  1. 選用:如果系統提示您建立 Google Developer Program 設定檔,請填寫表單。
  2. 「掃描以驗證您是真人」對話方塊出現時,請使用手機掃描 QR code 並完成驗證。如果 QR code 未顯示,請重新整理頁面,然後再次點選「領取抵免額」。
  3. 確認畫面上顯示「已成功領取活動抵免額!」訊息,然後點選「開啟帳單帳戶」。

Google 開發人員中心確認卡片,顯示「已成功領取活動抵免額」和「開啟帳單帳戶」按鈕。

🔍 檢查成果

帳單帳戶佈建作業最多可能需要五分鐘。如要確認抵免額是否有效,請完成下列步驟:

  1. 如果「帳單帳戶管理」頁面尚未開啟,請開啟 Google Cloud Billing (或將網址複製到無痕視窗):
https://console.cloud.google.com/billing
  1. 按一下「您的帳單帳戶」分頁標籤,然後重新整理頁面,直到包含「GDP Credit」的帳戶在「狀態」欄中顯示「有效」為止。

Google Cloud Billing 帳戶管理頁面,顯示有效的 GDP 抵免額帳單帳戶。

3. 建立 Google Cloud 專案 (選用)

建立專屬的 Google Cloud 雲端專案,將本程式碼實驗室的所有資源隔離,以便在完成後徹底移除。

如要建立 Google Cloud 專案,請按照下列步驟操作:

  1. 開啟「建立專案」頁面 (或將網址複製到無痕視窗):
https://console.cloud.google.com/projectcreate
  1. 輸入專案詳細資料:
    • 專案名稱:輸入描述性名稱,例如 google-cloud-workshop。
    • 「帳單帳戶」(如有顯示):選取「GDP Credit」帳戶 (或有效的帳單帳戶)。
    • Parent resource (上層資源):保留「No organization」(無組織) 選項 (或視需要選取組織)。
  2. 記下系統產生的專案 ID,然後點選「建立」。

「建立 Google Cloud 雲端專案」表單,顯示「專案名稱」、「產生的專案 ID」、「上層資源」和「建立」按鈕。

🔍 檢查成果

專案建立完成後,開啟 Google Cloud 控制台工具列中的「通知」,然後點選「選取專案」。

Google Cloud 控制台的「通知」選單,其中顯示「建立專案」和「選取專案」連結。

4. 設定環境

確認您已在 Google Cloud 控制台左上方的專案挑選器中,選取有效的 Google Cloud 雲端專案,然後啟用 Agent Platform API,以便使用 Agent Studio。

啟用 Agent Platform API

  1. 在 Cloud Marketplace 開啟 Agent Platform API (或將網址複製到無痕視窗):
https://console.cloud.google.com/marketplace/product/google/aiplatform.googleapis.com
  1. 確認頂端工具列已選取工作坊專案,然後點選「啟用」(如果已顯示「管理」,代表 API 已啟用)。

5. 建立第一個代理

建立虛擬服務專員

啟用 Agent Platform API 後,請在 Agent Studio 建立第一個代理:

  1. 開啟 Agent Studio (或將網址複製到無痕視窗):
https://console.cloud.google.com/agent-platform/studio/agent-designer/list
  1. 在「歡迎」頁面,點選「+ 建立代理」。
  2. 系統會將您重新導向至 Agent Designer 控制台。
  3. 按一下「我的代理」,然後填寫下列設定:
  • 名稱:個人助理
  • 說明:多功能、友善且實用的個人助理。
  • 操作說明:
You are a versatile, friendly, and practical personal assistant. Your primary goal is to assist the user with three specific domains: Travel Planning, Tech Event Scouting, and Diet/Nutrition advice. You adjust your tone to be helpful, professional, and clear.
  • 模型:Gemini 3.8 Flash
  • 工具:Google 搜尋和網址背景資訊
  • 按一下畫面右上角的「儲存」。
  1. 儲存代理後,點選「預覽」。
  2. 測試代理,例如詢問「你好,你可以做什麼?」。代理會根據上述指示回覆。

瞭解內建工具

Agent Studio 提供內建工具,可將代理連結至外部資料:

  • Google 搜尋:允許代理即時查詢網路,擷取最新資訊 (例如即將舉辦的科技活動)。
  • 網址背景資訊:讓代理專注於使用者提供的特定網頁內容,確保回覆有憑有據。

6. 測試代理

由於這個個人助理代理涵蓋旅遊規劃、科技活動搜尋和飲食建議,請逐一測試各項功能。

首先,測試旅遊規劃要求:

I want to plan a 3-day trip to Tokyo next month.

接著,請 Gemini 搜尋科技活動:

Find me some upcoming events in Singapore on Luma.

最後,要求提供飲食計畫:

Can you help me design a healthy meal plan?

您會發現代理的回覆很籠統,因為它還不瞭解您。例如,即使你是素食者,它可能會建議吃含肉的早餐;即使你喜歡歷史悠久的寺廟,它可能會規劃充滿現代購物中心的旅遊行程。

為了成為真正的個人助理,代理必須經過自訂,才能瞭解您的個人偏好。

7. 打造個人專屬的單體式代理

在單一主要代理的指令中,加入三種角色 (旅遊、活動和飲食) 的詳細指南,擴充代理的功能 (單一代理設計)。

  1. 點選 Flow,返回 Agent Designer 控制台。
  2. 按一下「Personal Assistant」開啟設定。
  3. 將現有的指令文字全部替換為下列擴充的單一提示:
You are a highly personalized assistant. You always use a helpful, clear, and professional tone. Keep the following user profile and preferences in mind for every interaction:

- USER DIET: The user is strictly vegetarian and prefers high-protein options. Never suggest recipes containing meat, poultry, or fish. Focus on rich plant-based proteins (e.g., tofu, lentils, Greek yogurt).

- USER TRAVEL: The user prefers structured trips, historical landmarks, and local culinary experiences. Always prioritize these elements in itineraries.

- USER TECH INTERESTS: The user is based in Singapore and is interested in Artificial Intelligence events on Luma, Eventbrite, and Meetup.

### Domain 1: Travel Planner
When the user asks to plan a trip, generate a structured, day-by-day travel itinerary with clear headings and bullet points, keeping the USER TRAVEL preferences in mind.

### Domain 2: Tech Event Scout
When the user asks to find tech events, search specifically for upcoming AI or Web Development events in Singapore on Luma or Meetup, keeping the USER TECH INTERESTS in mind.

### Domain 3: Personal Dietitian
When the user requests nutrition or meal planning advice, draft a structured meal plan with simple food recommendations, keeping the USER DIET preferences in mind. Always include a disclaimer stating this is for educational purposes only.
  1. 開啟「預覽」面板。如果對話正在進行,請點選右上方的「New Session」,清除對話記錄。
  2. 使用相同的提示詞再次與代理對話:
  • 我想規劃下個月去東京 3 天的行程。
  • 幫我找 Luma 上即將在新加坡舉辦的活動。
  • 可以幫我設計健康飲食計畫嗎?

現在,代理會先套用系統提示中的偏好設定,再回答問題。

雖然這種個人化單體代理可以運作,但隨著代理成長,可能會面臨以下挑戰:

  • 提示詞過於冗長:如果加入喜愛的航空公司、運動習慣和工作時間表,單一提示詞區塊會變得過長,模型也更容易遺漏限制條件。
  • 工具過度曝光:只有 Event Scout 需要 Google 搜尋。如果為單體式代理啟用 Google 搜尋,營養師和旅遊規劃師也會使用這項功能,觸發不必要的網頁搜尋。
  • 維護難度:更新飲食偏好設定時,不應有破壞差旅規則的風險。

為解決這個問題,您將這些設定檔拆分為專門的子代理。

8. 轉換至多代理系統

將個人化助理分成三個專業子代理組成的團隊,並由個人助理擔任協調者。

  1. 點選 Flow,返回 Agent Designer 控制台。
  2. 按一下「Personal Assistant」開啟設定。
  3. 將「Instructions」替換為協調提示:
You are a personal assistant coordinator. Your goal is to understand the user's intent and route the conversation to the correct specialist sub-agent:
- Route to the Travel Planner sub-agent if the user wants to plan a trip, vacation, or itinerary.
- Route to the Tech Event Scout sub-agent if the user is looking for tech events, meetups, or conferences.
- Route to the Personal Dietitian sub-agent if the user is asking for diet, meal planning, recipes, or nutrition advice.
  1. 將「模型」變更為「Gemini 3.5 Flash」(輕量級轉送作業不需要大型模型)。
  2. 從「工具」中移除「Google 搜尋」和「網址背景資訊」。
  3. 在「代理設計工具」畫布上任一處點按一下,即可儲存代理。

9. 建立個人化子代理

現在,請建構三個專門的子代理,並為每個子代理設定專屬的領域偏好設定和工具。

建立旅遊規劃子代理

  1. 點選 Flow,返回 Agent Designer 控制台。
  2. 找到「Personal Assistant」,然後點選資訊卡底部的「+」按鈕。
  3. 按一下「Subagent」,然後填寫下列設定:
  • Name: Travel Planner
  • 說明:處理與行程、旅遊偏好和行李打包訣竅相關的查詢。
  • 操作說明:
You are a detail-oriented Travel Planner. 

PREFERENCE: The user prefers structured trips, historical landmarks, and local culinary experiences.

When the user asks to plan a trip:
1. Build a structured, day-by-day travel itinerary matching the destination they mention.
2. Ensure the itinerary is tailored around historical sites and local dining experiences.
3. Include practical travel tips such as packing recommendations and typical local weather estimates for that region.
4. Keep the suggestions organized with clear headings and bullet points.
  1. 將「模型」設為「Gemini 3.8 Flash」。
  2. 從「工具」中移除「網址背景資訊」,並保持啟用「Google 搜尋」。
  3. 在「代理設計工具」畫布上任一處點按,即可儲存子代理。

建立 Tech Event Scout 子代理

  1. 點選 Flow,返回 Agent Designer 控制台。
  2. 找到「Personal Assistant」,然後點選資訊卡底部的「+」按鈕。
  3. 按一下「Subagent」,然後填寫下列設定:
  • Name: Tech Event Scout
  • 說明:在 Luma、Meetup 和 Eventbrite 上搜尋即將舉辦的科技聚會、活動和會議。
  • 操作說明:
You are a proactive Tech Event Scout.

PREFERENCE: The user is based in Singapore and is interested in Artificial Intelligence and Web Development events on Luma and Meetup.

When the user asks to find tech events:
1. Use the Google Search tool to search for actual, upcoming AI or Web Development events in Singapore on Luma or Meetup.
2. Present 3 to 4 upcoming events. For each event, provide:
   - The event title
   - Date and location
   - The platform hosting it (Luma or Meetup)
   - A brief description of what the event covers
3. Remind the user to verify the event registration page for official details before finalizing plans.
  1. 將「模型」設為「Gemini 3.8 Flash」。
  2. 從「工具」中移除「網址背景資訊」,並保持啟用「Google 搜尋」。
  3. 在「代理設計工具」畫布上任一處點按,即可儲存子代理。

建立營養師子代理

  1. 點選 Flow,返回 Agent Designer 控制台。
  2. 找到「Personal Assistant」,然後點選資訊卡底部的「+」按鈕。
  3. 按一下「Subagent」,然後填寫下列設定:
  • Name: Dietitian
  • 說明:提供結構化飲食計畫、食譜和飲食建議。
  • 操作說明:
You are an encouraging and practical Dietitian.

PREFERENCE: The user is strictly vegetarian and prefers high-protein options. Never suggest recipes containing meat, poultry, or fish.

When the user requests nutrition or meal planning advice:
1. Draft a simple, structured 3-day meal plan featuring high-protein, vegetarian food items (e.g., tofu, beans, greek yogurt, eggs).
2. Include a brief list of primary ingredients to help them with grocery planning.
3. Always include this disclaimer: "This advice is for educational and general planning purposes. Please consult a healthcare professional or registered dietitian for personalized medical advice."
  1. 將「模型」設為「Gemini 3.8 Flash」。
  2. 從「工具」中移除「Google 搜尋」和「網址背景資訊」。
  3. 在「代理設計工具」畫布上任一處點按,即可儲存子代理。

設定好三個子代理後,Agent Designer 中的代理圖表會如下所示:

Agent Designer 畫布,顯示個人助理協調員連結至旅遊規劃工具、科技活動偵察員和營養師子代理

10. 測試多代理系統

確認協調者在單一多輪對話中,能順暢地在三個專門子代理之間轉送。

如要清除對話記錄,請點選「預覽」面板中的「新工作階段」,然後測試以下三個提示:

  • 我想規劃下個月去東京 3 天的行程。
  • 幫我找 Luma 上即將在新加坡舉辦的活動。
  • 可以幫我設計健康飲食計畫嗎?

代理能準確切換三個領域後,即可部署至 Agent Runtime。

11. 部署代理 (選用)

在預覽模擬器中確認代理行為符合需求後,即可部署至 Agent Runtime,讓外部應用程式或使用者呼叫。

透過 Agent Studio 部署

  1. 在「Agent Studio」控制台頂端,點選「部署」。
  2. 選取目標區域,並部署至 Agent Runtime。
  3. 等待 2 到 5 分鐘,讓佈建作業完成。

測試已部署的代理

部署完成後,請依序前往「Agent Runtime」>「Playground」,測試即時執行階段:

  1. 開啟 Agent Runtime (或將網址複製到無痕視窗):
https://console.cloud.google.com/agent-platform/runtimes
  1. 在執行階段清單中,點選已部署的代理 (Personal Assistant)。
  2. 選取「Playground」分頁標籤,然後傳送測試查詢,確認協調器和子代理在實際環境中的轉送作業。

排解部署失敗問題

在沙箱或工作坊專案中,您有時可能會看到類似以下的錯誤:

Creating agent runtime for Personal Assistant in us-west1
1 minute ago
gcp-experiments
Deployment failed: Reasoning Engine resource [projects/415458962931/locations/us-west1/reasoningEngines/4162566304806469632] failed to start and cannot serve traffic. Please refer to our troubleshooting pages (e.g., https://docs.cloud.google.com/gemini-enterprise-agent-platform/troubleshooting/agent-deployment) to debug and fix the error.

如果遇到這項錯誤,請檢查下列事項:

  • 驗證專案計費功能:確認 Google Cloud 專案已連結有效的帳單帳戶。
  • IAM 權限:確認使用者帳戶或服務代理具備 Agent Platform 使用者 (roles/aiplatform.user) 角色。
  • 在 Agent Runtime 重試:在左側導覽選單中開啟「Agent Runtime」,查看狀態或重試部署作業。

12. 清除 (選用)

為避免 Google Cloud Billing 帳戶持續產生費用,請在完成後刪除所有已部署的執行階段和代理資源。

刪除執行階段 (如有部署)

  1. 開啟 Agent Runtime (或將網址複製到無痕視窗):
https://console.cloud.google.com/agent-platform/runtimes
  1. 按一下「Personal Assistant」旁邊的三個垂直點 (「更多動作」),然後選取「刪除」。

刪除代理

  1. 開啟 Agent Studio (或將網址複製到無痕視窗):
https://console.cloud.google.com/agent-platform/studio/agent-designer/list
  1. 按一下「Personal Assistant」旁邊的三個垂直點 (「更多動作」),然後選取「刪除」。

關閉 Google 雲端專案

如果您是專為本程式碼實驗室建立專案,並想刪除其中的所有資源,請按照下列步驟操作:

  1. 開啟「專案設定」(或將網址複製到無痕視窗):
https://console.cloud.google.com/iam-admin/settings
  1. 確認頁面頂端已選取程式碼實驗室專案,然後依序點選「關閉」、輸入專案 ID,再點選「仍要關閉」。

13. 恭喜

恭喜!您已使用 Agent Studio 建構多用途個人助理系統,完全不需編寫程式碼。

完成的目標

  • 在 Agent Studio 設定代理,並使用內建的 Google 搜尋建立基準
  • 將單一單體式系統提示詞,演進為一個協調者和三個領域子代理
  • 在模擬器中測試多輪轉送,涵蓋旅遊、活動探查和營養相關工作

接下來,您可以嘗試將代理連結至企業資料來源、MCP 工具或自訂網頁前端。