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

您可以使用「建構自己的 GenAI assist」功能建立文字產生器,並將其整合至 Agent Assist。文字產生器會使用 Text Bison 和 Gemini 等進階大型語言模型 (LLM),產生建議內容。您可以使用這些建議,協助客戶服務對話的雙方參與者 (例如真人服務專員和使用者)。產生器可使用 Agent Assist 內建的 LLM 呼叫,並可針對大多數 LLM 工作進行設定。如要進一步瞭解 Agent Assist 中的產生器,請參閱 Vertex AI 說明文件

發電機輸入

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

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

  • 模型選項:模型選擇和設定,可讓模型發揮最佳效能,例如溫度、輸出符記限制、Top-K 和 Top-P。產生器輸出內容會受到這些設定的限制。建立產生器時,您可以按一下「模型選項」來選擇模型並設定模型選項,也可以使用預設設定。在 Vertex AI 中,模型選項稱為「參數值」

  • 觸發事件:下列事件之一,用來指出何時啟動產生器:

    • END_OF_UTTERANCE:在輸入每個語句後觸發產生器。
    • MANUAL_CALL:只有在您明確發出 API 呼叫時才會觸發產生器。
    • CUSTOMER_MESSAGE:僅在收到每則客戶訊息後觸發產生器。
    • AGENT_MESSAGE:只在每則服務專員訊息後觸發產生器。

產生器輸出內容

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

用途

本節將舉三個使用案例為例,說明如何實作自行建構的 GenAI 輔助產生器。模型產生的輸出回應可能與以下範例不同。

專業改寫

您可以指示產生器在回覆客戶前,以專業、禮貌且具同理心的態度重新表達真人服務專員的說法,如下所示。

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

    # 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}:對話中的最後一句話。

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

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

測試產生器

在「建構自己的生成式 AI 輔助控制台」中,您可以在「測試產生器」部分測試產生器。

如要在「建構自己的生成式 AI 輔助控制台」中測試產生器,請按照下列步驟操作:

控制台

  1. 新增對話的轉錄稿。您可以手動輸入語音內容,也可以點選「上傳」,上傳 JSON 格式的轉錄稿。
  2. 如要新增更多需要擷取的資料,請按一下「more_vert」和「note_add」「Add injected data」

「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 模擬工具中驗證對話設定檔。模擬器會顯示產生的回覆,並附註產生器名稱。

測試提示

在「建構自己的生成式 AI 輔助」主控台中,您可以使用模擬工具測試提示,方法與驗證對話設定檔相同。下圖所示的產生輸出內容,說明 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