Slot_was_set is not working as expected

Hi! I’m using Rasa 3.6.13-full version and currenctly I’m facing a issue when using slot_was_set as a condition in my rules.

I have these rules, the first one I want to run when the user is greeting the bot for the first time in the session. I want the bot to say “hi” as well, send the user a message with tips on how to use the bot, and then trigger a form to fill a slot related to the user’s identity.

The second rule handles the cases where the user says “hi” to the bot again in the same session. I don’t need to fill the slot again and I don’t want to send chat chips, so I just send a response with something like “hi again”.

rules:

- rule: Greet The User and Activate cnpj form
  condition:
      - slot_was_set:
        - user_was_greeted: false
  steps:
    - intent: greet
    - action: greet_the_user
    - action: action_help_with_features
    - action: cnpj_form
    - active_loop: cnpj_form


- rule: Just Greet The User Again
  condition:
    - slot_was_set:
      - user_was_greeted: true
  steps:
    - intent: greet
    - action: utter_greet_again

# OTHER RULES ...

The problem is:

When I greet the bot for the first time, my Custom Action (you can see the code below) is triggered correctly, BUT the other actions that follow are not executed. I suspect this is because when I use SlotSet and set the slot value to True, Rasa triggers the second rule and ignores the rest of the first one.

class ActionGreetTheUser(Action):
    def name(self) -> Text:
        return "greet_the_user"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],) -> List[Dict[Text, Any]]:

        Debugger().info(f"ActionGreetTheUser.run: tracker.slots={tracker.slots}")

        dispatcher.utter_message(response=UTTER_GREET)
        dispatcher.utter_message(response=UTTER_IAMBOT)

        return [SlotSet("user_was_greeted", True)]

Can anyone help me?

Other solutions to execute different paths when the user greets the bot are also welcome! :slightly_smiling_face:

2 Likes

I am having the same kind of problems. Reading the documentation and even some code examples, I was expecting that it would work just as you’ve described. In some cases, the execution takes a different flow from the intended one, creating bugs such as reported by your post, where a set happens, apparently, before it should have happened. This is most likely a bug from Rasa, since it wouldn’t make sense that this is the expected behavior, enforcing some workarounds for it to properly work.

2 Likes

looks like a core feature from rasa but it doesn’t seem to work. I’m not quite sure what is the best approach and practice here. Does anyone has a solution?

1 Like

A few weeks ago I solved this problem.

Although the first rule (Greet The User and Activate cnpj form) does not have an execution restriction related to the user_was_greeted slot, it will only be executed by the bot if the slot has the value false. This is because the Just Greet The User Again rule will only be executed if the user_was_greeted slot has the value true, and Rasa executes the rule with the more specific condition in cases of ‘conflict’. My rule

rules:

- rule: Greet The User and Activate cnpj form
  steps:
    - intent: greet
    - action: greet_the_user
    - action: action_help_with_features # user_was_greeted slot is set to true here
    - action: cnpj_form
    - active_loop: cnpj_form


- rule: Just Greet The User Again
  condition:
    - slot_was_set:
      - user_was_greeted: true
  steps:
    - intent: greet
    - action: utter_greet_again

# OTHER RULES
...

I hope this helps you!