Pattern for gathering information in IBM Watson Conversations

In a previous post, I shared some thoughts and an approach to Recursive questions with IBM Watson’s Conversation service. The post detailed how we can collect a piece of information from users in a way that allows for that information to be provided in the initial utterance or as a response to a question from our bots.

In this post, I will extend this example and demonstrate a pattern to collect multiple pieces of information while maintaining flexibility and eliminating duplication. You can download the workspace source code from my Github account.

What are we trying to do?

The scenario is that we are creating a bot for a cloud service provider which will enable users to open a new account. Our Acme SaaS company provides three account types (Bronze, Silver and Gold) and two subscription types (Monthly and Annual). We have two entities for Account_Type and Subscription_Type and an intent for Open_Account.

I find it helpful when designing processes to be serviced by bots to map these out logically, I like to do this as follows:

Intent Entities Resolution
Open_Account Account_Type
Subscription Type
Account Opened

Creating the above mapping, particularly for complex use cases will help you identify where intents can be merged. If you get two intents with different Entity conditions but the same resolution you should merge the intents and disambiguate on the Entity values.

The above mapping identifies that we need to know the Account Type and Subscription Type before we can fulfil the request and open an account. The following diagram shows the strategy we are going to implement to fulfil our open account request.

The important thing to note from above is that we can describe the collection of the information in a recursive loop. Within the loop if a required entity is provided we save it to context, if additional entities are required we prompt for those and repeat. Once all requirements are satisfied we can fulfil the users request.

How do we do that?

To achieve this, with the dialog features of the Watson Conversation service, we will use a combination of @Entity and $Context conditions and the “continue_from” features in a single level within the dialog. Let’s take a look at the first few nodes.

screen-shot-2016-11-18-at-14-17-40Our first node matches on the intent for Open_Account and uses a “continue_ from” to go immediately to the check for @Account_Type. This node will fire if the user’s input includes a valid @Account_Type and uses it a “continue_from” to go immediately to the next entity check.

Looking at the advanced tab of @Account_Type or $account_type node, we can see that it returns no output and sets the account_type variable on the context object. We will use that context variable later to fulfil the request but also to make sure we don’t ask the user for the info twice.

{
  "output": {},
  "context": {
    "account_type": "<? @Account_Type ?>"
  }
}

Moving down the node stack at this level we do the same for Subscription_Type which if it’s present we will again use the “continue_from” and move on to check each context variable.

screen-shot-2016-11-18-at-17-55-05Our next few nodes have conditions that check if a context variable doesn’t exist and if not, prompts for the user to provide the entity. Once we have checked for $account_type and $subscription_type our final node fulfils the request (or at least says that it will).

Context variable checks and fulfilment node

Notice the use of <? $account_type ?> in the output of the last node, this inserts the values of the information collected into the response to the user.

Before wrapping up I’d like to point out one more thing you can’t see in the image above, but the nodes with conditions on the context variables (e.g. !$account_type) have complex output that uses a feature called sequential selection policy. Let’s take a look at the advanced json first then I’ll explain what it does.

{
  "output": {
    "text": {
      "values": [
        "I can help you open an account...Which option would you like?",
        "Sorry I didn't understand that...Gold account?"
      ],
      "selection_policy": "sequential"
    }
  }
}

When this node fires (i.e. when the $account_type variable is not set) it will output the first item in the values array “I can help you open an account…”. If the user fails to enter a valid @Account_Type then it will output the second item in the values array “Sorry I didn’t understand…”. With this approach you can re-prompt the user without having to introduce new nodes.

What does it all mean?

To conclude I want to point out the ways that we can interact with the Open_Account flow. If I were to ask “I’d like to open an account”, the bot would ask “what type of account?”.  If I then say “bronze” the bot will ask “monthly or annual payments?”. If I then say “monthly” the bot will fitful the request. However I could also say “I’d like to open a bronze account” in which case the bot will just ask “monthly or annual payments?”. If I say “I’d like to open a Bronze account with monthly billing” the bot will simply fitful the request.

Using this pattern we can allow the user to provide all, some or none of the information we require in the initial request. With a few nodes and one level of evaluation we can collect the information we need and even re-prompt the user where required.

As a reminder you can download the workspace I used to test this pattern on my Github account. Just download it and use the import feature in the conversation tooling to see a working example for yourself.