Version: Latest

Tutorials for CALM assistants

This tutorial is designed for those new to Rasa and chatbots. It covers essential techniques key to creating any Rasa Studio assistant, and understanding these basics will help you make significant progress in mastering Rasa Studio. You will build a CALM-based assistant that greets users, introduces itself, and assists with money transfers.

Part 1: Creating an assistant

  1. Log in as a developer or flow builder.

  2. Click the assistant dropdown and select "Create assistant project."

    image
  3. Fill in the details:

    1. Enter a unique assistant name. As you're going to create a flow to help people transfer money, it can be "transfer_money_assistant".

    2. Leave "Modern" as the mode. The advanced configuration part (action server URL and model) may remain at the default settings.

    image
  4. Finally, click the "Create assistant" button.

Part 2: Creating welcome flow

In CALM (Conversational AI with Language Models), the business logic of your AI assistant is implemented as a set of flows. Each flow describes the logical steps your AI assistant uses to complete a task. It describes the information you need from the user, data you need to retrieve from an API or a database, and branching logic based on the information collected.

A flow in Rasa only describes the logic your assistant follows, not all the potential paths conversations can take. If you're used to designing AI assistants by creating flow charts of how conversations should go, you'll see that flows in Rasa are much simpler.

To create your first flow:

  1. Select the newly created assistant.

  2. Navigate to the Flow Builder page.

  3. Click "Create flow" to begin crafting your welcome flow.

    image
  4. Enter the flow name, such as welcome_and_self_introduction. The description assists Rasa in deciding when to activate this flow, and it also helps anyone viewing your flow understand its purpose. For instance, if a user says "Hi!", the description guides the Rasa assistant to recognize welcome_and_self_introduction as the relevant flow. Therefore, in the Description field, clearly state the flow's objective, like "Greet, introduce the assistant, and ask what the user needs help with". Then, click "Save".

    image
  5. Your flow is created. Click on it to start building.

    image

Introducing the assistant

Rasa specializes in building assistants that achieve things for users. The CALM paradigm enables the native integration of LLMs with your business logic. With CALM, you simply describe your business logic using flows. Each flow contains steps to collect information from the user, call APIs, and follow branching logic.

The most important thing to notice about this business logic is that it doesn’t include any description of the user’s side of the conversation. There’s no step labeled intent, or lines describing “if the user says this and then says this”. The user’s side of the conversation is handled via Intentless Policy.

  1. For example, when a user texts "Hi," your Dialogue Understanding component (the LLMCommandGenerator) should generate a command StartFlow('welcome_and_self_introduction') as a response. In this welcome_and_self_introduction flow, we aim to greet the user with a simple "Hello!" message and introduce the assistant. To start building this flow, click the "+" icon and select the "Message" step.

    image
  2. Click "Select message" and then choose "Create message" from the menu.

    image
  3. Fill in the details:

    • Enter the name, e.g utter_greet and and message e.g "Hello! I'm Sbot, a friendly assistant created using Rasa Studio".
    • Leave the checkbox "Use Contextual Response Rephraser" checked so this message can be rephrased depending on the context of the conversation.
    • Once you're set, click "Save".
    image

Part 3: Creating money transfer flow

Let’s now build the flow that helps users in conducting money transfers, allowing LLM to activate this process when users inquire about sending money. To do it:

  1. Return to the flow list.

  2. Create a flow named money_transfer with the description: "Ask all the required questions to process a money transfer request from users." Click "Save."

    image
  3. Select the flow from the list to proceed with building it.

Collecting information about the recipient

  1. Create the "Collect Information" step to ask the user who the recipient of the transfer will be.

    image
  2. Instruct the assistant on what information to collect in this step by filling out the "Description" field. For example, "This step inquires about the recipient of the payment."

    image
  3. Create a slot to define the specific information the assistant should collect from the user's reply. Slots function as your bot's memory, acting as a key-value store to hold information provided by the user (like the name of the recepient) or gathered from external sources (like the result of a database query). To create a slot, click on the "Select or create slot" field and choose "Create slot."

    image
  4. Input recipient as a slot name. Then select Text as type — text slot is used to store textual information such as personal names, names of countries, cities, etc. Click "Save". If you're interested, take a moment to learn more about slot types.

    image
  5. Finally, generate a message that the assistant will use to collect this information from the user. To do this, click "Create message".

    image
  6. The system will automatically fill in the message name by combining the slot name with the Rasa command utter_ask, resulting in utter_ask_recipient. Enter the message content as "Who would you like to send money to?"

    image
  7. The "Use Contextual Response Rephraser" option is enabled by default. This feature enables the assistant to rephrase its responses by prompting an LLM, based on the conversation's context. It helps make the assistant's responses feel more organic and conversational. Learn more.

    image

    If you prefer full control over responses, you can manually add message variations. Simply uncheck the Rephraser checkbox and click the "Add variation" button.

    image
  8. Add as many variations as you'd like, then click "Save".

    image
  9. By default, a "Collect Information" step can be skipped if the slot is already filled. For instance, if a user says "I want to transfer money to John," the assistant will already know the recipient's name and won't need to ask this question to fill the slot. If you want the assistant to always ask the question, even if the slot is already filled, enable the "Ask before filling" option. However, in the tutorial scenario and this particular question, we can leave it disabled.

    image
  10. Leave the "Reset slot value" option enabled. This resets the slot after the flow's final steps, clearing its value and re-triggering its question in future sessions. It can be useful for slots like transfer_amount or recipient_name, which vary each session. Disabling this option keeps the slot value and skips the question if "Ask before filling" is off.

    image

Collecting information about the amount

  1. Add one more "Collect information" step to ask the user about the amount of transfer.

    image
  2. Enter the description: "This step inquires about the amount of the payment, in US Dollars".

    image
  3. Create a new slot.

    image
  4. Input amount as a slot name. Then select Float as type — it is employed for storing numerical values that can have decimal points. Click "Save".

    image
  5. Finally, generate a message that the assistant will use to collect this information from the user. To do this, click "Create message".

    image
  6. The system will automatically fill in the message with utter_ask_amount. For the message content, you might use "How much money would you like to send (in US Dollars)?"

    image
  7. You can optionally add buttons to provide the user with structured choices, streamlining the process for users to quickly select an answer. To do this, enter the desired values in the input field below the message. Press the "Enter" key after typing each value. Once finished, click "Save".

    image
  8. Leave "Ask before filling" disabled. If a user starts the conversation with "I want to transfer 50 dollars", the assistant will already fill the slot and won't to ask for the amount again. Leave "Reset slot value" enabled to ensure that the next time a user requests a money transfer, the bot will ask for the transfer amount again.

    image

Validating if funds are sufficient

In this step, we aim to verify whether the user has sufficient funds for the transfer. Ideally, this is done using a custom action (API call) to check the user's balance and return a response. However, for the first part of the tutorial, we'll use simple Logic to validate fund sufficiency.

  1. Add a "Logic" step. This type of step allows you to branch the flow based on a condition.

    image
  2. Define the condition for sufficient funds. To do this, click on the first condition to create a scenario where the amount is less than or equal to $1000. If the transaction amount is less than the available funds, it indicates sufficient funds are available. Select the first condition and set it to amount is less than or equal 1000.

    image
  3. For cases where the user does not have enough funds, we need to notify them.

    1. Create a "Message" step after the "Else" branch.

      image
    2. Add a new message named utter_insufficient_funds with the text "You don't have sufficient funds to complete this transaction". Click "Save."

      image

Confirming the request

When the user confirms they have sufficient funds, we can proceed to the next step: verifying we have correctly understood the user's request.

  1. After the first condition, add a "Collect information" step.

    image
  2. Add the description "This step asks the user to confirm the recipient and the transfer amount".

    image
  3. Create the slot and call it final_confirmation. Since you are asking a Yes or No question, you can store the result as a Boolean type.

    image
  4. Create a new assistant’s message. It will be automatically filled with the name utter_ask_final_confirmation. Enter the message "Please confirm that you want to transfer {amount} to {recipient}". We use curly brackets to reference slot values, so the amount and recipient saved from previous questions will be inserted here.

    image
  5. Enable "Ask before filling" so that the next time a user transfers money, Sbot will not automatically fill this slot and will ask for confirmation again instead.

    image
  6. Add a "Logic" step.

    image
  7. For the scenario where the user confirms the request (first conditional branch), enter the following details: final_confirmation is True.

    image
  8. For the Else branch, you don't need to create any specific condition. It will automatically cover any scenario not met in the other condition branch.

