Skip to main content
Article
rasachatbotnludialogue-managementpythonllm-fallbackopen-sourceconversational-ai

Build a Multi-Channel Chatbot with Rasa

Use the Rasa open-source framework to scaffold a production-ready chatbot. This guide shows how to initialize a project, train your first model for intent classification, and test it locally before adding more complex features like LLM fallbacks.

intermediate30 min5 steps
The play
  1. Install Rasa and Initialize Project
    Install the Rasa open-source library using pip. Then, run the `rasa init` command to create a new project with all the necessary boilerplate files for training data (`data/`), custom logic (`actions/`), and model configuration (`config.yml`).
  2. Train Your First Model
    Navigate into your new project directory. Use the `rasa train` command to train the NLU (intent recognition, entity extraction) and dialogue management models based on the example data in your `data/` directory.
  3. Test Your Bot in the Shell
    After training completes, start an interactive session with your bot using `rasa shell`. This lets you test its responses directly in the terminal and see intent classification details for each message you send. Type `/stop` to end the session.
  4. Configure an LLM Fallback
    To handle open-domain questions, set up a fallback to call an LLM. First, define a rule in `data/rules.yml` to trigger a custom action when NLU confidence is low. Then, implement that action in `actions/actions.py` to call your preferred LLM API.
  5. Connect to a Web Channel
    To deploy your bot on a website, enable the REST channel. Add the channel configuration to `credentials.yml`. Then, run the Rasa server with the API enabled. You can now interact with your bot by sending POST requests to its webhook URL.
Starter code
#!/bin/bash
# This script installs Rasa, creates a new project, trains it, and starts a shell to chat.

# 1. Ensure you have Python 3.8 - 3.10 and pip installed

# 2. Install Rasa Open Source
# It is recommended to do this in a virtual environment
# python -m venv .venv
# source .venv/bin/activate
pip install rasa

# 3. Create a new project non-interactively
rasa init --no-prompt --path my-rasa-bot

# 4. Navigate into the project directory
cd my-rasa-bot

# 5. Train the initial model
rasa train

# 6. Run the bot and talk to it in your shell
echo "Rasa setup complete. Now running 'rasa shell' to chat with your bot."
echo "Try saying 'hello' or 'I am sad'. Type '/stop' to exit."
rasa shell
Build a Multi-Channel Chatbot with Rasa — Action Pack