建構自己的生成式 AI 協助功能

您可以建立自己的生成式 AI 輔助工具,並與 Agent Assist 整合。文字生成器會使用 Text Bison 和 Gemini 等先進的大型語言模型 (LLM) 生成建議。您可以根據這些建議,協助客戶服務對話的兩端參與者,例如真人服務專員和真人使用者。生成器可以使用 Agent Assist 的內建 LLM 呼叫,並針對大多數 LLM 工作進行設定。如要進一步瞭解 Agent Assist 中的生成器,請參閱 Vertex AI 說明文件

生成器輸入內容

文字產生器需要下列輸入內容:

  • 指令:說明您希望文字生成器執行的工作。在 Vertex AI 中,這項指令稱為「提示」

  • 模型選項:選擇模型和設定,確保模型發揮最佳效能,例如溫度、輸出符記限制、TopK 和 TopP。這些設定會限制生成器輸出內容。建立生成器時,您可以點選「模型選項」選擇模型並設定模型選項,也可以使用預設設定。在 Vertex AI 中,模型選項稱為「參數值」

  • 觸發事件:下列其中一個事件,表示何時啟動產生器:

    • END_OF_UTTERANCE:在每次輸入語音後觸發產生器。
    • MANUAL_CALL:只有在您明確發出 API 呼叫來叫用產生器時,才會觸發產生器。
    • CUSTOMER_MESSAGE:只在每則顧客訊息後觸發產生器。
    • AGENT_MESSAGE:只在每個代理程式訊息後觸發產生器。

生成器輸出內容

提供文字生成器輸入內容後,自訂生成式 AI 輔助生成器會提供建議,例如文章連結、適當的回覆,或促銷優惠的後端資訊。這些建議會以文字格式提供,且與生成時的客戶服務對話內容相關。

用途

本節提供三個使用案例,說明如何實作「自行建構生成式 AI 輔助生成器」。模型可能會生成與下列範例不同的輸出內容。

專業改寫

你可以指示生成器以專業、禮貌和同理心的方式重新措辭,然後再回覆顧客,如下所示。

  • 生成器名稱:專業重寫
  • 觸發條件事件:服務專員訊息
  • 指示:

    # TASK DESCRIPTION:
    Output the agent's response under ## LAST UTTERANCE rewritten in a professional, polite and empathetic way in EXAMPLE 4.
    - DO NOT miss any information mentioned by the original text.
    - Only output rewritten response.
    - You're provided with EXAMPLE 1-3. Follow the format.
    
    # EXAMPLE 1
    ## CONVERSATION:
    AGENT: Yo what's up it's Akshay. This is Amazon customer service. What do you want?
    
    ## LAST UTTERANCE:
    Yo what's up it's Akshay. This is Amazon customer service. What do you want?
    
    ## OUTPUT:
    Hi I'm Akshay. Thank you for choosing Amazon customer service. How can I assist you today?
    
    # EXAMPLE 2
    ## CONVERSATION:
    CUSTOMER: Hi, I'm having some trouble with my Apple Music subscription.
    AGENT: Hey, I'm [name]. I can help, I guess. What's your name and account number?
    CUSTOMER: Sure, my name is [name] and my account number is [number].
    AGENT: Alright. Checked that out. You are on Apple Music Individual plan, right?
    
    ## LAST UTTERANCE:
    Alright. Checked that out. You are on Apple Music Individual plan, right?
    
    ## OUTPUT:
    Thank you. I see that you're currently subscribed to the Apple Music Individual plan. Is that correct?
    
    # EXAMPLE 3
    ## CONVERSATION:
    AGENT: What is your order number?
    CUSTOMER: 12345
    AGENT: Hang on a sec. Looking.
    CUSTOMER: I'll wait.
    AGENT: Alright, it appears your order is not registered. Did you even submit the order?
    CUSTOMER: Let me double check. Shoot, someone canceled it. Must be the kids.
    AGENT: Yeah, watch your kids will you?
    CUSTOMER: I'm so sorry.
    AGENT: All good. Have a good one.
    
    ## LAST UTTERANCE:
    All good. Have a good one.
    
    ## OUTPUT:
    No problem. I'm glad I can help. Please have a good day!
    
    # EXAMPLE 4
    ## CONVERSATION:
    ${parameter:transcript}
    
    ## LAST UTTERANCE:
    ${parameter:transcript_last_utterance}
    
    ## OUTPUT:
    

顧客留存率

