An Introduction to Chatbot Development with Rasa
Chatbots have become an increasingly popular way for businesses to interact with customers and automate tasks. From virtual assistants to customer support agents, chatbots powered by artificial intelligence are transforming how we communicate with computers.
One of the leading open source frameworks for building conversational AI is Rasa. In this in-depth guide, we‘ll cover everything you need to know to get started with chatbot development using Rasa, including key concepts, installation, training your models, testing your assistant, best practices, and real-world applications. By the end, you‘ll have a solid foundation to build your own AI-powered chatbots with Rasa.
What is Rasa?
Rasa is an open source framework for developing conversational AI assistants. It provides the building blocks for creating chatbots and voice assistants that can understand natural language, hold multi-turn conversations, and connect to messaging channels and APIs.
Unlike cloud-based chatbot platforms, Rasa allows you to host your assistant on your own infrastructure, giving you full control over your data and architecture. It‘s used by companies like Adobe, Paralegal, N26, Zurich Insurance, and more for applications like customer service, IT helpdesk automation, and internal processes.
Rasa‘s framework is based on machine learning, using natural language understanding (NLU) and dialogue management backed by neural networks. This allows it to handle the variability and ambiguity of human conversations without relying on rigid if/else logic.
Why Use Rasa for Chatbot Development?
There are a few key reasons to choose Rasa for your conversational AI projects:
-
Open source: Rasa‘s code is open to view, modify and contribute to, giving transparency and flexibility. You‘re not locked into a proprietary platform.
-
On-prem or private cloud: Rasa can be deployed on your own servers, for maximum control and data privacy, which is essential for regulated industries.
-
Extensive language support: Rasa has NLU pipelines for English and many other languages out of the box. You can also add your own by training on your data.
-
Flexible integration: Rasa‘s action server allows you to write custom code, fetch data from APIs and databases, and connect to any messaging channel.
-
Machine learning-based: Advanced NLU and dialogue management let Rasa handle contextual, non-linear conversations like a human.
-
Active community: Rasa has a large, active open source community contributing code, documentation, tutorials, and support.
How Rasa Works: Architecture Overview
To understand how to build chatbots with Rasa, let‘s look at a high-level overview of its architecture:

There are two main components in the Rasa framework:
-
Rasa NLU (Natural Language Understanding): Processes user messages to extract intents and entities. The interpreter.
-
Rasa Core: Chooses which action to take based on the conversation state (tracked in a tracker store) and a dialogue policy. Rasa Core is the dialogue management and action selector.
When a user sends a message, it first goes to the Rasa NLU interpreter to extract structured data like intents and entities. This output then goes to the tracker, which keeps the conversation state. The policy then chooses the next best action to take based on the state. That action is logged by the tracker and executed by the action server – either sending a response, making an API call, querying a database, etc.
To train a Rasa assistant, you provide training data for both NLU (in markdown or json format) and Core (as stories of example conversations). You also configure the ML pipeline and policies in a config file. Then Rasa‘s command line interface lets you train, test, and deploy your models.
Getting Started: Installing Rasa
Let‘s walk through getting Rasa installed on your machine and an initial project set up. The easiest way is using pip in a Python 3 virtual environment:
python3 -m venv ./venv
source ./venv/bin/activate
pip install rasa
You can then create a new project with:
rasa init
This will set up the files and folders for your Rasa project, including:
- Actions: Custom action code
- Data: NLU and story training data
- Models: Trained model files
- Config: Pipeline and policy configuration
- Credentials: For connecting to messaging channels
- Endpoints: For configuring tracker store and action server
- Domain: Defines the universe of your assistant – intents, entities, slots, responses, forms, actions
Creating NLU Training Data
To build an NLU model that can understand user messages, you need to provide training examples in your Rasa project‘s data directory. Rasa supports different formats like Markdown, JSON, and YAML.
Here‘s an example of some training data in the recommended Markdown format:
## intent:greet
- hey
- hello
- hi
- good morning
- good evening
## intent:inform
- my name is [Martin](name)
- I am [Jack](name)
- I‘m [Paul](name)
- call me [Amy](name)
## intent:purchase
- I‘d like to buy a [laptop](device)
- I want to purchase a [phone](device)
- Can I get a [tablet](device)?
- How much is the [desktop computer](device)
In this example, we have training examples for three intents: greet, inform, and purchase. The syntax is a heading with ##intent: followed by example phrases separated by "-". Entities are annotated with square brackets.
You would create many more examples covering the range of user expressions you expect for each intent and entity. The more examples and variety, the better your model can generalize.
Defining Domain and Dialogue Management
After you‘ve defined some NLU data, the next step is specifying your chatbot‘s domain in a domain.yml file. This defines everything your bot knows:
- Intents: The user goals your assistant can recognize
- Entities: Important keywords extracted from user messages
- Slots: Information to keep track of during a conversation (like a form filling)
- Actions: The things your assistant can do, like send a message, make an API call, etc.
- Forms: For collecting a set of related information over multiple turns
- Responses: Template responses your assistant can send
Here‘s a snippet of an example domain file:
intents:
- greet
- purchase
- inform
entities:
- device
- name
slots:
device:
type: text
name:
type: text
actions:
- action_greet
- action_purchase
- utter_ask_name
responses:
utter_greet:
- text: Hi there! How can I help you?
utter_ask_name:
- text: What‘s your name?
This domain defines the intents, entities and slots we saw in the NLU data, along with some actions and responses. Actions prefixed with action_ are custom actions that run code, while responses are template responses the bot can send.
To define the flow of conversations, you create stories in a file like data/stories.md. Stories are example conversations between a user and your assistant for different paths.
Here‘s a simple story for a purchasing flow:
## purchase path
* greet
- action_greet
* purchase{"device":"laptop"}
- slot{"device":"laptop"}
- utter_ask_name
* inform{"name":"Jack"}
- slot{"name":"Jack"}
- action_purchase
This story defines a conversation where a user:
- Greets the bot
- Expresses intent to purchase a laptop (filling the device slot)
- Provides their name when asked (filling the name slot)
- The bot then runs a custom action to handle the purchase
Training and Testing
With some training data defined, you can now train a Rasa model. The command to do this is:
rasa train
This will train an NLU model and a dialogue model based on your training data, saving them in the models directory. You can configure hyperparameters and the ML pipeline in a config.yml file.
To test your assistant, you can start a shell session with:
rasa shell
This lets you chat with your bot on the command line and see how it responds. It‘s useful for debugging and verifying your bot behaves as intended.
Rasa also provides an interactive learning mode with:
rasa interactive
This starts an interactive session where you can provide correct actions to take at each step and generate new stories. It‘s a powerful way to expand your training data and improve your model.
Best Practices for Rasa Chatbot Design
To create smooth, engaging chatbot conversations with Rasa, here are some best practices to keep in mind:
- Use a consistent persona and voice for your bot. Give it a clear role.
- Break up long messages into multiple shorter ones for readability.
- Provide clear guidance and calls to action at each step. Don‘t leave the user guessing what to do.
- Handle errors gracefully – have fallback responses for when the bot doesn‘t understand.
- Allow users to interrupt and change course. Don‘t force them down a rigid path.
- Personalize the experience by referring to information you‘ve collected like their name.
- Keep the conversation focused. Don‘t introduce too many topics at once.
- Have a clear path to escalate to a human if needed. Your bot can‘t handle everything.
- Test frequently with real users and improve based on feedback.
Integrating Rasa with Messaging Channels
Once you‘ve built and tested your Rasa chatbot, you‘ll likely want to deploy it on messaging channels where users can interact with it. Rasa provides integrations for many common platforms like:
- Your own website
- Facebook Messenger
- Slack
- Telegram
- Twilio
- Google Hangouts
- Microsoft Bot Framework
To connect your bot, you provide authentication credentials and an endpoint URL in a credentials.yml file. Rasa then uses connecters to handle sending and receiving messages from each channel.
Rasa X and the Rasa Ecosystem
Rasa X is a set of tools for developing and improving your AI assistant built on top of the open source Rasa framework. It provides a user interface for:
- Conversation-driven development, visually editing training data
- Annotating messages with intents and entities
- Reviewing conversations to flag mistakes
- Sharing your assistant with teammates
- Analytics on usage, intents, conversation paths etc.
- Model deployment and CI/CD
It gets your whole team involved in the chatbot development process and allows rapid iteration.
Other tools in the ecosystem include Rasa action server for running custom code, Rasa SDK for developing custom actions, and Rasa X/Enterprise for lifecycle management.
Real-World Chatbot Applications with Rasa
Rasa is used by hundreds of companies worldwide for a variety of conversational AI apps. Some examples include:
- TalkSpace‘s mental health chatbot for finding the right therapist
- N26 Bank‘s virtual assistant for banking queries and tasks
- Paralegal‘s legal assistant for drafting and analyzing contracts
- Zurich Insurance‘s AI claims assistant
- Airbus‘ procurement bot for supply chain FAQs
- Lemonade‘s AI claims bot for easy insurance claims filing
From answering questions to completing tasks to generating documents, Rasa chatbots streamline customer interactions and business workflows across industries.
The Future of Conversational AI
Chatbots and voice assistants have come a long way in the last few years, but there‘s still far to go to reach human-level conversation. Some key areas of research and development in the field include:
- Better natural language understanding for more complex queries and context
- Emotional intelligence – detecting emotion and responding appropriately
- Personalization based on user profiles
- Multilingual models that can converse fluently in many languages
- Multimodal assistants combining text, voice, gestures and images
As an active open source project at the forefront of conversational AI, Rasa continues to push the boundaries of what‘s possible. Rasa envisions a future where many AIs work together as an overlay on the world, helping us seamlessly access services and information through simple conversation.
By joining the Rasa community and building your own chatbots, you can be a part of shaping that future. To learn more and get started, check out the Rasa docs, tutorials, and community forum.