Creating NLU-only CALM bots
Creating an NLU-only CALM bot is a powerful approach that enables you to leverage your existing NLU pipeline without relying on large language models (LLMs). This guide will show you step-by-step how to use your NLU pipeline with the new Flows primitive in Rasa Pro CALM. This is particularly helpful if you lack access to LLMs or want to transition your Story-based bots to align better with newer conversational AI technologies.
Setting Up Your NLU Pipeline for CALM
To create an NLU-only CALM bot, you need to configure your NLUCommandAdapter and integrate it with the FlowPolicy in your config.yml. Below, you'll learn how to accomplish this.
Adding the NLUCommandAdapter to Your Configuration
To translate your NLU pipeline output into something your CALM bot can understand, you need the NLUCommandAdapter
and the FlowPolicy
.
The NLUCommandAdapter
converts NLU intents and entities into commands that the FlowPolicy
uses.
Add the NLUCommandAdapter
to your config.yml
like this:
In the configuration above, the NLUCommandAdapter
is added at the end of your NLU pipeline to bridge the gap between intent/entity prediction and flow execution.
Defining Flows with NLU Triggers
With your NLU pipeline set up, the next step is to define flows that can be triggered by specific NLU intents. Here’s how to configure NLU triggers in flows.yml
.
Define the Flows with NLU triggers
The NLUCommandAdapter
uses predicted intents to start a flow. To trigger a flow using an intent, add an nlu_trigger
to your flow definition.
Below is an example flow with an NLU trigger:
It is recommended to use a confidence_threshold
to avoid accidental flow triggers due to low-confidence predictions.
info
Multiple Intents in NLU Trigger
If you want a flow to be triggered by multiple intents, list them under nlu_trigger
like this:
This configuration allows you to handle similar user queries by triggering the same flow for different intents.
Adding NLU Triggers to Default Patterns
To manage flow cancellations or specific fallback scenarios effectively, consider incorporating NLU triggers into CALM's default patterns. For instance, you can define a cancel
intent with example phrases such as 'cancel', 'stop', 'nevermind', etc., and associate it with pattern_cancel_flow
. This approach ensures a more seamless conversation flow by preemptively handling user interruptions or requests to terminate a dialogue.
info
To keep your configuration organized, it is best practice to store your customized patterns in a separate file from your main flows. This way, you can easily distinguish between patterns and flows.
Check the Default Pattern Configuration for reference when modifying the default patterns and responses.
Best Practices for using slots
Slots play a crucial role in guiding the conversation logic of a CALM bot. Here are some best practices for effectively using slots in your flows.
Branching Based on Slot Values
Use slots to store information such as user preferences, choices, or other relevant data. Then, use slot values in conditions to determine the flow of your conversation. Slots help reduce complexity by eliminating the need for multiple stories and (often) custom actions.
active_flow
in Mapping Conditions
Use When using the same entity to fill multiple slots across different flows, leverage the active_flow
attribute in mapping conditions to ensure that the right slot is filled depending on the current active flow.
Validating Slot Values
Effective slot validation is key to ensuring your bot collects accurate information. Below are ways to validate slot values:
Simple Validation with Slot Rejections
Use slot_rejections
to quickly validate values within your flows.
Add a corresponding response to your domain to prompt the user to try again:
Advanced Validation Using Custom Actions
For more complex scenarios, implement custom slot validation within a custom action. For example, you can check if a phone number is already linked to another account.
Create the custom action in actions.py
:
note
Note this custom action must follow this naming convention: validate_{slot_name}
in order for Rasa to call it automatically when the slot is collected.
Summary
In this guide, you learned how to create an NLU-only CALM bot using Rasa, starting with setting up the NLUCommandAdapter
in your configuration, defining NLU-triggered flows, using slots for conversation logic, and validating slot values. By following these steps, you can build efficient and flexible assistants that make the best use of your existing NLU resources.
For additional guidance, explore the related topics in Rasa Pro: