虚拟 Agent Assist

本方法指南将引导您完成直接调用 API 来启用虚拟代理辅助功能的过程。虚拟客服助理会跟踪对话,并使用 Dialogflow 虚拟客服为人工客服提供工作流支持,以及检测数据分析意图。

如果您愿意,可以使用 Agent Assist 控制台训练模型,并使用模拟器测试其性能。如需查看相关说明,请参阅虚拟 Agent Assist 控制台教程

准备工作

您必须先实现一项或多项 Agent Assist 功能,以便与虚拟客服搭配使用,然后才能启用 Virtual Agent Assist。智能回复、常见问题解答、Agent Assist、文章建议和智能撰写功能可以单独使用,也可以与虚拟客服助理搭配使用。以下链接可将您引导至相关文档,以了解实现详情。

创建对话

当最终用户与人工或虚拟客服之间开始对话时,您需要创建对话如需查看建议,您还必须创建最终用户参与者和人工客服参与者,并将其添加到对话中。以下部分将引导您完成此过程。

首先,您必须创建一个对话:

REST

如需创建对话,请对 Conversation 资源调用 create 方法。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_ID:您的 Cloud 项目 ID
  • LOCATION_ID:您的位置 ID
  • CONVERSATION_PROFILE_ID:您在创建对话配置文件时收到的 ID

HTTP 方法和网址:

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

请求 JSON 正文:

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

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

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

conversations 后面的路径段包含新对话 ID。

Python

如需向 Agent Assist 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

def create_conversation(project_id, conversation_profile_id):
    """Creates a conversation with given values

    Args:
        project_id:  The GCP project linked with the conversation.
        conversation_profile_id: The conversation profile id used to create
        conversation."""

    client = dialogflow.ConversationsClient()
    conversation_profile_client = dialogflow.ConversationProfilesClient()
    project_path = client.common_project_path(project_id)
    conversation_profile_path = conversation_profile_client.conversation_profile_path(
        project_id, conversation_profile_id
    )
    conversation = {"conversation_profile": conversation_profile_path}
    response = client.create_conversation(
        parent=project_path, conversation=conversation
    )

    print("Life Cycle State: {}".format(response.lifecycle_state))
    print("Conversation Profile Name: {}".format(response.conversation_profile))
    print("Name: {}".format(response.name))
    return response

创建最终用户参与者

您必须将最终用户参与者和人工客服参与者添加到对话中才能查看建议。首先,将最终用户参与者添加到对话中:

REST

如需创建最终用户参与者,请对 Participant 资源调用 create 方法。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_ID:您的 Cloud 项目 ID
  • LOCATION_ID:您的位置 ID
  • CONVERSATION_ID:您的对话 ID

HTTP 方法和网址:

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

请求 JSON 正文:

{
  "role": "END_USER",
}

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

{
  "name": "projects/PROJECT_ID/locations/LOCATION_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID",
  "role": "END_USER"
}

participants 后面的路径段包含新的最终用户参与者 ID。

Python

如需向 Agent Assist 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

def create_participant(project_id: str, conversation_id: str, role: str):
    from google.cloud import dialogflow_v2beta1 as dialogflow

    """Creates a participant in a given conversation.

    Args:
        project_id: The GCP project linked with the conversation profile.
        conversation_id: Id of the conversation.
        participant: participant to be created."""

    client = dialogflow.ParticipantsClient()
    conversation_path = dialogflow.ConversationsClient.conversation_path(
        project_id, conversation_id
    )
    if role in ROLES:
        response = client.create_participant(
            parent=conversation_path, participant={"role": role}, timeout=600
        )
        print("Participant Created.")
        print(f"Role: {response.role}")
        print(f"Name: {response.name}")

        return response

创建人工客服参与者

将人工客服参与者添加到对话中:

REST

如需创建人工客服参与者,请对 Participant 资源调用 create 方法。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_ID:您的 Cloud 项目 ID
  • LOCATION_ID:您的位置 ID
  • CONVERSATION_ID:您的对话 ID

HTTP 方法和网址:

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

请求 JSON 正文:

{
  "role": "HUMAN_AGENT",
}

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

{
  "name": "projects/PROJECT_ID/locations/LOCATION_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID",
  "role": "HUMAN_AGENT"
}

participants 后面的路径段包含新的人工客服参与者 ID。

Python

如需向 Agent Assist 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

def create_participant(project_id: str, conversation_id: str, role: str):
    from google.cloud import dialogflow_v2beta1 as dialogflow

    """Creates a participant in a given conversation.

    Args:
        project_id: The GCP project linked with the conversation profile.
        conversation_id: Id of the conversation.
        participant: participant to be created."""

    client = dialogflow.ParticipantsClient()
    conversation_path = dialogflow.ConversationsClient.conversation_path(
        project_id, conversation_id
    )
    if role in ROLES:
        response = client.create_participant(
            parent=conversation_path, participant={"role": role}, timeout=600
        )
        print("Participant Created.")
        print(f"Role: {response.role}")
        print(f"Name: {response.name}")

        return response

添加最终用户的消息并获取建议

如需为对话添加和分析最终用户消息,请对 Participant 资源调用 analyzeContent 方法。响应包括一个 dialogflowAssistAnswers 字段,其中包含以下数据:

  • fulfillmentText:包含建议的回答。您可以配置系统,以便向人工客服显示此建议。
  • answer record:建议的唯一 ID。

选择建议

人工客服收到建议后,可以直接接受,也可以先进行修改,然后再传递给最终用户。如需选择建议,请使用人工客服参与者再次调用 analyzeContent。将 suggestionInput 字段设置为您选择的设置,并提供您之前收到的 answer recordtext override 字段应包含发送给最终用户的实际文本。以下是配置 suggestionInput 字段的示例:

{
  "answerRecord": "answer-record",
  "textOverride": {
    "text" : "Yes, there will be ponies.",
    "languageCode": "en-US"
  }
}

完成对话

对话结束后,请使用 API 完成对话。

REST

如需完成对话,请对 conversations 资源调用 complete 方法。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_ID:您的 GCP 项目 ID
  • CONVERSATION_ID:您在创建对话时收到的 ID

HTTP 方法和网址:

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

如需发送您的请求,请展开以下选项之一:

您应该收到类似以下内容的 JSON 响应:

{
  "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID",
  "lifecycleState": "COMPLETED",
  "conversationProfile": "projects/PROJECT_ID/conversationProfiles/CONVERSATION_PROFILE_ID",
  "startTime": "2018-11-05T21:05:45.622Z",
  "endTime": "2018-11-06T03:50:26.930Z"
}

Python

如需向 Agent Assist 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

def complete_conversation(project_id, conversation_id):
    """Completes the specified conversation. Finished conversations are purged from the database after 30 days.

    Args:
        project_id: The GCP project linked with the conversation.
        conversation_id: Id of the conversation."""

    client = dialogflow.ConversationsClient()
    conversation_path = client.conversation_path(project_id, conversation_id)
    conversation = client.complete_conversation(name=conversation_path)
    print("Completed Conversation.")
    print("Life Cycle State: {}".format(conversation.lifecycle_state))
    print("Conversation Profile Name: {}".format(conversation.conversation_profile))
    print("Name: {}".format(conversation.name))
    return conversation