OVERVIEW
Virtual Assistants
Kore.ai Platform
Key Concepts
Natural Language Processing (NLP)
Accessing Platform
VIRTUAL ASSISTANTS
Virtual Assistant Builder
Virtual Assistant Types
Getting Started
Creating a Simple Bot
SKILLS
Storyboard
Dialog Task
Introduction
Dialog Builder (New)
Dialog Builder (Legacy)
User Intent Node
Dialog Node
Entity Node
Supported Entity Types
Composite Entities
Supported Colors
Supported Company Names
Form Node
Logic Node
Message Nodes
Confirmation Nodes
Bot Action Node
Service Node
Custom Authentication
2-way SSL for Service nodes
Script Node
Agent Transfer Node
WebHook Node
Grouping Nodes
Connections & Transitions
Manage Dialogs
User Prompts
Knowledge Graph
Terminology
Building
Generation
Importing and Exporting
Analysis
Knowledge Extraction
Build
Alert Tasks
Introduction
Ignore Words and Field Memory
How to Schedule a Smart Alert
Small Talk
Digital Views
Overview
Configuring Digital Views
Digital Forms
Overview
How to Configure Digital Forms
NATURAL LANGUAGE
Overview
Machine Learning
Introduction
Model Validation
Fundamental Meaning
Introduction
NLP Guidelines
Knowledge Graph
Traits
Introduction
How to Use Traits
Ranking and Resolver
Advanced NLP Configurations
INTELLIGENCE
Overview
Context Management
Overview
Session and Context Variables
Context Object
How to Manage Context Switching
Manage Interruptions
Dialog Management
Sub-Intents & Follow-up Intents
Amend Entity
Multi-Intent Detection
Sentiment Management
Tone Analysis
Sentiment Management
Event Based Bot Actions
Default Conversations
Default Standard Responses
TEST & DEBUG
Talk to Bot
Utterance Testing
Batch Testing
Record Conversations
CHANNELS
PUBLISH
ANALYZE
Overview
Dashboard
Custom Dashboard
Overview
How to Create Custom Dashboard
Conversation Flows
NLP Metrics
ADVANCED TOPICS
Universal Bots
Overview
Defining
Creating
Training
Customizing
Enabling Languages
Store
Smart Bots
Defining
koreUtil Libraries
SETTINGS
Authorization
Language Management
PII Settings
Variables
Functions
IVR Integration
General Settings
Management
Import & Export
Delete
Versioning
Collaborative Development
Plan Management
API GUIDE
API Overview
API List
API Collection
SDKs
SDK Overview
SDK Security
SDK App Registration
Web SDK Tutorial
Message Formatting and Templates
Mobile SDK Push Notification
Widget SDK Tutorial
Widget SDK – Message Formatting and Templates
Web Socket Connect & RTM
Using the BotKit SDK
Installing
Configuring
Events
Functions
BotKit SDK Tutorial – Agent Transfer
BotKit SDK Tutorial – Flight Search Sample Bot
Using an External NLP Engine
ADMINISTRATION
HOW TOs
Creating a Simple Bot
Creating a Banking Bot
Context Switching
Using Traits
Schedule a Smart Alert
Configure UI Forms
Add Form Data into Data Tables
Configuring Digital Views
Add Data to Data Tables
Update Data in Data Tables
Custom Dashboard
Custom Tags to filter Bot Metrics
Patterns for Intents & Entities
Build Knowledge Graph
Global Variables
Content Variables
Using Bot Functions
Configure Agent Transfer
Update Balance Task
Transfer Funds Task
RELEASE NOTES
  1. Home
  2. Docs
  3. Virtual Assistants
  4. How Tos
  5. How to Manage Context Switching

How to Manage Context Switching

In this How-To, we will explore a scenario in a Banking Bot, where, sharing the context across intents, FAQs helps in improving the user experience and efficiency of the Bot. Also, we will be looking at how the context can be used within a dialog flow to determine the sequence of events.

For details on what Context Management is and how it is implemented in the Kore.ai Bots platform, refer here.

Problem Statement

Consider a Banking Bot trying to address the following scenarios:

  • Sharing content across intents – Once the user has entered his/her account number, they should not be prompted for the same again in the course of the conversation.
    User: I want to transfer $200 from my account
    Bot: Sure, may I have your account number?
    // (initiating Transfer Amount task)
    User: It’s 2343544
    Bot: What is the payee account number
    User: Wait, do I have sufficient funds
    // (transferring to Get Balance task)
    Bot: What is your account number

    Ideally, Get Balance should not be asking for the account number.
  • Context-based dialog flow – Based upon the context, the flow of a given task might change with the Bot making an explicit call to another task as a sub-dialog.
    Extending the above example:
    User: I want to transfer $200 from my account
    Bot: Sure, may I have your account number?
    // (initiating Transfer Amount task)
    User: It’s 2343544
    Bot: What is the payee account number
    User: 4355403
    Bot: What is your account number?
    // (transferring to Get Balance task to check for sufficient funds)
    User: It’s 2343544
    Bot: Current balance is $1200
    Bot: Amount $200 has been debited from your account.
    //(resuming Transfer Amount task)

    Ideally, Get Balance should not ask for the account number and should not display the balance message. It should happen in the background between the two tasks, without user knowledge.
  • Follow-up Intents – Access to certain tasks could be restricted due to security reasons or business requirements.
    For example, updating account balances should be restricted to Transfer Amount flow. Update Account task should not be available directly to the User nor any other task in the Bot.
  • Sharing context between intent and FAQs – During a task, the user might ask a generic question but within the context.
    For example, while transferring an amount, the user might ask about rates and the Bot needs to respond with the FAQ related to funds transfer rates.
  • Sharing content across FAQs – A specific question might be a follow up of a previous query.For example, “What are the interest rated for credit cards?” followed by “What are the charges?”, the charges reference is to the credit cards.

This document gives a detailed step-by-step approach to achieving all the above-mentioned scenarios using – context tags and variables, input pre-conditions and output context, and emit entity value features of the platform.

Pre-requisites

  • Bot building knowledge
  • A Banking Bot with the dialogs as mentioned below:
    • Get Balance – Dialog task prompting the user for their Account Number and displaying the available balance in the account.
    • Transfer Funds – Dialog task prompting the user for Payer and Payee account numbers and the amount to be transferred and transferring the specified amount from the payer account to the payee account.
    • Update Account – Dialog task prompting the user for Account Number that needs to be updated, the Amount to be updated and whether the amount needs to be credited or debited and updating the Account balance accordingly.
    • Knowledge Collection – Frequently asked questions related to the bank.

Implementation

Let us consider each of the above scenarios one by one.

Sharing content across intents

Sharing content needs to be handled differently in the two cases mentioned:

  • Bot-driven transition – This can be handled at the time of Bot development by invoking the corresponding intent and passing the data through entity pre-assignment
  • User-driven transition – This is a bit complex since we have no way of knowing when, during the current task flow, the user would make such a request and it requires a combination of tags, entity emission, and extraction.

Task-driven Context switching

The following is the scenario where the Transfer Amount dialog invokes the Get Balance task to check if the Payer Account has sufficient funds for the transfer.

 

We will be using the Bot scoped Context Variables and Entity Pre-Assignments to achieve this.

Steps:

We need to invoke Get Balance from Transfer Amount, check for funds and proceed accordingly

  1. Open the Transfer Amount dialog
  2. Add a Dialog Node, Bot Action Node with a Script Node, and a Message Node as follows:
    1. Dialog Node will invoke the Get Balance using the Entity Pre-Assignments to populate:
      • Account Number – entity required in the Get Balance dialog set to Payer Account number
      • Add Key/Value – pair context.type and transfer identifying the Transfer Amount intent. This will be checked in the Get Balance dialog as shown in the next step to modify the flow.
      • Ensure that the Transition Option is set to Initiate Get_Balance, once complete return to this node
    2. Script NodeCheckBalance to check the balance in the payer account with the amount to be transferred and proceed accordingly. Balance in the payer account is obtained from a BotContext variable that will be populated by the Get Balance dialog.
      • JavaScript:
        var nextStep = “”;
        if (context.session.BotUserSession.Balance >= context.entities.Amount)
           nextStep = “update”;
        context.nextStep = nextStep;

      • Connection Settings Bot Action Connections should indicate to proceed to UpdateBalance in case of sufficient funds (if the context.nextStep is update from the above script) else go to message node.
    3. Message Node to display the insufficient funds message