Displaying success and cancel messages

If the user confirms the transaction request, we'll provide a success message.

  1. After the final_confirmation is true branch, add a "Message" step.

    image
  2. Create a new message named utter_transfer_successful with the text "All done. {amount} has been sent to {recipient}".

    image
  3. For the Else branch, also create a new message.

    image
  4. Name it utter_cancel_transfer and add the text "Transfer canceled".

    image

Linking to Feedback flow

Let's now ask users to leave feedback on the assistant's performance. If we're building a complex assistant, the feedback piece of logic can be reused in multiple scenarios. That's why it makes sense to separate it into another flow.

  1. Add a “Link” step after both “Transfer successful” and “Transfer canceled” messages.

    image
  2. Select "Create flow" in the dropdown.

    image
  3. Name the new flow leave_feedback. To make sure it only starts after the completion of the transfer_money flow and is not triggered automatically, set its description to "Never predict StartFlow for this flow; users shouldn't be able to trigger it themselves".

    image

Part 4: Creating feedback flow

  1. Go to the leave_feedback flow that you’ve just created.

    image
  2. Start with a “Collect information“ step to ask the user if they want to leave feedback:

    • Add the description "Ask user to leave feedback".
    • Create a slot named feedback with a Boolean type.
    • Add an assistant's message with the name utter_ask_feedback and the text "Do you want to leave feedback?"
    image
  3. Following this question, insert a "Logic" step.

    image
  4. Set the first condition as feedback is true. If the user is willing to leave feedback, this branch will be activated.

    image
  5. After the Else branch — the case when the user doesn’t want to leave feedback — add a message.

    image
  6. Name the new message utter_goodbye and add the text "Thank you and have a great day!"

    image
  7. After feedback is true branch, add the “Collect information” step.

    image
  8. Enter the description: "Ask users to rate the assistant's performance".

    image
  9. Create a new slot named rating and use Float as a type, as we’ll accept the number from 1 to 5.

    image
  10. Create a new message named utter_ask_rating with the text "On a scale from 1 to 5, how would you rate your experience chatting with Sbot?". Optionally you can add buttons so user could easily pick the answer.

    image
  11. If you want, you can activate "Ask before filling" so this question won’t be skipped after each transaction.

    image

Your simple assistant is ready!

Part 5: Training and testing the assistant

Training a model is a fundamental step in developing an assistant. This process is crucial as it enables the model to learn and adapt to specific tasks or domains. By doing so, it enhances its performance, equipping it to offer meaningful and relevant responses to user inputs.

Studio users can perform direct training of their assistant within the user interface. Technical users, however, can train the same assistant on their local machine.

  1. Tick the "Ready for training" checkbox for all of the flows that you have created.

    image
  2. Click the "Train" button to initiate training.

    image
  3. In the event of a successful model training, you will see the green tick.

    image
  4. If the training process encounters an issue or fails, the following window will appear:

    image
  5. After successful training, navigate to "Try your assistant" to start interacting with your assistant.

    image

Part 6 [Advanced]: Adding a custom action

A Custom action step can execute any code you desire, including API calls, database queries, and more. Whether it's turning on the lights, adding an event to a calendar, checking a user's bank balance, or anything else you can imagine, custom actions offer extensive flexibility.

As of now, custom actions can only be implemented outside of Studio. For details on how to implement a custom action, please refer to the SDK Doc. Any custom action that you want to use in flows should be added into the actions section of your domain.

