Actions
Actions
Actions are the things your bot runs in response to user input.
There are four kinds of actions in Rasa:
- Utterance actions: start with
utter_and send a specific message to the user- Retrieval actions: start with
respond_and send a message selected by a retrieval model- Custom actions: run arbitrary code and send any number of messages (or none).
- Default actions: e.g.
action_listen,action_restart,action_default_fallback
Utterance Actions
To define an utterance action (ActionUtterTemplate), add an utterance template to the domain file that starts with utter_:
templates:
utter_my_message:
- "this is what I want my action to say!"
It is conventional to start the name of an utterance action with utter_. If this prefix is missing, you can still use the template in your custom actions, but the template cannot be directly predicted as its own action.
Retrieval Actions
Retrieval actions make it easier to work with a large number of similar intents like chitchat and FAQs.
Custom Actions
An action can run any code you want. Custom actions can turn on the lights, add an event to a calendar, check a user’s bank balance, or anything else you can imagine.
Rasa will call an endpoint you can specify when a custom action is predicted. This endpoint should be a webserver that reacts to this call, runs the code and optionally returns information to modify the dialogue state.
Custom Actions Written in Python
For actions written in Python, we have a convenient SDK which starts this action server for you.
The only thing your action server needs to install is rasa-sdk:
pip install rasa-sdk
The file that contains your custom actions should be called actions.py. Alternatively, you can use a package directory called actions or else manually specify an actions module or package with the --actions flag.
Execute Actions in Other Code
Rasa will send an HTTP POST request to your server containing information on which action to run. Furthermore, this request will contain all information about the conversation.
Proactively Reaching Out to the User Using Actions
You may want to proactively reach out to the user, for example, to display the output of a long-running background operation or notify the user of an external event.
Default Actions
There are eight default actions:
| Action | Description |
|---|---|
action_listen |
Stop predicting more actions and wait for user input. |
action_restart |
Reset the whole conversation. |
action_default_fallback |
Undo the last user message and utter a message that the bot did not understand. |
action_deactivate_form |
Deactivate the active form and reset the requested slot. |
action_revert_fallback_events |
Revert events that occurred during the TwoStageFallbackPolicy. |
action_default_ask_affirmation |
Ask the user to affirm their intent. |
action_default_ask_rephrase |
Ask the user to rephrase their intent. |
action_back |
Undo the last user message. |