Local Setup for Custom Actions
This guide is for technical users who want a quick way to test out a new custom action from a local development server.
Prerequisites
This workflow requires that you already have a Rasa Pro CALM project initialized. Please see the Rasa Pro installation guide for more details
Step 1: Implement Your Custom Action
Add your custom action by creating or modifying the actions/actions.py file. Below is an example of a custom action that validates sufficient funds:
actions.py
# This file contains your custom actions which can be used to run
# custom Python code.
# See Rasa Pro Tutorial for more details https://rasa.com/docs/pro/tutorial#integrating-an-api-call
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)]
Step 2: Run the Action Server
Start the action server locally using the Rasa CLI:
rasa run actions
This command launches the action server, which runs on http://localhost:5055 by default.