In this part of the tutorial, we are going to replace the previously created amount validation logic with a custom action.

  1. Return to the money_transfer flow.

  2. After the question about how much money you would like to transfer and before the logic branch, add a "Custom action" step.

    image
  3. Open the custom action dropdown and click "Create custom action."

    image
  4. Enter the name action_validate_sufficient_funds and a description: "Goal: Validate whether the funds are sufficient for the transfer. Requirement: Check if the slot amount is greater than 1000. If true, return a true value for the slot has_sufficient_funds. If false, return a false value for the slot has_sufficient_funds."

    image
  5. Select the first condition, the one labeled amount is less_or_equal 1000. We’ll need to replace this with validation from the custom action. Instead of amount, create a new slot.

    image
  6. Enter slot name has_sufficient_funds. Select Boolean as a type and click "Save".

    image
  7. Set the condition so that has_sufficient_funds is true.

    image
  8. Switch to an IDE to set up your own Rasa Action Server.

    To do this, you need Rasa Pro 3.7.0 or newer.

    Create a local Rasa project

    rasa init --template calm
  9. Implement the custom action that validates the amount of funds. You can copy/paste the following Python code in actions/actions.py:

    # These files contains your custom actions which can be used to run
    # custom Python code.
    #
    # See this guide on how to implement these action:
    # https://rasa.com/docs/rasa/custom-actions
    from typing import Any, Text, Dict, List
    from rasa_sdk import Action, Tracker
    from rasa_sdk.executor import CollectingDispatcher
    from rasa_sdk.events import SlotSet
    class ActionValidateSufficientFunds(Action):
    def name(self) -> Text:
    return "action_validate_sufficient_funds"
    def run(self, dispatcher: CollectingDispatcher,
    tracker: Tracker,
    domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
    # hard-coded balance for tutorial purposes. in production this
    # would be retrieved from a database or an API
    balance = 1000
    transfer_amount = tracker.get_slot("amount")
    has_sufficient_funds = transfer_amount <= balance
    return [SlotSet("has_sufficient_funds", has_sufficient_funds)]
  10. Run action server using Rasa CLI.

    rasa run actions
  11. Use a reverse proxy like ngrok to expose the action server running on your local machine to the public internet and pass this to Studio for training. This can help you with quick prototyping & testing. Optionally you can also deploy this action server in your chosen cloud environment and pass the public URL to Studio to connect with your assistant.

    ngrok http 5055
  12. In Studio paste the action server url + /webhook in Manage assistants - Advanced configuration - Action server URL:

    image
  13. Train and test your assistants again, as described in Part 5.

Part 7: Editing YAML files [Advanced]

  1. Download YAML files from Studio via Rasa CLI.

    To do this, you need Rasa Pro 3.7.0 or newer.

    Note: Make sure you pass the value for studio-url, realm-name and client-id based on variables used during your Studio deployment

    Create a local Rasa project

    rasa init --template calm

    Config connection to Studio

    rasa studio config
    ? Please enter an URL path to the Authentication Server <studio-url>/auth/
    ? Please enter an URL path to the Studio <studio-url>/api/graphql
    ? Please enter Realm Name <realm-name>
    ? Please enter client ID <client-id>

    Use the appropriate parameters if the default were changed for your Rasa Studio deployment.

    Log in to Studio as a developer

    rasa studio login --username=<username> --password=<password>

    Download assistant by assistant-name

    Run the following in the folder where your local Rasa project is located:

    rasa studio download <assistant-name> -d domain

    The download will update domain.yml and data/studio_flows.yml of the local assistant.

  2. Apply changes, you can’t apply in Studio but only in YAML:

    • edit config.yml
    • view Tracing (Observability)
    • add Analytics Data Pipeline
    • add IVR Channel with AudioCodes
    • run End-to-End Test
    • use Secrets Management
    • use PII Management
    • add markers
    • use Conversational Enterprise Search
    • add Conversation Tracking
    • set slots in flow.yml and and domain.yml
    • add NLU Triggers in flow.yml and domain.yml
    • add Generation prompt in flow.yml
    • add Flow Guards in flow.yml
  3. Train the rasa model locally using rasa CLI.

    rasa train
  4. Test your assistant with custom action using Rasa Inspector.

    rasa inspect