Rasa RestAPI persist state and move to previous action/slot

Hello people, I am working with the Rasa REST API and an angular web application. I want to add a functionality in frontend where the user can go back to the previous slot or action, this may be even triggered by the back button from the browser.

It seems my stories are being executed right via the API, but when I stop making a request and want to go back to the previous part/action/slot in my Rasa Form, then select something and try to keep going, it does not recognize my actual position in the story and the whole user journey gets messy.

So, apparently the web application did jump back to the previous step but in the backend it did not. Now the frontend and backend are not synchronous and I have to restart the application in order to get proper results.

Does the Rasa API support some king of functionality as “going/moving to the previous step in the story” ?? How can I implement this behaviour?

Here is an example how I have integrated the API in frontend:

function send(text) {

    var dataToSend = JSON.stringify({
        "recipient_id": "user",
        "message": text
    })

  $.ajax({
        url: 'http://localhost:5005/webhooks/rest/webhook', //  RASA API
  	type: 'POST',
  	headers: {
            'Content-Type': 'application/json; charset=utf-8'
        },
        dataType: "json",
        data: dataToSend,
        success: function (data, textStatus, xhr) {
            console.log(data);

  		if (Object.keys(data).length !== 0) {
  			for (i = 0; i < Object.keys(data[0]).length; i++) {
  				if (Object.keys(data[0])[i] == "buttons") { 
  					addSuggestion(data[0]["buttons"])
  				}

  			}
  		}

  		setBotResponse(data);

  	},
  	error: function (xhr, textStatus, errorThrown) {
  		console.log('Error in Operation');
  		setBotResponse('error');
  	}
  }); 

so that I can make the following request:

curl -XPOST http://localhost:5005/webhooks/rest/webhook -d ‘{“sender”: “default”, “message”: “hello”}’ -H “Content-type: application/json”

Any help is very welcome! Thnx

hey! you probably want to use action_back, see Policies

Hi, thanks for the advice. I already checked that I have the Mapping Policy in the config.yml. But “action_back” by “/back” doesn’t seem to be working properly.

When testing the intent “/back” in the console the session remains in the part and it fails to continue with the rasa form. Am I missing something here?

I am using Rasa 1.4.1

can you please try running on the shell with rasa shell --debug ? that should give a good indication what’s going on

Hi amn41, good point, this is what I get:

First I have in my domain.yml:

intents:

  • back: triggers: action_back

and I can train the model without errors. Then when I run Rasa in debug modus:

Your input ->  /back
2020-02-05 17:50:56 DEBUG    rasa.core.tracker_store  - Recreating tracker for id 'default'
2020-02-05 17:50:56 DEBUG    rasa.core.processor  - Received user message '/back' with intent '{'name': 'back', 'confidence': 1.0}' and entities '[]'
2020-02-05 17:50:56 DEBUG    rasa.core.processor  - Logged UserUtterance - tracker now has 14 events
2020-02-05 17:50:56 DEBUG    rasa.core.policies.memoization  - Current tracker state [{'prev_action_listen': 1.0, 'intent_affirm': 1.0}, {'prev_disclaimer_action': 1.0, 'intent_affirm': 1.0}, {'prev_action_listen': 1.0, 'intent_choose': 1.0}, {'prev_redflag_action': 1.0, 'intent_choose': 1.0}, {'prev_action_listen': 1.0, 'intent_back': 1.0}]
2020-02-05 17:50:56 DEBUG    rasa.core.policies.memoization  - There is no memorised next action
2020-02-05 17:50:56 DEBUG    rasa.core.policies.mapping_policy  - The predicted intent 'back' is mapped to  action 'action_back' in the domain.
2020-02-05 17:50:56 DEBUG    rasa.core.policies.form_policy  - There is no active form
2020-02-05 17:50:56 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_2_MappingPolicy
2020-02-05 17:50:56 DEBUG    rasa.core.processor  - Predicted next action 'action_back' with confidence 1.00.
2020-02-05 17:50:56 DEBUG    rasa.core.processor  - Action 'action_back' ended with events '['UserUtteranceReverted()', 'UserUtteranceReverted()']'
2020-02-05 17:50:56 DEBUG    rasa.core.processor  - Current slot values:

So far, so good, the next predicted action is “action_back”, but if we take a look to the CURRENT TRACKER STATE I am still in the actual step, so my next answer will refer to the actual question and not to the last one:

2020-02-05 17:50:56 DEBUG    rasa.core.policies.memoization  - Current tracker state [{}, {'prev_action_listen': 1.0, 'intent_greet': 1.0}, {'prev_welcome_action': 1.0, 'intent_greet': 1.0}, {'prev_action_listen': 1.0, 'intent_affirm': 1.0}, {'prev_disclaimer_action': 1.0, 'intent_affirm': 1.0}]
2020-02-05 17:50:56 DEBUG    rasa.core.policies.memoization  - There is a memorised next action '0'

2020-02-05 17:50:56 DEBUG    rasa.core.policies.mapping_policy  - There is no mapped action for the predicted intent, 'affirm'.
2020-02-05 17:50:56 DEBUG    rasa.core.policies.form_policy  - There is no active form
2020-02-05 17:50:56 DEBUG    rasa.core.policies.ensemble  - Predicted next action using policy_0_MemoizationPolicy
2020-02-05 17:50:56 DEBUG    rasa.core.processor  - Predicted next action 'action_listen' with confidence 1.00.
2020-02-05 17:50:56 DEBUG    rasa.core.processor  - Action 'action_listen' ended with events '[]'
2020-02-05 17:50:56 DEBUG    rasa.core.lock_store  - Deleted lock for conversation 'default'.

Do you have an idea what is going wrong here? Do I have to create a custom action for this? I really don’t see it through.

Any help is welcome

HI,

Sorry, I double check my bot and I have realized that “action_back” is indeed working correctly. I just had to take a better look to the Tracker State. When navigating through the questions in my bot I could see the Tracker State was indeed changing to the previous action, I just couldn’t see the previous question, but once I responded with the right information I was able to keep the correct path in the rasa story.

Thanks for the help.