How to create a partially rule-based conversation within a chat dialogue

hi, beneath the chat and intent driven conversation we want to implement parts of the communication on a rule-based level. Dependent on his previous answers (or button clicks) the user has to be led through the conversation or choices to be made. These paths along a decision tree have to be 100% accurate. We tried to implement this via buttons in the template section of stories.md but failed. Which other approaches are there to implement rule-based steps along a decision tree beneath a “normal” intent driven conversation? We’d like to have a mix of rule-based and intent driven chat if possible. Thanx for help, Rainer

Hi @RainerK,

I believe the functionality you’re looking for is something we’ve implemented as a new feature on our master version (so will be in the next major release, but isn’t out yet). That feature consists of a new MappingPolicy which maps certain intents to certain actions with full confidence and priority. With this, you’d be able to create buttons with intent payloads that would automatically map to the correct action. Does that sound like the functionality you need?

In the meantime, it takes a little bit of finagling in a custom action, where you’d define the bots actions directly based on the intent received. Check out an example from our demo bot where we wanted to map each FAQ intent to it’s answer utterance.

1 Like

hi @erohmensing , thank you for your answer! Two questions:

  1. when will the next master version be available for public?
  2. if the aim is to map a button directly to an action, why do you map it indirectly to an intent (which is already known by the button/link clicked) and then to an action and not directly to an action?

Best, Rainer

1 Like

@RainerK the master is always available on our github, that’s the glory of open source! As for when the new enhancements on master will be in a stable release, I’m not sure – maybe sometime late next month.

Button clicks are mapped to intents because they still represent user input, so when you’re writing stories, you want the button clicking to go in the * {intent} part of the story rather than the - {action} part, since the user is picking the certain intent and then the bot is doing the action in response to that intent – the user cannot do actions.

Hi, I am also looking for the same version with some intents direct mapping to actions, is that version released?

Yes @akanksha, check out the MappingPolicy – supported in both rasa 1.0.1 and if you don’t want to upgrade quite yet, rasa_core 0.14.4 (for that you’ll need rasa_nlu 0.15.0)

thanks Ella, i saw this but it will not solve the purpose I am looking, as for an intent, we can only give one trigger. Depending on the entities or slot values , I can define different actions for same intent.

What I am actually looking, does rasa provides a rules/decision tree kind of facility for dialogue management, in case i do not want to go for reinforcement learning to predict next reponse/action. Does, rasa provides any option like this so that we can model our dialogues using only rules or a combination of both rules and reinforcement learning.

Hm for this I would map the intent to a custom action, and then in the custom action you can have logic that checks the slots and returns a FollowUpAction depending on the slots and entities.

1 Like

But really, all of this is better handled in your stories. Every time you add a new story, the memoization policy memorizes it, and will predict the next action you wrote if it has seen the context before. So you can in theory create a completely decision-based bot if you put all of the different possibilites in your stories.

Hijacking since this thread is basically solved and you’re online Ella :smiley:

After using MappingPolicy, rasa will always use Keras after executing the mapped action. Is there any way to keep Memoization going? I’ve got a lot of long stories that can get derailed easily.

Hm, sounds like you haven’t added it to your stories, you’ll have to do that unless the action it triggers returns a UserUtteranceReverted(). (We’re aware that this isn’t yet possible for bot utterances and are working on it)

First off: This is awesome.

Second: This means I’d have to copy every story and shove a mapped action in there? That would multiply my stories by a factor of at least 8!

Hey @Remy!

Sorry, that was a miscommunication, you’re totally right, you shouldn’t have to add it to your stories. However this ties into what I mentioned – in order to have it not affect your stories, the action has to return UserUtteranceReverted(). We’re working on making this super easy and intuitive, but in the meantime there is a workaround if you just want to trigger a bot utterance:

The ideal way to do this would be to create a custom action that you map to: e.g.

- greet:
    triggers: action_greet

Then you would create a custom action that dispatches the utterance you want to say, and then reverts everything so that it’s like it never happened. E.g.:

class ActionGreet(Action):
    """Revertible mapped action for utter_greet"""

    def name(self):
        return "action_greet"

    def run(self, dispatcher, tracker, domain):
        dispatcher.utter_template("utter_greet", tracker)
        return [UserUtteranceReverted()]

So in this case you want greet to trigger utter_greet, but use action_greet as the triggered action to do the work of both sending the utterance and reverting the mapped action. Hope that helps!

P.S. We’re going to change the documentation a little to make all of this more clear. Thanks for asking questions :slight_smile:

1 Like

Right-o! Thanks for clearing that up. I’ll just wait for the userUtterenceReverted fix. It’s not that important for my use-case right now to make custom actions that basically do the same thing as just an utter.

Hi @erohmensing,

I am currently working on a chatbot for my study, but the project will end in three weeks. Will this:

be done before that…?

We want to help future students with their study choice, but during this conversation a student could come up with questions. The bot should answer the question and return to the conversation as if the question was not asked. It seems the UserUtteranceReverted() would do the trick, but then I would need an action for every FAQ, right? That will be a lot of actions…

And besides that, I cannot make the code work. I created an actions.py file, but where should the program call that file?

I hope you can help me :slight_smile:

Hi Ella,

I created decision based bot using memoization policy as suggested by you. According to my understanding when we are training RNN for stories, it also makes combinations from given stories so as to create a sequence. The issue I am having is that when I ask the same question again to the bot, I mean i repeat my question after a gap of say 2 questions, then it is giving me a different answer for the same question. Can you tell me why this is happening ? Can it be ruled out? i want it to give same answer for the same question if it has been asked 10 times?

That depends @akanksha, are you using the MemoizationPolicy or the AugmentedMemoizationPolicy? Are there any featurized slots in the stories you’re trying to repeat?

Can you provide an example of where it went wrong and what the desired behavior would be?

thanks Ella for the reply.

I am using Memoization policy yes there are featurized slots, like

*info_mobile_seva{“push”:“push”,“sm”:“sms”}

  • utter_push_sms

*info_mobile_seva{“sm”:“sms”}

  • utter_sms

. Actually I want to model something like… if there is only “sms” in the query, then it is supposed to give utter_sms as response and if there is keywords “Push” and “sms” both in the query then it is supposed to give a diffrent answer as “utter_push_sms”. . Also if there is “sms and rates” in the query, then there is a different response. I don’t know how to model such rules. Is there a different approach I should follow? Also is it possible that my bot will be able to give replies on single keywords like ‘sms’?

Hi @erohmensing,

I am using Memoization policy yes there are featurized slots, like

*info_mobile_seva{“push”:“push”,“sm”:“sms”}

  • utter_push_sms

*info_mobile_seva{“sm”:“sms”}

  • utter_sms

. Actually I want to model something like… if there is only “sms” in the query, then it is supposed to give utter_sms as response and if there is keywords “Push” and “sms” both in the query then it is supposed to give a diffrent answer as “utter_push_sms”. . Also if there is “sms and rates” in the query, then there is a different response. I don’t know how to model such rules. Is there a different approach I should follow? Also is it possible that my bot will be able to give replies on single keywords like ‘sms’?

Ah so those aren’t actually slots but rather entities. The setup you have should be right for featurizing the entities for your use case! I’d recommend not creating slots for those entities unless you need to, though.

Also is it possible that my bot will be able to give replies on single keywords like ‘sms’?

is it recognizing the intent and entity correctly?