How to check if the slot is set from previous intent

Hi, I am creating a chatbot with Rasa, I am having a problem handling the intents, I have custom actions which gets the slot value from the user utterance for a location name. In case user don’t mention the location I need to check if the location was set in the previous intent. I wrote some stories to handle it, but it doesn’t seem to work. How can I check the entity from previous intent? I assume this should be done in my custom actions code and can’t be done through stories. Thanks in advance for your help. Cheers.

Do you really need to know, when it was set? Not rather if it was set? Both is possible, but the latter is way easier.

Hey, I don’t need to know when exactly it was set, I just need to get it from the last intent. What i am interested is if it was set or not, and its value. What I did and it seems to work now, it to remove the stories for wrong location names, or no location name set by user and only have the stories for the correct locations. Then setting the slots in custom actions in if else clause for different possible scenarios of the slot value. in this case tracker.get_slot(“location”) seems to work fine. I don’t understand what the tracker is doing though. if it checks first for the slot value in user utterance, and if it is not filled it checks for the slot value from previous intent, or not.

The tracker keeps the state of the current conversation. All slots are accessible on tracker. If a slot has not been set has the value ‘None’.

It’s hard to understand what your problem is, without any context. SO provide an example dialog. And probably show us your custom FormAction.

1 Like

The problem is solved now. I just handle the slots in my actions file. All I needed to know was what you said: The tracker keeps the state of the current conversation. All slots are accessible on tracker. If a slot has not been set has the value ‘None’. Thank you.

Bumping this topic as I think Rasa developers are still waiting for an answer whether it is possible to check if a slot is set in a story. (Without writing a custom action to do that.)

This seems like pretty basic functionality, surprised not to be able to find the answer in any of the existing documentation.

2 Likes

Hey, Need help. I need to check if all the slots from the intent are fulfilled or not. Currently I have configured a lambda(java) and called it in Validation code hook. I was looking at the earlier messages and something called tracker is discussed. Can anyone help me with the tracker?

Thanks in advance…!!

As a minimal example, using Rasa 2.2,

slots:
  slot_1:
    type: categorical
    influence_conversation: true
    values:
      - a
      - b

responses:
  utter_a:
    - text: Text a
      buttons:
        - title: option 1
          payload: /go_to_b{{"slot_1":"a"}}
        - title: option 2
          payload: /go_to_b{{"slot_1":"b"}}

  utter_b:
    - text: Text b
      buttons:
        - title: option quit
          payload: /quit_exercise

  utter_b_1:
    - text: Text b
      buttons:
        - title: option quit
          payload: /quit_exercise

  utter_c:
    - text: Text c

  utter_d:
    - text: Text d

stories:
  - story: story 1
    steps:
      - intent: go_to_a
      - action: utter_a

  - story: story 2 a
    steps:
      - intent: go_to_b
      - slot_was_set:
          - slot_1: a
      - action: utter_b

  - story: story 2 b
    steps:
      - intent: go_to_b
      - slot_was_set:
          - slot_1: b
      - action: utter_b_1

  - story: story 3 c
    steps:
      - intent: quit_exercise
      - slot_was_set:
        - slot_1: a
      - action: utter_c

  - story: story 3 d
    steps:
      - intent: quit_exercise
      - slot_was_set:
        - slot_1: b
      - action: utter_d

The idea is that there is a categorical slot [slot_1]. Which depending on the user choice at the beginning, can be set to “a” or “b”. So in story 2a and 2b, it can actually detect what was set in the slot previously. However, when it gets to story 3c and 3d, it is unable to detect the same slot. This seems to imply that slot_was_set will only detect slots that were set in the previous event but anything beyond that, doesn’t get detected?

I can get around this by creating a custom action and using tracker.get_slot(), but would prefer to avoid this if I can just do it via stories.

Hey! I was working on a project and I wanted to check if it’s now possible to check if a slot is filled, from stories. Creating a custom action just for this doesn’t seem like an elegant solution.

If you run rasa with --debug option you will see how slots are set. Rasa x GUI also shows slots and intents as you chat.