你也可以指示生成器建議有助於留住顧客的客服人員回覆,例如提供產品折扣、追加銷售或交叉銷售產品,以及解決問題,如下例所示。生成器會透過 IngestContextReferences API 存取您提供的折扣和優惠資訊,做為情境參考資料。

  • 生成器名稱:客戶流失與續留
  • 觸發條件事件:消費者訊息
  • 內容參照:優惠
    • 一:11% 折扣
    • Nest:5% 折扣
    • 新客折扣:10%
  • 指示:

    # TASK DESCRIPTION:
    You are an Agent who is helping a customer resolve an issue with complete understanding of the same.
    - Make sure you wait to understand the concern or query before making any suggestions.
    - If the customer informs about the issue, you need to ask the exact reason. If the reason is valid, you can give appropriate credit from the OFFERS section.
    - If the customer is about to cancel an order or subscription, make sure you offer something from the OFFERS section and try to retain the customer.
    - If a customer is inquiring about a new product, offer some combo for upselling another product.
    Below are two examples for detecting churn and generating suggestions for mitigation.
    The output should be a single message suggested to the agent according to the context of the conversation.
    
    # EXAMPLE 1
    Customer: Hello
    Agent: Welcome to Google. How may I help you?
    Customer: I want to cancel order.
    Agent: Sure Let me have an order ID.
    Customer: Its 123321
    Agent: I could see that you placed an order for Google Nest. May I know the reason for cancellation?
    Customer: It's available at cheaper rate now. 
    Agent: Ohh.! I see. Let me check the current price and adjust the order price. Is it okay ?
    Customer: Sure..! I can purchase the product  as long as I can get it at the discounted price. I'd definitely go with it
    Agent: Google Nest costs $200 at present. I can see that you paid $230.
    Customer: Yeah. Can you request to refund $30. I can buy it at $200.
    Agent : Sure. I have updated. You will get $30 refund once your order is delivered.
    Customer: Thanks.
    Agent : Welcome
    
    # EXAMPLE 2
    Customer: Hello
    Agent: Welcome to Google. How may I help you?
    Customer: I am having Google One Subscription. I think I may need some more space in future. 
    Agent: Okay. May I have your customer Id:
    Customer: Its 123321
    Agent: I could see that you have 100GB Plan at present. How much are you expecting to need in future?
    Customer: I think I may need 100GB or more.
    Agent: I could check that you are a loyal customer who had subscriptions since last 6 months. I can provide you 10% discount. 
    Customer: Sure..! That would be great. 
    Agent: 200GB Subscription costs $180 per annum which I can offer you at $162.
    Customer: That's cool. Thank you.
    Agent: Is there anything else I can help you with?
    Customer: No thanks.
    
    ## CONTEXT
    ${parameter:transcript}
    
    ## OFFERS
    ${parameter:offers}
    

建立產生器

下列範例說明如何建立「打造專屬的 GenAI 輔助文字產生器」。

控制台

如要使用 Agent Assist 控制台建立產生器,請按照下列步驟操作:

  1. 前往控制台的「Build-your-own-assist」Build-your-own-assist頁面。

    前往「Build-your-own-assist」(打造專屬的輔助功能)

  2. 點選「建立」

  3. 輸入產生器的名稱。

  4. 從清單中選取觸發事件。

  5. 輸入指令來定義工作。

  6. 按一下「模型選項」,然後從清單中選取模型。

  7. 設定參數或使用預設設定。

  8. 按一下「儲存」,然後再次按一下「儲存」,即可儲存產生器。

REST

如要使用 API 建立產生器,請按照下列步驟操作:

  1. Generator 資源呼叫 CreateGenerator 方法。
  2. description 欄位中輸入產生器名稱。
  3. 輸入觸發事件。
  4. FreeFormContext.text 中輸入指令,定義工作。
  5. published_model 欄位中輸入模型名稱,或將欄位留空以使用預設模型。
  6. inference_parameter 欄位中指定模型參數,或將欄位留空以使用預設值。

參數

如要讓指令具有脈絡,請使用 ${parameter:<parameter_name>} 格式將字詞標示為參數。您也可以在對話中呼叫 IngestContextReferences 方法,使用資料擷取 API 匯入參數的實際值。使用這個方法時,系統會在執行階段將指令中的參數替換為對應值。

以下是 JSON 範例,說明如何呼叫 IngestContextReferences 匯入參數值:

{
  "contextReferences": {
    "glossary": {
      "contextContents": [
        {
          "content": "east one",
          "contentFormat": "PLAIN_TEXT"
        }
      ]
    }
  }
}

