借助“自行构建生成式 AI 助理”,您可以创建文本生成工具并将其与 Agent Assist 集成。文本生成工具使用先进的大语言模型 (LLM),例如 Text Bison 和 Gemini,来生成建议。您可以使用这些建议来帮助客户服务对话两端的参与者,例如人工客服人员和人工用户。生成器可以使用 Agent Assist 中的内置 LLM 调用,这些调用可以针对大多数 LLM 任务进行配置。如需详细了解 Agent Assist 中的生成器,请参阅 Vertex AI 文档。
生成器输入
文本生成工具需要以下输入:
说明:用于描述您希望文本生成工具执行的任务的文本。在 Vertex AI 中,说明称为 提示。
模型选项:模型选择和设置,用于优化模型性能,例如温度、输出 token 数量上限、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 访问您提供的有关折扣和优惠的信息,作为上下文参考。
- 生成器名称:客户流失和留存
- 触发事件:客户发送的消息
- 上下文参考:优惠
- One: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}
创建生成器
以下示例展示了如何创建“自行构建生成式 AI 助理”文本生成工具。
控制台
如需使用 Agent Assist 控制台创建生成器,请执行以下操作:
在控制台中,前往Build-your-own-assist 页面。
点击创建 。
输入生成器的名称。
从列表中选择触发事件。
输入说明以定义任务。
点击模型选项 ,然后从列表中选择一个模型。
设置参数或使用默认设置。
点击保存,然后再次点击保存以保存生成器。
REST
如需使用 API 创建生成器,请执行以下操作:
- 从 生成器 资源调用
CreateGenerator方法。 - 在
description字段中输入生成器的名称。 - 输入触发事件。
- 在 FreeFormContext.text 中输入说明以定义任务。
- 在
published_model字段中输入模型名称,或将其留空以使用默认模型。 - 在
inference_parameter字段中指定模型参数,或将其留空以使用默认值。
参数
您可以使用 ${parameter:<parameter_name>} 格式将字词标记为参数,使说明具有上下文。您还可以使用数据注入 API,通过在对话中调用 IngestContextReferences 方法来导入参数的实际值。使用此方法,说明中的参数将在运行时被其值替换。
以下是一个 JSON 示例,展示了如何通过调用 IngestContextReferences 来导入参数的值:
{ "contextReferences": { "glossary": { "contextContents": [ { "content": "east one", "contentFormat": "PLAIN_TEXT" } ] } } }
还有一些生成器参数不需要提取。这些内置参数如下:
${parameter:transcript}:客服人员与用户之间的对话,包括用户的最后一句话。${parameter:transcript_last_utterance}:对话中的最后一句话。
任何说明中都应至少使用一个内置参数。
无论是内置参数还是提取的参数,生成器参数都与创建生成器时设置的模型选项不同。这些生成器参数的值来自对话记录或提取的数据。另一方面,您可以为整个生成器设置模型选项的值。
测试生成器
在“自行构建生成式 AI 助理”控制台中,您可以在测试生成器 部分测试生成器。
如需在“自行构建生成式 AI 助理”控制台中测试生成器,请执行以下操作:
控制台
- 添加对话记录。您可以手动输入话语,也可以点击 upload 以 JSON 格式上传记录。
- 如需添加更多需要提取的数据,请依次点击 more_vert 和 note_add 添加注入的数据。
“自行构建生成式 AI 助理”控制台会显示生成的响应,并使用生成器的名称进行注释。
REST
如需使用 API 测试生成器,请执行以下操作:
- 在
generatorName字段中输入生成器名称。 - 在
conversationContext字段中提供对话。 - 在
contextReferences字段中提供参数值(如果有)。 - 在
triggerEvents字段中输入用于生成建议的触发器。 生成的建议可在generatorSuggestion字段中找到。
对话配置文件
对话配置文件定义了一组参数,用于控制对话期间提出的建议。以下步骤将使用 HumanAgentAssistantConfig 对象创建 conversationProfile 资源。
控制台
- 在 Agent Assist 控制台中,前往 对话配置文件 页面。
- 点击 + 创建。
- 输入显示名称。
- 选择建议类型 check_box Build-your-own-assist。
- 输入生成器的名称,或从列表中选择生成器的名称。
REST
以下是一个对话配置文件的 JSON 示例。
{ "displayName": "build-your-own-assist-test", "humanAgentAssistantConfig": { "humanAgentSuggestionConfig": { "generators": "projects/PROJECT_ID/locations/global/generators/GENERATOR_ID" } } }
使用模拟器进行验证
您可以在 Agent Assist 模拟器 中验证对话配置文件。模拟器会显示生成的响应,并使用生成器的名称进行注释。
测试提示
在“自行构建生成式 AI 助理”控制台中,您可以使用模拟器测试提示,就像验证对话配置文件一样。下图所示的生成输出说明了 freeform-tool-test1 生成器对示例提示的遵循情况。

运行时对话
对话是指客服人员(包括人工客服人员和虚拟客服人员)与支持客户或最终用户之间的互动。在运行时,当最终用户与人工客服之间开始对话时,您需要创建对话。如需查看建议,您必须创建最终用户参与者和人工客服参与者,并将其添加到对话中。
创建对话
如需创建对话,请执行以下操作:
- 从
conversation resource调用create方法。 - 在使用任何请求数据之前,请先进行以下替换:
- 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" }
创建最终用户参与者
如需创建最终用户参与者,请执行以下操作:
- 从
participants资源调用create方法。 - 在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:您的项目 ID
- CONVERSATION_ID:您的对话 ID
为角色字段提供对话 ID 和“最终用户”,如下所示。
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" }
创建人工客服参与者
如需创建人工客服参与者,请执行以下操作:
- 从
participants资源调用create方法。 - 在使用任何请求数据之前,请先进行以下替换:
- 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" }
分析消息
生成器还可以分析对话中的消息。在对话期间,您可以添加消息,生成器可以使用 analyzeContent 方法分析人工客服和最终用户消息,该方法来自 participants 资源。
如需添加和分析人工客服消息,请按以下步骤操作。
- 调用
analyzeContent方法。 - 在使用任何请求数据之前,请先进行以下替换:
- 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" } }] }
如需添加和分析最终用户消息
- 调用
analyzeContent方法。如果已针对其他 Agent Assist 功能调用该方法,请勿重复调用。 - 在使用任何请求数据之前,请先进行以下替换:
- 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,您可以使用消息资源中的 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 资源
获取建议的另一种方法是按照以下步骤操作。
- 从
suggestions资源调用generate方法。 - 在使用任何请求数据之前,请先进行以下替换:
- 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 资源
获取建议的最后一种方法是按照以下步骤操作。
- 从
statelessSuggestion资源调用generate方法。 - 在使用任何请求数据之前,请先进行以下替换:
- 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 |