The Conversational Abstract Machine

Yan Georget
Botfuel
Published in
4 min readJul 11, 2018

In a previous post, we introduced Botfuel Dialog, an open-source Node.js SDK for building highly conversational chatbots. Today, I would like to explain how chatbots built with Botfuel Dialog are natively conversational.

What does conversational mean for a chatbot?

A chatbot is said to be conversational if it is robust to complex, non-linear conversations that contain unexpected utterances. A conversational chatbot is expected to handle these unexpected utterances gracefully.

In this article, we will focus on two types of conversations: conversations containing digressions and conversations where the user changes his mind. Other types of complex conversations exist, for example conversations where the user expresses several intents at once, but they are out of the scope of this article.

Example of a digression

Example of a change of mind

A long history of Abstract Machines

According to Wikipedia, an abstract machine, also called an abstract computer, is a theoretical model of a computer hardware or software system used in automata theory.

A well known abstract machine is the Turing Machine. A more recent, and also well known one, is the Java Virtual Machine. In this article, we will introduce Botfuel Dialog’s Conversational Abstract Machine (we are reusing the CAM acronym but our virtual machine does not share anything with the famous Categorical Abstract Machine).

The Conversational Abstract Machine

At the heart of Botfuel Dialog are the concepts of Dialog and Dialog Manager. A dialog is a piece of code that handles a fragment of a conversation. The Dialog Manager is responsible for deciding which dialog to execute next based on user input. See this for a more in-depth introduction to the concepts of Botfuel Dialog.

The Conversational Abstract Machine is the execution model of the Dialog Manager.

The two stacks

The Conversational Abstract Machine works with two stacks: the stack of dialogs to be executed next (let’s call it next) and the stack of dialogs previously executed (let’s call it previous).

Based on user input, the Dialog Manager will push dialogs to next. The use of a stack structure to handle dialogs to be executed next makes the support of digressions implicit: a digression is just another dialog pushed on top of next.

Once executed, dialogs will be moved to previous. Under certain conditions, previously executed dialogs can be resurrected and moved back to next.

Re-entrant dialogs

Such dialogs need to be declared as re-entrant (this is the case of the PromptDialog). Re-entrant dialogs are dialogs that are candidates to be re-executed after completion. When no intent can be detected, the last re-entrant dialog in previous is pushed back to next.

This mechanism allows to support changes of mind.

The instruction set

We have carefully designed a reduced set of dialog instructions for the Conversational Abstract Machine: complete, wait, triggerNext, cancelPrevious, startNewConversation. These instructions are called explicitely in the dialog, they are usually called in the dialogWillComplete hook.

The complete instruction move the current dialog to previous.

complete()

The wait instruction waits for user input and does not affects the stacks.

wait()

The triggerNext instruction completes the current dialog and pushes a new dialog to next.

triggerNext(‘Dialog3’)

The cancelPrevious instruction completes the current dialog and removes the previous one from next.

cancelPrevious()

The startNewConversation instruction starts a new conversation with two empty stacks.

startNewConversation()

Example of dialogs

Let’s see how to use CAM instructions with two simple dialogs.

PromptDialog

Using the previous instructions, the dialogWillComplete hook of the PromptDialog can be simply written as:

async dialogWillComplete(userMessage, data) {
if (data.missingEntities.size === 0) {
return this.complete();
}
return this.wait();
}

ResetDialog

The ResetDialog starts a new conversation upon completion:

async dialogWillComplete() {
return this.startNewConversation(‘greetings’);
}

Now get inspired by the many examples provided with Botfuel Dialog and play with the CAM instructions to design highly conversational chatbots!

--

--

Yan Georget
Botfuel
Writer for

X alumnus, PhD in AI, worked at Criteo as VP R&D, founded several startups, currently building next-gen chatbots at Botfuel. https://about.me/yangeorget