此外,有些產生器參數不需要擷取。這些內建參數包括:

  • ${parameter:transcript}:代理程式和使用者之間的對話,包括使用者最後一次說出的話。
  • ${parameter:transcript_last_utterance}:對話中的最後一句話。

任何指令都應至少使用一個內建參數。

無論是內建或擷取,生成器參數都與建立生成器時設定的模型選項不同。這些產生器參數的值來自對話轉錄稿或擷取的資料。另一方面,您會為整個產生器設定模型選項的值。

測試產生器

在「Build your own GenAI assist」控制台中,您可以在「Test generator」部分測試生成器。

如要在「Build your own GenAI assist」控制台中測試生成器,請按照下列步驟操作:

控制台

  1. 新增對話的轉錄稿。您可以手動輸入語句,也可以點選「上傳」,上傳 JSON 格式的轉錄稿。
  2. 如要新增需要擷取的資料,請按一下 more_vertnote_add「新增插入資料」

「Build your own GenAI assist」控制台會顯示生成的附註回應,並標註生成器的名稱。

REST

如要使用 API 測試產生器,請按照下列步驟操作:

  1. generatorName 欄位中輸入產生器名稱。
  2. 在「conversationContext」欄位中提供對話。
  3. contextReferences 欄位中提供參數值 (如有)。
  4. triggerEvents 欄位中輸入生成建議的觸發條件。 系統會在 generatorSuggestion 欄位中顯示生成的建議。

對話設定檔

對話設定檔會定義一組參數,用來控管對話期間的建議。下列步驟會建立含有 HumanAgentAssistantConfig 物件的 conversationProfile 資源。

控制台

  1. Agent Assist 控制台中,前往「Conversation profiles」頁面。
  2. 點選「+ 建立」
  3. 輸入顯示名稱。
  4. 選取建議類型 check_box「Build-your-own-assist」Build-your-own-assist
  5. 輸入生成器的名稱,或從清單中選擇生成器的名稱。

REST

  1. 對話設定檔資源呼叫 create 方法
  2. 為新的對話個人資料命名。
  3. 輸入語言代碼。
  4. 在 human_agent_suggestion_config 中輸入產生器名稱。

以下是會話設定檔的 JSON 範例。

{
  "displayName": "build-your-own-assist-test",
  "humanAgentAssistantConfig": {
    "humanAgentSuggestionConfig": {
      "generators": "projects/PROJECT_ID/locations/global/generators/GENERATOR_ID"
    }
  }
}

使用模擬工具驗證

您可以在 Agent Assist 模擬工具中驗證對話設定檔。模擬器會顯示生成的註解回覆,並附上生成器的名稱。

測試提示

在「Build your own GenAI assist」控制台中,您可以透過模擬工具測試提示,驗證對話設定檔。下圖顯示的生成輸出內容,說明 freeform-tool-test1 生成器遵循範例提示的程度。

執行階段對話

「對話」是指服務專員 (包括真人虛擬服務專員) 與支援服務客戶或使用者之間的互動。在執行階段,當使用者與真人服務專員開始對話時,您會建立對話。如要查看建議,您必須建立使用者參與者和真人服務專員參與者,並將他們加入對話。

建立對話

如要建立對話,請按照下列步驟操作:

  1. conversation resource 呼叫 create 方法。
  2. 使用任何要求資料之前,請先替換以下項目:
    • PROJECT_ID:您的專案 ID
    • CONVERSATION_PROFILE_ID:您的對話設定檔 ID

HTTP 方法和網址:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations

JSON 要求內文:

{
  "conversationProfile": "projects/PROJECT_ID/conversationProfiles/CONVERSATION_PROFILE_ID",
}

在 JSON 回應中,conversations 後方的路徑區段包含新的對話 ID。JSON 回應應類似如下:

{
  "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID",
  "lifecycleState": "IN_PROGRESS",
  "conversationProfile": "projects/PROJECT_ID/conversationProfiles/CONVERSATION_PROFILE_ID",
  "startTime": "2023-11-05T21:05:45.622Z"
}

建立使用者參與者

如要建立使用者參與者,請按照下列步驟操作:

  1. participants 資源呼叫 create 方法。
  2. 使用任何要求資料之前,請先替換以下項目:
    • PROJECT_ID:您的專案 ID
    • CONVERSATION_ID:您的對話 ID

請提供對話 ID,並在角色欄位中輸入「END_USER」,如下所示。

HTTP 方法和網址:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_ID/participants

JSON 要求內文:

{
  "role": "END_USER",
}

