构建自己的 GenAI 助手

借助“自行构建 GenAI 助手”功能,您可以创建文本生成器并将其与 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:仅在每条代理消息后触发生成器。

生成器输出

向文本生成器提供输入后,“自行构建 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 访问您提供的有关折扣和优惠的信息,以用作上下文参考。

  • 生成器名称:客户流失和留存
  • 触发事件:客户消息
  • 上下文引用:商品
    • 一:8.9 折
    • Nest:8 折
    • 新客户折扣: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. 在控制台中,前往自行构建助手页面。

    前往“自行构建助手”

  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>} 格式将字词标记为参数,从而使指令具有上下文。您还可以使用 Data Ingestion API 在对话中调用 IngestContextReferences 方法,以导入参数的实际值。使用此方法时,指令中的参数将在运行时替换为其值。

以下 JSON 示例展示了如何通过调用 IngestContextReferences 导入参数的值:

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

此外,还有一些不需要提取的生成器参数。这些内置参数如下:

  • ${parameter:transcript}:代理与用户之间的对话,包括用户的最后一句话。
  • ${parameter:transcript_last_utterance}:对话中的最后一句话语。

任何指令中都应使用至少一个内置参数。

无论是内置还是提取的,生成器参数都不同于在创建生成器时设置的模型选项。这些生成器参数的值来自对话转写或提取的数据。另一方面,您可以为生成器整体设置模型选项的值。

测试生成器

在“构建您自己的 GenAI 助手”控制台中,您可以在测试生成器部分测试生成器。

如需在“构建您自己的 GenAI 助手”控制台中测试生成器,请执行以下操作:

控制台

  1. 添加对话的转写内容。您可以手动输入语音,也可以点击上传以 JSON 格式上传转写内容。
  2. 如需添加更多需要提取的数据,请依次点击 more_vertnote_add 添加注入的数据

“构建您自己的 GenAI 助理”控制台会显示带有生成器名称注释的生成回答。

REST

如需使用 API 测试生成器,请执行以下操作:

  1. generatorName 字段中输入生成器名称。
  2. conversationContext 字段中提供对话。
  3. contextReferences 字段中提供参数值(如果有)。
  4. triggerEvents 字段中输入用于生成建议的触发器。生成的建议会显示在 generatorSuggestion 字段中。

对话资料

对话配置文件定义了一组参数,用于控制对话期间提供的建议。以下步骤将使用 HumanAgentAssistantConfig 对象创建 conversationProfile 资源。

控制台

  1. Agent Assist 控制台中,前往对话配置文件页面。
  2. 点击 + 创建
  3. 输入显示名称。
  4. 依次选择建议类型 check_box 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 模拟器中验证对话配置文件。模拟器会显示带有生成器名称注释的生成回答。

测试提示

在“构建您自己的 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 的配额和限制。“自行构建 GenAI 助手”功能存在以下配额限制:

名称 说明 限制
每分钟(每个区域)的生成器管理器操作数 限制每分钟可以执行的发电机管理器操作(例如创建、列出或删除发电机)的数量。 300
发电机(每个区域) 限制您可以在单个项目中创建的生成器数量上限。 200
每个模型类型每分钟的生成器建议操作数(每个区域) 限制每种模型类型每分钟可收到的发电机建议操作请求的数量。 10