使用應對手冊建構代理程式

本指南說明如何使用劇本建構及測試簡單的襯衫訂購代理程式。與這個智慧助理互動時,你可以詢問商店位置、營業時間,或訂購襯衫。

事前準備

閱讀本指南之前,請先完成下列工作:

  1. 如果尚未設定,請按照設定指示操作。

關於應對手冊

代理程式由一或多個應對手冊組成。 每本應對手冊都有明確定義的有限範圍。 劇本包含下列資料:

X 項目
名稱 用於識別劇本的名稱。
目標 目標是劇本應達成的概略描述。
操作說明 操作說明是達成劇本目標時應採取的高階步驟。
範例 範例是使用者與代理程式之間的對話範例。這些範例實際上是 LLM 的少量樣本提示範例。

建立代理程式

如要建立代理程式,請按照下列步驟操作:

  1. 前往 Conversational Agents 控制台:

    Conversational Agents 控制台

  2. 選取或建立專案 (如果尚未建立)。

  3. 點選「建立代理」

  4. 點按「自行建立」

  5. 將代理程式命名為「Shirt Ordering - Playbooks」。

  6. 提供位置

  7. 提供時區。

  8. 提供預設語言

  9. 在「Conversation start」選項中選取「Playbook」

  10. 點選「建立」

  11. 使用者介面會將您帶往名為「Default Generative Playbook」的預設 Playbook。

  12. 按一下返回按鈕,即可查看劇本清單。

建立訂單應對手冊

Order 應對手冊會處理襯衫訂單。 如要建立這本應對手冊:

  1. 點選「建立」
  2. 選取「工作應對手冊」選項。
  3. 輸入應對手冊名稱:Order
  4. 輸入下列目標:

    You are a shirt store ordering assistant. Help customers purchase shirts.
    Help the customer choose a size and color.
    The shirts come in small, medium, and large.
    The shirts can be red, green, or blue.
    
  5. 輸入下列指令:

    - If the customer has not provided a size, ask them to choose a size.
    - If the customer has not provided a color, ask them to choose a color.
    - Once the customer has selected a size and color for the shirt,
      repeat the selection to the customer, and ask them to confirm the selection.
    - Once the customer has confirmed their selection,
      let them know that the shirt is now ordered.
    - Do not provide prices or collect payment.
    - Do not collect the customer's name or address.
    
  6. 按一下 [儲存]

  7. 按一下返回按鈕,返回劇本清單。

建立資訊應對手冊

資訊劇本會處理有關商店的問題。如要建立這本應對手冊:

  1. 點選「建立」
  2. 選取「工作應對手冊」選項。
  3. 輸入應對手冊名稱:Information
  4. 輸入下列目標:

    You provide information about a shirt store.
    The store is open between 8 AM and 6 PM every day.
    The store is located at 1007 Mountain Drive, Gotham City, NJ.
    
  5. 輸入下列指令:

    - If the customer asks for the store location, provide them with the address.
    - If the customer asks for the store hours, provide them with the hours.
    
  6. 按一下 [儲存]

  7. 按一下返回按鈕,返回劇本清單。

更新預設劇本

首次建立應用程式時,系統會為您建立預設劇本。這本教戰手冊應引導對話,轉向以特定目標為主的適當教戰手冊。在下方的操作說明中,您可以看到預設教戰手冊如何參照其他教戰手冊。如要更新這本教戰手冊:

  1. 按一下預設劇本。本教戰手冊已加上醒目顯示的星號。
  2. 輸入下列目標:

    You are an assistant for a shirt store.
    Your name is "Samantha".
    Your job is to direct customers to other playbooks based on the customer's questions.
    
  3. 輸入下列指令:

    - If the customer hasn't been greeted yet, greet the customer,
      introduce yourself, and ask the user how you can help.
    - If the customer wants information about the store,
      route them to ${PLAYBOOK: Information}
    - If the customer wants to purchase a shirt,
      route them to ${PLAYBOOK: Order}
    
  4. 按一下 [儲存]

  5. 請注意,由於目前沒有範例,因此系統會醒目顯示劇本參照。我們會在下一節中新增這些項目。

  6. 按一下返回按鈕,返回劇本清單。

提供範例

此時,劇本已可運作。不過,您必須提供範例,確保模型回覆品質。

開啟應對手冊後,即可在「範例」分頁中手動提供範例。不過,使用運作中的劇本進行對話,並將對話儲存為範例,通常會比較簡單。

預設劇本的對話範例很簡短。 這份教戰手冊只需要將你導向另一份教戰手冊即可。 如要與預設劇本對話,請按照下列步驟操作:

  1. 關閉或取消畫面右側可能顯示的任何面板。
  2. 按一下頂端導覽列中的模擬器 按鈕。
  3. 在「資源」中,選取預設的劇本。
  4. 使用預設模型或選取其他模型。
  5. 在「Enter user input」文字方塊中輸入 Hello,然後按下 Enter 鍵。
  6. 劇本會回覆問候訊息。

如要將這段對話儲存為範例:

  1. 在「Invocations」下拉式選單中選取預設劇本。
  2. 按一下介面右上方的「儲存為範例」按鈕。
  3. 範例編輯器面板隨即開啟。 您可以使用這個編輯器新增、編輯、刪除或重新排序動作。
  4. 提供範例名稱:Greeting
  5. 視需要更新劇本回覆。
  6. 向下捲動至「End example with output information」(以輸出資訊結尾的範例),然後在「Summary」(摘要) 區段中輸入 The user is greeted.
  7. 按一下儲存圖示。

在資訊劇本中新增位置範例:

  1. 關閉或取消畫面右側可能顯示的任何面板。
  2. 如有需要,請按一下「重設」restart_alt 按鈕,重設對話。
  3. 在模擬工具的「Start Resource」下拉式選單中,選取資訊劇本。
  4. 輸入訊息:Where are you located?
  5. 劇本會回覆位置資訊。
  6. 在「Invocations」下拉式選單中選取資訊劇本。
  7. 按一下「另存為範例」按鈕。
  8. 提供範例名稱:Location
  9. 如要將這段對話儲存為範例,請先刪除包含「你在哪裡」的動作。只有預設劇本範例可以從使用者動作開始。
  10. 如要提供範例,並加入發起對話的脈絡,請展開「先前對話的摘要...」部分,然後在「Starts example with input information」(以輸入資訊開始範例) 欄位中輸入以下內容:The customer asked "Where are you located?"
  11. 如要提供範例,並加入完成對話的脈絡,請展開「劇本執行摘要...」部分,並在「End example with output information」(以輸出資訊結尾的範例) 欄位中輸入以下內容:The store is located at 1007 Mountain Drive, Gotham City, NJ.
  12. 按一下儲存圖示。

在資訊劇本中新增營業時間範例:

  1. 與上述步驟類似,但請輸入訊息:What are your hours?,並將範例命名為:Hours

為訂單應對手冊新增選取範例:

  1. 與上述步驟類似,但請將範例命名為 Selection,選取訂單劇本,然後傳送下列訊息:

    • I want to buy a shirt
    • Large
    • Green
    • Yes

測試代理

現在可以測試代理程式。 開啟模擬器面板,與代理進行對話。您不需要進行上述對話。 舉例來說,你可以詢問這個代理程式襯衫有哪些顏色。如果沒有得到預期結果,請修正範例並建立新範例,以改善回覆。

使用 API 與代理程式互動

請參閱「與 API 互動」一節。