Async support in RASA

I am designing a bot where for a particular action , it would take some time to complete the action . Is it possible to come out of that action and respond when it is done in the UI so that in the mean time other actions can be done

1 Like

Hi @hemamalini, do you mean within Rasa X and a custom action? Rasa already calls remote actions in an async way, so the server should be responsive when you’re waiting for your custom action to complete

1 Like

Hi not with Rasa X. Using open source Rasa and custom ui. If some custom actions are taking time ,is it possible for the server to handle other queries and answer this when that custom action gets over

Yes, remote actions are called asynchronously, so this is already happening

1 Like

Hi @ricwo
I am having the same problem : It seems that rasa actions server is executing the custom actions sequentially .
For reference, I am providing u the logs :
My rasa model server has these properties:
2020-08-26 17:39:46 DEBUG rasa.core.tracker_store - Attempting to connect to database via ‘sqlite://:***@/rasa_server.db’.
2020-08-26 17:39:46 DEBUG rasa.core.tracker_store - Connection to SQL database ‘rasa_server.db’ successful.
2020-08-26 17:39:46 DEBUG rasa.core.tracker_store - Connected to SQLTrackerStore.
2020-08-26 17:39:46 DEBUG rasa.core.lock_store - Connected to lock store ‘InMemoryLockStore’.\

For two queries : i am giving you logs of rasa server and actions server.
Logs of rasa Model server -
Here u can see there are two users with sender_id {sbm.kumar , vi.kumar}
And two Queries - “Find Issues” and “Prediction Issues”
sbm.kumar request for “Prediction Issues” functionality which comes at 17:52:50
vi.kumar request for “Find Issues” functionality which comes at 17:52:53\

2020-08-26 17:52:50 DEBUG rasa.core.tracker_store - Recreating tracker from sender id ‘sbm.kumar’
2020-08-26 17:52:50 DEBUG rasa.core.processor - Received user message ‘/ask_predict_issues_part’
2020-08-26 17:52:50 DEBUG rasa.core.actions.action - Calling action endpoint to run action ‘action_predict_issues_part’.

2020-08-26 17:52:53 DEBUG rasa.core.tracker_store - Recreating tracker from sender id ‘vi.kumar’
2020-08-26 17:52:53 DEBUG rasa.core.processor - Received user message ‘/ask_find_issues_part’
2020-08-26 17:52:53 DEBUG rasa.core.actions.action - Calling action endpoint to run action ‘action_find_issues_part’.\

Logs of rasa actions server -
Here , at 17:52:39 - Preiction custom action runs and the actions server prints nothing until this action completes.
“api for predicting issues is called.” this api takes time .
Until this api is completed there is no log of “Find Issues” custom action.
U can check this from timestamp.
Once “action_predict_issues_part” completes then at 17:53:52 “action_find_issues_part” starts
[2020-08-26 17:52:39] “POST /webhook HTTP/1.1” 200 1842 0.019000
action_predict_issues_part
api for predicting issues is called.
action_completed\

[2020-08-26 17:53:52] “POST /webhook HTTP/1.1” 200 12050 62.046102
action_find_issues_part
action_completed\

My Observations-
The behaviour of Rasa Model server is Async and Parallel ,
But behaviour of Rasa Actions server to execute custom actions is sequential\

Kindly tell me what i can do or am i missing anything to make you understand my query.\

You’re right - the action server itself runs actions sequentially. The Rasa server however runs remote actions async

1 Like

@ricwo Thanks for your response. But I want to make it async. If 100 users will use my RASA bot then the 100th user will get response too late Kindly help me to solve it

My bot is about to go in production phase , i am just stuck to this problem Kindly help

This is already the case.

For a given user, the actions will run sequentially. For incoming messages from different users, this does not happen. The /webhooks/rest/webhook endpoint is an async endpoint.

1 Like

Hi @ricwo For different users also I am getting the same scenario - “Sequential Processing of custom actions” .
This is what I am asking . Kindly help me to solve it

If the execution of the custom action takes the same amount of time for all users, then they will most likely be processed sequentially. The ordering here is not guaranteed though

Hello I have recently faced the same problem and resolved it.

To make any custom rasa action asynchronous, you have to do following two things:

  1. declare the run() method of your custom action as async
class ActionMyCustomAction(Action):
    def name(self):
        return "action_my_custom_action"
    async def run(self, dispatcher, tracker, domain):
        '''
         write your code here
        '''
        return []
  1. Make all the functions inside run() method as async.
  • Example of making time.sleep(5) as async
await asyncio.sleep(5)
  • Example of making api calls as asynchronous
import asyncio
from aiohttp import ClientSession
async with ClientSession(headers=headers) as session:   
       async with session.post(url=url, json={"message": "hello"}) as response:
               response = await response.text()

You may also refer this link. https://knowledgesmack.blogspot.com/2022/09/creating-rasa-custom-actions.html

I hope it helps :slight_smile:

1 Like

"Hey, I am using the approach you provided for making function calls asynchronous. However, when I call the API, it takes around 2 to 3 minutes to fetch the data, but I am encountering the following error within 1 minute or even earlier: “ERROR rasa_sdk.endpoint - Exception occurred during execution of request sanic.exceptions.ServiceUnavailable: Response Timeout”

Could you please provide a solution for this?"