在 JSON 回應中,participants 後方的路徑區段包含新的使用者參與者 ID。JSON 回應應類似如下:

{
 "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID/participants/USER_PARTICIPANT_ID", "role": "END_USER"
}

建立真人服務專員參與者

如要建立人機代理程式參與者,請按照下列步驟操作:

  1. participants 資源呼叫 create 方法。
  2. 使用任何要求資料之前,請先替換以下項目:
    • PROJECT_ID:您的專案 ID
    • CONVERSATION_ID:您的對話 ID

請為欄位提供對話 ID 和 HUMAN_AGENT 角色,如下所示。

HTTP 方法和網址:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_ID/participants

JSON 要求內文:

{
  "role": "HUMAN_AGENT",
}

在 JSON 回應中,participants 後方的路徑區段包含新的真人服務專員參與者 ID。回覆內容應如下所示:

{
"name": "projects/PROJECT_ID/conversations/CONVERSATION_ID/participants/AGENT_PARTICIPANT_ID", "role": "HUMAN_AGENT"
}

分析訊息

生成器也能分析對話中的訊息。在對話期間,您可以新增訊息,生成器可以透過 participants 資源的 analyzeContent 方法,分析服務專員和使用者的訊息。

如要新增及分析真人服務專員訊息,請按照下列步驟操作。

  1. 呼叫 analyzeContent 方法。
  2. 使用任何要求資料之前,請先替換以下項目:
    • PROJECT_ID:您的專案 ID
    • CONVERSATION_ID:您的對話 ID
    • PARTICIPANT_ID:您的人工服務專員參與者 ID

提供對話 ID 和真人服務專員參與者 ID。要求應包含類似下列內容:

HTTP 方法和網址:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID:analyzeContent

JSON 要求內文:

{
  "textInput": {
    "text": "Bonjour, ici le service client d'ABC fishing, comment puis-je vous aider aujourd'hui ?",
    "languageCode": "en-US"
  }
}

您應該會收到類似如下的 JSON 回應:

{
  "message": {
    "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID/messages/MESSAGE_ID",
    "content": "Bonjour, ici le service client d'ABC fishing, comment puis-je vous aider aujourd'hui ?",
    "languageCode": "en-US",
    "participant": "PARTICIPANT_ID",
    "participantRole": "HUMAN_AGENT",
    "createTime": "2023-02-13T00:01:30.683Z"
  },
  "humanAgentSuggestionResults": [{
    "generateSuggestionsResponse": {
      "generatorSuggestionAnswers": [{
        "generatorSuggestion": {
          "freeFormSuggestion": {
            "response": "Hello, this is ABC fishing customer service, how can I help you today?"
          }
        },
        "sourceGenerator": "projects/PROJECT_ID/locations/global/generators/GENERATOR_ID",
        "answerRecord": "projects/PROJECT_ID/locations/global/answerRecords/ANSWER_RECORD_ID"
      }],
      "latestMessage": "projects/PROJECT_ID/locations/global/conversations/CONVERSATION_ID/messages/MESSAGE_ID"
    }
  }]
}

新增及分析使用者訊息

  1. 呼叫 analyzeContent方法。如果已為其他 Agent Assist 功能呼叫方法,請勿重複呼叫。
  2. 使用任何要求資料之前,請先替換以下項目:
    • PROJECT_ID:您的專案 ID
    • CONVERSATION_ID:您的對話 ID
    • PARTICIPANT_ID:您的人工服務專員參與者 ID

提供對話 ID 和真人服務專員參與者 ID。要求應包含類似下列內容:

HTTP 方法和網址:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID:analyzeContent

JSON 要求內文:

{
  "textInput": {
    "text": "Hi",
    "languageCode": "en-US"
  }
}

您應該會收到類似如下的 JSON 回應:

{
  "message": {
    "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID/messages/MESSAGE_ID",
    "content": "Hi",
    "languageCode": "en-US",
    "participant": "PARTICIPANT_ID",
    "participantRole": "END_USER",
    "createTime": "2020-02-13T00:07:35.925Z"
  },
  "humanAgentSuggestionResults": [{
    "generateSuggestionsResponse": {
      "generatorSuggestionAnswers": [{
        "generatorSuggestion": {
          "freeFormSuggestion": {
            "response": "Salut"
          }
        },
        "sourceGenerator": "projects/PROJECT_ID/locations/global/generators/GENERATOR_ID",
        "answerRecord": "projects/PROJECT_ID/locations/global/answerRecords/ANSWER_RECORD_ID"
      }],
      "latestMessage": "projects/PROJECT_ID/locations/global/conversations/CONVERSATION_ID/messages/MESSAGE_ID"
    }
  }]
}