Next, let us modify the Get Balance dialog to check for transfer tag and populate the Bot Context variable if needed.

  1. Open the Get Balance dialog
  2. Open the BalanceMessage (the final message node) node
  3. Under Bot Responses section open the Manage Responses dialog
  4. Add the following JavaScript. This script populates the Bot Context variable with Account Balance if the request comes from Transfer Amount task else displays the usual balance message.
    if (context.type == "transfer")
      BotUserSession.put('Balance', context.GetAccountBalance.response.body.Balance);
    else
      print ('The Balance in your account is ' + context.GetAccountBalance.response.body.Balance);
    

Test the Bot to see the changes in action.

User triggered context switching

The following is an example of this use case. Users can at any point and time during the Transfer Amount check account balance before proceeding with the transfer.

Let us see how this can be achieved. We will be using historic tags – system generated and custom tags. The historic tags get transmitted from one intent to another automatically.

Steps:
First, modify the Transfer Amount to populate the appropriate tags and configure the Hold and Resume settings:

  1. Open the Transfer Amount dialog
  2. Open the properties panel of PayerAccount entity
  3. From the NLP tab, set the Auto emit the entity values captured flag. This will ensure that the Payer Account number is saved in the context. Since it is the first value being emitted by this intent, it would be positioned next to the intent name in the tags array
  4. Next, open the Manage Interruptions dialog from the more (vertical ellipses) option
  5. Customize the settings for this task as Allow hold and resume and set the Hold Options to Hold the current task and resume back once the new task is completed and the Resume Options to Resume the on hold task without any specific message to the user.

Next, modify the Get Balance dialog to capture the data sent by the Transfer Amount

  1. Open the Get Balance dialog
  2. Add a Script nodeCheckAcId to check if the Account Number is available in the context, after the Intent node
  3. Add the following script. This script checks for the Intent “Transfer Amount”. Captures the account number and populates the AccountNumber entity with that value.
    var i = koreUtil._.indexOf(context.historicTags[0].tags, 'Transfer Amount');
    context.entities.AccountNumber = context.historicTags[0].tags[i+1]
    

Run the Bot and see the changes taking effect.

Follow up Intents

The Update Account intent should be invoked only through Transfer Amount. There are two things that can be done:

  1. Restricting user access:
    1. Open the Update Account dialog
    2. Access Dialog Settings from the more (vertical ellipses) option
    3. Set Options to Sub intent only dialog
    4. This will restrict user access to this dialog, this dialog will not be available either directly or from the Help option.
  2. Restricting task access:
    1. Open the Update Balance dialog
    2. Open the UpdateBalance intent, NLP Properties tab
    3. Under the Manage Context section add “Transfer” to the Intent Preconditions.
      This will ensure that this dialog will be executed only if the Transfer exists in context.
    4. Open Transfer Amount dialog
    5. Open the TransferAmount intent node, NLP Properties tab
    6. Under the Manage Context section add “Transfer” to the Context Output as expected by the Update Balance dialog
    7. Now the Update Balance can not be triggered by any other dialog.

Sharing context across FAQs

The following Knowledge Collection is used in this scenario:

Primary Question: What are the interest rates for credit cards?
Primary Question: What are the charges for credit cards?
Alternate: What are the charges?

The use case is as follows:

In the second question, the word charges is in the context of the credit card. To enable it, all you need is set a flag, rest the platform takes care. For each question answered the Context tags are set automatically, we just instruct the platform to use them appropriately.

  1. Go to Natural Language -> Thresholds & Configurations
  2. Expand the Knowledge Collection tab
  3. Scroll down and set the Qualify Contextual Paths tag. With this setting, the KG engine will qualify a question if any of the available context tags are part of that particular FAQ path.
  4. Run the bot and see the effect.

Sharing context between intents and FAQs

The following Knowledge Collection is used in this scenario:

Primary Question: What are your transfer rates?
Alternate: what are the rates?

The use case here is that the user might, during the transfer amount, ask about the rates. This should result in the appropriate FAQ being triggered to answer the query.

The default setting for the Interruption Behavior for FAQs will ensure that the FAQs are attended to while a Dialog Task is in progress

But this will not solve the use case described. It would answer the direct question – “What are the transfer rates” but not “What are the rates”. The reason being the FAQ not picking the context. To ensure that the context is picked by the FAQ:

  1. The Transfer Amount task is already emitting the transfer tag, the same will be used in this case
  2. Go to Natural Language -> Thresholds & Configurations
  3. Expand the Knowledge Collection tab
  4. Scroll down and set the Qualify Contextual Paths tag (if not already set as per previous use case)
  5. Run the Bot and see the changes taking effect
Menu