將交談從 Bot 切換為人類Transition conversations from bot to human

適用于: SDK v4APPLIES TO: SDK v4

無論 Bot 擁有多高的人工智慧,有時仍可能需要將交談遞交給人類。Regardless of how much artificial intelligence a bot possesses, there may still be times when it needs to hand off the conversation to a human being. 因為 Bot 不了解使用者 (因為 AI 限制),或者如果要求無法自動處理而需要人工動作,就可能必須這麼做。This can be necessary either because the bot does not understand the user (because of an AI limitation), or if the request cannot be automated and requires a human action. 在這類情況下,Bot 應辨識何時需要進行遞交,並且為使用者提供順暢的轉換。In such cases the bot should recognize when it needs to hand off and provide the user with a smooth transition.

Microsoft Bot Framework 是一個開放平台,可讓開發人員與各種代理程式參與平台進行整合。Microsoft Bot Framework is an open platform that allows developers to integrate with a variety of agent engagement platforms.

遞交整合模型Handoff integration models

Microsoft Bot Framework 支援兩個可供整合代理程式參與平台的模型。Microsoft Bot Framework supports two models for integration with agent engagement platforms. 這兩個模型的遞交通訊協定相同,不過,模型與代理程式參與平台之間的上線詳細資料有所不同。The handoff protocol is identical for both models, however the onboarding details differ between the models and the agent engagement platforms.

其目標不是提供與任何客戶系統整合的通用解決方案,而是為 bot 開發人員和系統整合者提供 共同的語言最佳作法 ,以在迴圈中建立對話式 AI 系統。The goal is not to offer a universal solution for integration with any customer's system, but rather to provide a common language and best practices for bot developers and system integrators building conversational AI systems with human in the loop.

Bot 即代理程式Bot as an agent

在第一個模型 (也稱為「Bot 即代理程式」) 中,Bot 會聯結已連線至代理程式中樞的即時代理程式排名,並回應使用者要求,猶如要求來自任何其他 Bot Framework 通道。In the first model, known as "Bot as an agent", the bot joins the ranks of the live agents connected to the agent hub and responds to user requests as if the requests came from any other Bot Framework channel. 使用者與 Bot 之間的交談可以呈報給人類代理程式,屆時 Bot 就會退出作用中交談。The conversation between the user and the bot can be escalated to a human agent, at which point the bot disengages from the active conversation.

此模型的主要優點在於其簡單性 - 現有 Bot 可以最少的付出上線至代理程式中樞,而且代理程式中樞會負責處理訊息路由傳送的所有複雜性。The main advantage of this mode is in its simplicity – an existing bot can be onboarded to the agent hub with minimal effort, with all of the complexity of message routing taken care of by the agent hub.

Bot 即代理程式案例

Bot 即 ProxyBot as a proxy

第二個模型也稱為「Bot 即 Proxy」。The second model is known as "Bot as a proxy". 使用者會直接與 Bot 交談,直到 Bot 決定其需要來自人類代理程式的協助為止。The user talks directly to the bot, until the bot decides that it needs help from a human agent. Bot 中的訊息路由器元件會將交談重新導向至代理程式中樞,進而將其分派至適當的代理程式。The message router component in the bot redirects the conversation to the agent hub, which dispatches it to the appropriate agent. Bot 會留在迴圈中,並可收集交談的文字記錄、篩選訊息,或將其他內容提供給代理程式和使用者。The bot stays in the loop and can collect the transcript of the conversation, filter messages, or provide additional content to both the agent and the user.

彈性和控制是此模型的主要優點。Flexibility and control are the main advantages of this model. Bot 可支援各種不同的通道,並可控制交談在使用者、Bot 和代理程式中樞之間呈報與路由傳送的方式。The bot can support a variety of channels and have control over how the conversations are escalated and routed between the user, the bot, and the agent hub.

Bot 即 Proxy 案例

遞交通訊協定Handoff protocol

此通訊協定是以起始、bot 傳送至通道的事件為中心,以及由通道傳送至 bot 的狀態更新。The protocol is centered around events for initiation, sent by the bot to the channel, and status update, sent by the channel to the bot.

交付初始Handoff initiation

由 bot 建立的 交付初始 事件可起始提交。The Handoff Initiation event is created by the bot to initiate handoff.

此事件包含兩個元件:The event contains two components:

  • 將交談路由至正確的代理程式所需的 交付要求內容The context of the handoff request that is necessary to route the conversation to the right agent.
  • 交談的文字 記錄The transcript of the conversation. 代理程式可在起始遞交之前,讀取客戶與 Bot 之間發生的交談。The agent can read the conversation that took place between the customer and the bot before the handoff was initiated.

