Rasa SDK

3.16.1 · active · verified Thu Apr 16

Rasa SDK is the companion library to Rasa Open Source, enabling developers to write custom actions for their Rasa-powered chatbots. It provides the necessary interfaces and classes (like Action, Tracker, Dispatcher) to interact with the Rasa dialogue management and NLU components. Version 3.16.1 is the current stable release, with frequent updates for bug fixes and minor features, often in sync with Rasa Open Source releases.

Common errors

Warnings

Install

Imports

Quickstart

This example defines a simple custom action `ActionHelloWorld` that responds with a greeting. It demonstrates importing `Action`, `Tracker`, `CollectingDispatcher`, and `SlotSet`, along with the required `name()` and `run()` methods. The `run` method is made `async` to align with modern Rasa practices, though it's not strictly required for simple actions. To use this action, save it as `actions.py` and run it with `rasa run actions` in a separate terminal while your Rasa bot is running. The action name must be added to your `domain.yml`.

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 ActionHelloWorld(Action):

    def name(self) -> Text:
        return "action_hello_world"

    async def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        user_name = tracker.get_slot("name")
        if not user_name:
            user_name = "there"
        
        dispatcher.utter_message(text=f"Hello {user_name}! This is a custom action.")

        return [SlotSet("name", user_name)]

# To run this, save it as actions.py and then run `rasa run actions` in your terminal.
# Ensure your Rasa project's endpoints.yml is configured to point to this action server.

view raw JSON →