This page explains the basics of building an assistant with Rasa and shows the structure of a Rasa project. You can test it out right here without installing anything. You can also install Rasa and follow along in your command line.The glossary contains an overview of the most common terms you’ll see in the Rasa documentation.
In this tutorial, you will build a simple, friendly assistant which will ask how you’re doing and send you a fun picture to cheer you up if you are sad.
The first step is to create a new Rasa project. To do this, run:
rasa init --no-prompt
rasa init command creates all the files that a Rasa project needs and
trains a simple bot on some sample data.
If you leave out the
--no-prompt flag you will be asked some questions about
how you want your project to be set up.
This creates the following files:
an empty file that helps python find your actions
code for your custom actions
configuration of your NLU and Core models
details for connecting to other services
your NLU training data
your assistant’s domain
details for connecting to channels like fb messenger
your initial model
The most important files are marked with a ‘*’. You will learn about all of these in this tutorial.
The first piece of a Rasa assistant is an NLU model. NLU stands for Natural Language Understanding, which means turning user messages into structured data. To do this with Rasa, you provide training examples that show how Rasa should understand user messages, and then train a model by showing it those examples.
Run the code cell below to see the NLU training data created by
rasa init command:
The lines starting with
## define the names of your
are groups of messages with the same meaning. Rasa’s job will be to
predict the correct intent when your users send new, unseen messages to
your assistant. You can find all the details of the data format in Training Data Format.
The configuration file defines the NLU and Core components that your model
will use. In this example, your NLU model will use the
supervised_embeddings pipeline. You can learn about the different NLU pipelines
Let’s take a look at your model configuration file.
pipeline keys specify how the NLU model should be built.
policies key defines the policies that the Core model will use.
At this stage, you will teach your assistant how to respond to your messages. This is called dialogue management, and is handled by your Core model.
Core models learn from real conversational data in the form of training “stories”. A story is a real conversation between a user and an assistant. Lines with intents and entities reflect the user’s input and action names show what the assistant should do in response.
Below is an example of a simple conversation. The user says hello, and the assistant says hello back. This is how it looks as a story:
## story1 * greet - utter_greet
You can see the full details in Stories.
Lines that start with
- are actions taken by the assistant.
In this tutorial, all of our actions are messages sent back to the user,
utter_greet, but in general, an action can do anything,
including calling an API and interacting with the outside world.
Run the command below to view the example stories inside the file
The next thing we need to do is define a Domain.
The domain defines the universe your assistant lives in: what user inputs it
should expect to get, what actions it should be able to predict, how to
respond, and what information to store.
The domain for our assistant is saved in a
So what do the different parts mean?
things you expect users to say
things your assistant can do and say
template strings for the things your assistant can say
How does this fit together?
Rasa Core’s job is to choose the right action to execute at each step
of the conversation. In this case, our actions simply send a message to the user.
These simple utterance actions are the
actions in the domain that start
utter_. The assistant will respond with a message based on a template
templates section. See Custom Actions
to build actions that do more than just send a message.
Anytime we add new NLU or Core data, or update the domain or configuration, we
need to re-train a neural network on our example stories and NLU data.
To do this, run the command below. This command will call the Rasa Core and NLU train
functions and store the trained model
models/ directory. The command will automatically only retrain the
different model parts if something has changed in their data or configuration.
rasa train echo "Finished training."
rasa train command will look for both NLU and Core data and will train a combined model.
Congratulations! 🚀 You just built an assistant powered entirely by machine learning.
The next step is to try it out! If you’re following this tutorial on your local machine, start talking to your assistant by running:
Now that you’ve built your first Rasa bot it’s time to learn about some more advanced Rasa features.
Learn how to implement business logic using forms
Learn how to integrate other APIs using custom actions
Learn how to connect your bot to different messaging apps
Learn about customising the components in your NLU pipeline
Read about custom and built-in entities
You can also use Rasa X to collect more conversations and improve your assistant: