Natural language conversations we have in our everyday life are made easier and more succinct by the presence of context. Things like ‘I want to buy that’ are easily communicated as long as there’s enough context to understand what ‘that’ is referring to. Contexts help you achieve this in your conversations with consumers. Expressions like these can be matched with an intent if the necessary context is provided.

To enable follow-up intents and introduce ways to structure the flow of a conversation in task bots, each intent can have entry context and exit context. This context variable will be stored for each session and the state of this variable will change based on intents that are triggered over the course of a session.

Entry and exit contexts for an intent can be configured within the intent screen in the training section for task bots.

1002

An example of a conversation utilizing contexts

In the above example:

  • The consumer asks about the process to replace their card.
  • The bot replies with various ways to apply for a replacement and asks the user if they’d like to do it now. The ‘Replacement card’ intent is completed and the configured exit context ‘replace card’ becomes active for 5 turns.
  • The user responds with ‘Yes’, which wouldn’t be enough to identify an intent on its own. Due to the presence of ‘replace card’ intent, it’s matched with ‘Replacement card – yes’ intent configured in the bot.
  • The bot starts collecting slots for the ‘replacement card – yes’ intent.

Here is a vidcast explaining contexts and how to user them:

Exit contexts

Exit contexts control the active contexts for a session. An exit context contains the context value string and the duration of that context. When an intent is completed (all the slots are filled and the final response template key is triggered), the configured exit contexts for that intent become exit for their respective durations. Developers can configure a maximum of 15 exit contexts for a particular intent. An exit context can be added by pressing the enter/return key after typing the context.

1084

Context is available under slots in the intent configuration screen

Entry contexts

Entry contexts control whether an intent can be matched with the end-user query based on the active context of the session. When context is present in a session, the following rules are applied for intent matching:

  • An intent with entry contexts will only be matched if the active context in the session already contains all the required entry context values. In other words, the entry context of an intent must be a subset of active context for it to be matched.
  • For all intents satisfying the above rule, preference will be given to intents whose input context matches the active more closely if the confidence scores for multiple intents are the same. In other words, input context will be used for tie-breaking partial matches.

Developers can configure a maximum of 5 entry contexts for a particular intent.

1084

Entry contexts control intent matching

1084

Consumer response 'yes' is matched with a follow-up intent because of context

Context duration

Each exit context has a duration to decide the number of conversational turns that context will be active for. Once the number of turns are exhausted, the context is removed from the active context. The default duration of each exit context is five conversational turns, which can be changed by clicking on the duration and providing a new value. The maximum permitted duration for an exit context is 99 turns. The duration is overridden if an intent is completed with an exit context already present in the active context. In such cases, the exit duration in active context is replaced by the duration configured in the intent that was just completed.

1012

Users can edit the duration of a context by clicking the number on the exit context pill