All you need to know about Artificial Intelligence on Botnation: Advanced Features

Part 5 of 8

3.1 Contexts

The dictionary definition gives “All the circumstances in which an event occurs”. In the context of our AI, the meaning is the same and in practice it is a subset of AI rules that we associate to a part of our chatbot. Your ChatBot will therefore have different AIs depending on the context of the discussion.

It is also a good way to organize the rules by theme.

In the case of our Real Estate ChatBot, we could have specific contexts for “Purchase”, “Sale”, “Rental” and “Financing”.

To enable Contexts on your chatbot, you need to do so in the advanced settings.

The main context is the “default context”. We call the additional contexts you create “Secondary Contexts”.

The default context should always remain the main context of the chatbot.

For a Secondary Context to be considered/saved, it must contain at least one AI rule.

A Context is associated with a sequence in the sequence parameters (access via the cogwheel on the far right in the title bar of the sequence in question).

The rules of a context are applied as soon as a sequence with which it is associated is triggered.

In a context, if no default sequence is defined, if the AI does not find a corresponding rule in this context it launches a search in the default context. And if there is still no corresponding rule in the default context, the default answer of the default context is displayed.

If a default sequence has been defined in the secondary context:
Search in the secondary context AI -> if no answer -> Default answer from the secondary context.

If a default sequence has not been defined in the secondary context:
Search in the AI of the secondary context -> if no response -> Search in the AI of the default context -> if no response -> Default response of the default context.

Priority keywords are very useful to get out of a Context.

Before discovering the Tunnels, we will focus on a very useful feature in the management of keywords: the Word Libraries.

Online help:
Introduction to contexts

3.2 Keyword Libraries

These are sets of words that you can save and use as keywords in multiple chatbots and/or in different contexts within the same bot.

The management of libraries is done in the AI tab of your chatbot.

To create one, make a list of Keywords or Expressions as if it were a classic AI rule but without Priority Keywords or Negative Expressions. You can then add it to any of your bots’ AI rules.

To know : the modifications are taken into account everywhere the Library is used.

This feature is particularly useful when managing different bots with the same theme.

You are a digital agency specialized in real estate.

You create the following libraries:

And you will be able to use these Libraries in all bots that need to identify these types of assets.

And it also works across channels. You can use your libraries on your Web and Messenger chatbots equally.

Of course, you can’t use the same Library several times within the same context.

Online help:
NLP’s keywords libraries

3.3 Tunnels

Definition of a Tunnel:
This is a priority AI rule that triggers a search in another context. Optionally, an intermediate sequence can be launched.

This intermediate sequence can be used, among other things, to store in a variable a data without displaying anything in the chatbot.

Definition of a Variable :
This is data that the chatbot will store in its memory. A variable is defined by its name and its value.

EX: The Variable with the name “type_of_property” can take the value “House” or “Apartment”.

Online help:
All about variables

It is a complex logic to master but it is a very powerful tool. It will indeed allow to detect several intentions in the same sentence. The tunnel in the default context detects a first intent and then runs a search in the AI rules of another context to detect the second intent.

It is also possible to put tunnels in the secondary context and thus detect a third intention. In theory, by using cascading tunnels you can detect as many intentions as you want in the same sentence. But from a practical point of view, it is better to limit yourself to three intentions.

The best way to understand how it works is to study a practical case.


Still in our Parisian real estate chatbot, we want to detect, in natural language, the type of transaction, the type of property and the district concerned in order to launch a search in a database of ads.

So, not only does the chatbot need to understand a sentence like “I’m looking for an apartment for sale in Camden” but it also needs to translate this information into data that the search engine can understand.

Cascading tunnels and their intermediate sequences will solve this problem.

The general idea is to detect each intention one after the other .

We will need 3 contexts: The default context in which we will detect the “Transaction Type” intent, a “Property Type” context to detect that intent and finally a “Borough” Context for that intent.

Default context

We create a first “Purchase” Tunnel with the keywords corresponding to this intention and which will launch a search in the “Type of Good” Context.

And we use the intermediate sequence to store the information by assigning the value “purchase” to the “transaction_type” variable.

We then create a “Sale” Tunnel with the corresponding keywords and which will also launch a search in the “Type of asset” Context.

And we use the intermediate sequence to store the information by assigning, this time, the value “purchase” to the “transaction_tyoe” variable.

So we can see that we can have 2 different tunnels that refer to the same context but as their intermediate sequences and keywords are different, they detect two different intentions.

The chatbot can now make the difference between “I want to sell my apartment in Camden” and “I want to buy an apartment in Camden”.

“Type of asset” Context

We create a first Tunnel “Apartment” with the corresponding keywords and that will launch a search in the Context “district”.

And we use the intermediate sequence to store the information by assigning the value “apartment” to the variable “asset_type”.

We then create a “House” Tunnel with the corresponding keywords which will also launch a search in the “district” Context.

And we use the intermediate sequence to store the information by assigning, this time, the value “house” to the variable “asset_type”.

The chatbot can now make the difference between “I’m looking to sell my apartment in Camden” and “I’m looking for a house for sale in Camden”.

“District” Context

In this context, we create simple AI rules to detect each arrondissement, which will each refer to sequences in which we store the name of the district in the “district” variable.

To summarize:

In the default context, the chatbot detects the type of transaction, then searches for the type of property in the “Property type” context and finally detects the district in the “District” context.

And at each step, the chatbot stores the corresponding information in variables.

So, if the user writes “I am looking to buy an apartment in Camdem” the chatbot will detect the intentions and translate them as follows:

  • transaction_type = purchase
  • asset_type = apartment
  • district = camden

The chatbot can then launch the search in the database because this information can be used by the search engine.

Detecting multiple intents in a typed sentence is a headache for all AIs around the world. With tunnels, our platform finally offers a pragmatic and efficient solution to this problem.

3.4 How to find out which rules are in conflict?

The more advanced an AI is, the more time it takes to configure it and the more likely it is to have conflicting rules. Indeed, as soon as a new element is added (keyword, rule, context, tunnels), all the conflicts that this generates must potentially be managed.

To help you in the resolution of conflicts between several rules, we have a very useful tool which are the context and expression variables:

  • {{BN_ACTIVE_EXPRESSION}} which displays the last Expression (or keyword) that was triggered
  • {{BN_ACTIVE_CONTEXT}} which displays the last Context that was triggered

When you identify a problem in your AI it is often because the bot gave the wrong answer. You will have a solution by adding a “text” element with these two variables in the sequence of the wrong answer and replicating the error. This will tell you what Keyword or Expression triggered the response and the Context in which the error was made.

When you start using tunnels, it can happen that the ChatBot gets stuck in an infinite loop (e.g.: In Context A, a tunnel searches in Context B and finds another tunnel that returns to the first context).

In this case, our platform detects the problem, stops the ChatBot and shows you, in the conversation, the Sequence and the Context that triggered the infinite loop.

Building advanced AI is an iterative process and there is no alternative to spending a lot of time on it. This can range from a few days to several weeks depending on the complexity.

It is therefore advisable to take this information into account when drawing up your specifications and your schedule.

<< Previous part Table of contents Next part >>

Download the guide in PDF format

Create your Chatbot Easily and for Free!