Rethinking RASA chatbot

 HarshI.T.
4 min readJul 8, 2021

It has been a long time since we have been using RASA. I recall earlier days when I used Dialogflow and Rasa to build chatbots. It was fascinating to train your bot by single click or by single command in terminal. RASA was the framework that made Machine Learning exciting for me.

I would like to share one of my live project’s experience that made me to explore RASA architecture and take certain decisions to improve predictability of my chatbot.

Checkout architecture of RASA framework.

Rasa Architecture

User input comes from channel to Agent, Agent sends to NLU pipeline for intent prediction. Once intent is predicted, it will forward them to Dialogue Policies for decision making about next action to be taken. Next action can be a custom python script in action server or just a text utterance. that action may be a form of acknowledgement or next question following the same. It takes help of Tracker to isolate multiple user conversations.

Simple can be harder than complex — Steve Jobs
It is very difficult to build a simple system — Steve Jobs

Training a rasa bot is simple. Because of straight forward training process helps newbie to train bot without knowing coding or minimal coding knowledge so anyone can create a bot without learning AI / ML or even a Data scientist’s expertise.

It looks robust, isn’t it ? What if I say that every robust system doesn’t need to be large and complex.

The dark side of the moon 🌚

Rasa Core uses stories, domain and utterances to fulfil an intent. In short Rasa core module uses machine learning to decide if intent1 is classified then it should execute intent1’s action or intent2’s action. It predicts action to be taken when an input statement is classified into an intent, although we have already specified the rules in story file.

In other words Rasa Core uses machine learning to follow rules. WHY ? Well this is over engineering.

Over-Engineering is when someone decides to build more than what is really necessary based on speculation

Stories are used to train models that are able to generalise to unseen conversation paths. — RASA

Thus ….

  • If Intent1 has occurred before Intent2 then execute Action2
  • If Intent3 has occurred before Intent2 then execute Action3

In other words, you need to specify all conversation paths in rule based approach alternatively you specify some conversation paths in story and ML based approach will be able to predict rest of them. — sounds smart, right ? 🥸

Practically when I tried by specifying SOME conversation paths, it didn’t work expectedly and ended up adding MOST of conversation paths (close to All) because such ML models are data hungry. 🤯

Honestly adding stories in domain file was more lengthy and time consuming 😰 than writing a rule based approach.

I believe there should be a rule based approach to deal with such simple approach 😎. Fortunately Rasa has a flexibility to use any individual Rasa component as API. I required 100% precision and 100% accuracy for actions in one of my chatbot project which had more than 100 intents. I used below architecture to achieve that.

Rule Engine Approach:

Rule Engine based Architecture
Rule Engine Approach

Client: Client is any client platform that makes API call (for ex: Slack, Mobile App, Website, Skype etc.) to our server. Client has to send input statement to server and wait for response from server.

Flask API Gateway: This is API endpoint at server side, developed using Flask API framework of python. It behaves as controller to communicate with Rasa NLU and RuleEngine.

Rasa NLU Server: Rasa has flexibility to run as a program or individual modules. I started Rasa NLU module as server so our Flask endpoint will be internally calling Rasa NLU API, hosted in our machine.

Rule Engine 😎: Rule engine takes complete responsibility of Rasa core. Here difference is that you don’t need to train machine learning model. It is straight forward approach of taking action based on user’s conversation flow. It is able to take action based on detected intent, entities, context and confidence.

Rasa Core vs Rule Engine

Below is the comparison of RasaCore and RuleEngine implementation

TL;DR

You can use Rasa Core when you have few intents and simple conversation path to address. RasaCore is for those who don’t want to dirty hands on coding for channel integration, nested conversation paths or building a mature chatbot.

I recommend using Rule engine based approach if you are building serious product where accuracy and precision are key features of your product. Yes you will have to develop medium integration, rules and APIs, they will result in a mature and scalable product.

I am planning to make Rule Engine library as open source but needs some time and efforts. Let me know if you find this interesting and need Rule Engine integration in your project. Thanks for reading. Keep rocking with your bot.

--

--