Custom Actions
A custom action can run any code you want, including API calls, database queries etc. They can turn on the lights, add an event to a calendar, check a user's bank balance, or anything else you can imagine.
For details on how to implement a custom action, see the SDK documentation. Any custom action that you want to use in your stories should be added into the actions section of your domain.
When the dialogue engine predicts a custom action to be executed, it will call the action server, with the following information:
Your action server should respond with a list of events and responses:
Running Custom Actions Directly by the Assistant
New in 3.10
You can now run Python custom actions directly on the Rasa Assistant without the need for a separate Action Server.
Building an assistant often involves executing custom logic like API calls or database queries. Traditionally, this requires an Action Server. However, for a more integrated and efficient approach, you can run custom actions written in Python directly on the Rasa Assistant. This simplifies deployment and enhances the overall efficiency of your assistant.
Benefits of Direct Custom Action Execution
- Simplified Architecture: Removes the need for a separate Action Server, reducing the complexity of your architecture and deployment process.
- Lower Latency: Improves response times by eliminating the network roundtrips required to communicate with an external Action Server.
- Unified Environment: Executes all components of your assistant within the same environment, making debugging and local development smoother.
- Cost Efficiency: Reduces infrastructure costs as there is no need to maintain an additional server for handling custom actions.
Disadvantages of Direct Custom Action Execution
- Higher Effort To Secure Rasa Environment: The Rasa assistant will need access to the same sensitive resources required by the custom actions to access remote services (i.e. tokens, credentials), which may introduce security risks. Therefore, the Rasa instance should be secured properly by running in a more protected environment.
How to Configure the Feature
To use this feature, you need to update the action_endpoint
section of the endpoints.yml
file.
Add the actions_module
field and specify the path to your custom actions Python package.
This package will be imported and used directly by the Rasa Assistant to run the actions.
For example, consider this is your project structure:
You can configure the actions_module
field in the endpoints.yml
file as follows:
This configuration is mutually exclusive with the url
field, which you would typically use for pointing to an external Action Server.
If both url
and actions_module
are specified, actions_module
will be prioritized.
info
Every time you update the custom actions code, you must restart the Rasa Assistant to reflect the changes via the
rasa run
or rasa inspect
commands.