如果對話已完成且未使用 analyzeContent,您可以透過 messages 資源的 batchCreate 方法,匯入及分析對話的歷史訊息。

取得建議

在對話期間,生成器也會隨時根據訊息提供建議。根據預設,系統會根據任一參與者傳送的最新訊息提供建議。你也可以指定要取得建議的訊息。系統預設會提供建議,你也可以使用下列資源取得建議。

使用內建建議

analyzeContent 的回應會附上建議。觸發的生成器會產生這些建議。JSON 要求應包含類似下列內容:

HTTP 方法和網址:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID:analyzeContent

JSON 要求內文:

{
  "textInput": {
    "text": "I want to reserve a room.",
    "languageCode": "en-US"
  }
}

使用 suggestions 資源

如要取得建議,也可以按照下列步驟操作。

  1. suggestions 資源呼叫 generate 方法。
  2. 使用任何要求資料之前,請先替換以下項目:
    • PROJECT_ID:您的專案 ID
    • CONVERSATION_ID:您的對話 ID
    • PARTICIPANT_ID:您的人工服務專員參與者 ID

請提供對話 ID、任一參與者最近的訊息 ID,以及觸發事件。如果未設定訊息 ID 欄位,系統預設會根據任一參與者的最新訊息提供建議。系統隨即會啟動與觸發事件相關聯的產生器。JSON 要求應包含類似下列內容:

HTTP 方法和網址:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_IDsuggestions:generate

JSON 要求內文:

{
  "latestMessage": "projects/PROJECT_ID/conversations/CONVERSATION_IDmessages/Message_ID",
  "triggerEvents": [ "END_OF_UTTERANCE" ]
}

使用 statelessSuggestion 資源

最後一個取得建議的方法是按照下列步驟操作。

  1. statelessSuggestion 資源呼叫 generate 方法。
  2. 使用任何要求資料之前,請先替換以下項目:
    • PROJECT_ID:您的專案 ID
    • LOCATION_ID:您的位置 ID

提供生成器、對話訊息和包含擷取資料的內容參照。系統會將擷取的資料代入生成器的指令參數。您的 JSON 要求應類似如下:

HTTP 方法和網址:

https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/locations/LOCATION_ID/statelessSuggestion:generate

JSON 要求內文:

{
  "generator": {
    "description": "Translation",
    "triggerEvent": "END_OF_UTTERANCE",
    "freeFormContext": {
      "text": "Read the conversation between agent and customer, and the last utterance. Output the last utterance from customer by following these instructions:
      - If the last utterance from AGENT, output the utterance by translating it to English.
      - If the last utterance from CUSTOMER, output the utterance by translating it to French.
      - Specific brand names and technical terms specified under 'GLOSSARY' section, such as 'Google Home,' should remain unchanged as per the glossary guidelines.

# GLOSSARY
${parameter:glossary}

# CONVERSATION:
${parameter:transcript}

# LAST UTTERANCE:
${parameter:transcript_last_utterance}

# OUTPUT: "
    }
  },
  "contextReferences": {
    "glossary": {
      "contextContents": {
        "content": "east one",
        "contentFormat": "PLAIN_TEXT"
      }
    }
  },
  "conversationContext": {
    "messageEntries": [
      {
        "text": "hi",
        "languageCode": "en-US",
        "role": "END_USER",
        "createTime": {
          "seconds": "1400000000",
          "nanos": "10000000"
        }
      },
      {
        "text": "Bonjour, comment puis-je vous aider aujourd\\'hui ?",
        "languageCode": "en-US",
        "role": "HUMAN_AGENT",
        "createTime": {
          "seconds": "1400000010",
          "nanos": "10000000"
        }
      }
    ]
  },
  "triggerEvents": [
    "END_OF_UTTERANCE"
  ]
}

配額限制

您可以在 Dialogflow 配額頁面中查看 Agent Assist 的配額和限制。建立自己的生成式 AI 輔助功能時,有下列配額限制:

名稱 說明 限制
每分鐘的產生器管理員作業數 (每個區域) 每分鐘可執行的生成器管理員作業數量上限,例如建立、列出或刪除生成器。 300
發電機 (每個區域) 單一專案可建立的產生器數量上限。 200
每個模型類型每分鐘的產生器建議作業數 (每個區域) 每分鐘可接收的每個模型類型產生器建議作業要求數量上限。 10