以下是 [遞交初始事件] 欄位:The following are the handoff initiation event fields:

  • 名稱 -這 name 是設定為的 必要 欄位 "handoff.initiate"Name - The name is a required field that is set to "handoff.initiate".

  • - value 欄位是一個物件,其中包含代理程式中樞特定的 JSON 內容,例如必要的代理程式技能等等。Value - The value field is an object containing agent hub-specific JSON content, such as required agent skill and so on. 此為 選擇性 欄位。This field is optional.

    { "Skill" : "credit cards" }
    
  • 附件 - attachments選擇性 欄位,包含 Attachment 物件清單。Attachments - The attachments is an optional field containing the list of Attachment objects. Bot Framework 定義「文字記錄」附件類型,可用來將對話文字記錄傳送至代理程式中樞(如有需要)。Bot Framework defines the "Transcript" attachment type that is used to send conversation transcript to the agent hub if required. 您可以藉由提供的方式,將附件以內嵌 (的大小限制傳送) 或離線 ContentUrlAttachments can be sent either inline (subject to a size limit) or offline by providing ContentUrl.

    handoffEvent.Attachments = new List<Attachment> {
        new Attachment {
            Content = transcript,
            ContentType = "application/json",
            Name = "Transcript",
        }};
    

    注意

    代理程式中樞 必須忽略 他們不了解的附件類型。Agent hubs must ignore attachment types they don't understand.

  • 對話 - conversation 是一種類型的 必要 欄位, ConversationAccount 描述所要傳遞的交談。Conversation - The conversation is a required field of type ConversationAccount describing the conversation being handed over. 嚴重來說,它必須包含 Id 可用於與其他事件相互關聯的交談。Critically, it MUST include the conversation Id that can be used for correlation with the other events.

當 bot 偵測到代理程式需要將對話交給代理程式時,它會傳送一個轉換啟始事件來表示其意圖。When a bot detects the need to hand the conversation off to an agent, it signals its intent by sending a handoff initiation event. 在 c # 中,您 CreateHandoffInitiation 可以使用較高層級的 API 方法,如下列程式碼片段所示。In C# an higher level API CreateHandoffInitiation method can be used as demonstrated in the code snippet below.

var activities = GetRecentActivities();
var handoffContext = new { Skill = "credit cards" };
var handoffEvent =
    EventFactory.CreateHandoffInitiation(
        turnContext, handoffContext, new Transcript(activities));
await turnContext.SendActivityAsync(handoffEvent);

提交狀態Handoff status

代理程式中樞會將 提交狀態 事件傳送至 bot。The Handoff Status event is sent to the bot by the agent hub. 此事件會通知 bot 有關起始之遞交作業的狀態。The event informs the bot about the status of the initiated handoff operation.

注意

Bot 不是處理事件的 必要 專案,但它們 不能拒絕它Bots are not required to handle the event, however they must not reject it.

以下是 [提交狀態] 事件欄位:The following are the handoff status event fields:

  • 名稱 -這 name 是設定為的 必要 欄位 "handoff.status"Name - The name is a required field that is set to "handoff.status".

  • - value 這是 必要 的欄位,描述目前的交付作業狀態。Value - The value is a required field describing the current status of the handoff operation. 它是包含 必要 欄位 state 和選擇性欄位的 JSON 物件 message ,如下所定義。It is a JSON object containing the required field state and an optional field message, as defined below.

state具有下列其中一個值:The state has one of the following values:

  • accepted-代理程式已接受要求並取得對話的控制權。accepted- An agent has accepted the request and taken control of the conversation.
  • failed-提交要求失敗。failed- Handoff request has failed. message可能包含與失敗相關的其他資訊。The message might contain additional information relevant to the failure.
  • completed -已完成提交要求。completed - Handoff request has completed.

未指定欄位的格式和可能值 messageThe format and possible value of the message field are unspecified.

  • 成功的完成切換:Successful handoff completion:

    { "state" : "completed" }
    
  • 因為超時,導致提交作業失敗:Handoff operation failed due to a timeout:

    { "state" : "failed", "message" : "Cannot find agent with requested skill" }
    
  • - 交談 Conversation這是類型的 必要 欄位, ConversationAccount 描述已接受或已拒絕的交談。Conversation -Conversationis a required field of type ConversationAccount describing the conversation that has been accepted or rejected. Id交談的必須與起始遞交的 HandoffInitiation 相同。The Id of the conversation MUST be the same as in the HandoffInitiation that initiated the handoff.

切換程式庫Handoff library

已建立 提交程式庫 來補充支援遞交 BOT FRAMEWORK v4 SDK;特別:The Handoff Library has been created to complement the Bot Framework v4 SDK in supporting handoff; specifically:

  • 會執行 Bot Framework SDK 的新增功能,以支援對代理程式的 (也稱為 擴大Implements the additions to the Bot Framework SDK to support handoff to an agent (also known as escalation.
  • 包含三個事件種類的定義,用來發出信號交付作業。Contains definitions of three event types for signaling handoff operations.

注意

與特定代理程式中樞的整合不是程式庫的一部分。Integrations with specific agent hubs are not part of the library.

其他資源Additional resources