Action prediction not working

This is my domain.yml file -

version: '"3.0"'
config:
store_entities_as_slots: true
session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true
intents:
- bye:
use_entities: []
- greet:
use_entities: []
- name:
use_entities: []
entities:
- bot
- kairon_action_response
- image
- audio
- video
- document
- doc_url
- response
slots:
response:
type: rasa.shared.core.slots.CategoricalSlot
initial_value: null
influence_conversation: true
values:
- Nupur
- Khare
mappings:
- type: from_entity
entity: response
doc_url:
type: rasa.shared.core.slots.TextSlot
initial_value: null
influence_conversation: true
mappings:
- type: from_entity
entity: doc_url
document:
type: rasa.shared.core.slots.TextSlot
initial_value: null
influence_conversation: true
mappings:
- type: from_entity
entity: document
video:
type: rasa.shared.core.slots.TextSlot
initial_value: null
influence_conversation: true
mappings:
- type: from_entity
entity: video
audio:
type: rasa.shared.core.slots.TextSlot
initial_value: null
influence_conversation: true
mappings:
- type: from_entity
entity: audio
image:
type: rasa.shared.core.slots.TextSlot
initial_value: null
influence_conversation: true
mappings:
- type: from_entity
entity: image
kairon_action_response:
type: rasa.shared.core.slots.AnySlot
initial_value: null
influence_conversation: false
mappings:
- type: custom
bot:
type: rasa.shared.core.slots.AnySlot
initial_value: 64e4d839345989d3a0c32b01
influence_conversation: false
mappings:
- type: from_entity
entity: bot
responses:
utter_greet:
- text: I'm your AI Assistant, ready to assist
- text: Let me be your AI Assistant and provide you with service
utter_default:
- text: Sorry I didn't get that. Can you rephrase?
utter_please_rephrase:
- text: I'm sorry, I didn't quite understand that. Could you rephrase?
utter_surname:
- text: your surname is Khare
utter_name:
- text: Nupur
utter_bye:
- text: Take care, I'm here for you if you need anything.
- text: Adieu, always here for you.
- text: See you later, I'm here to help.
utter_nupur:
- text: your name is Nupur
actions:
- reset
forms: {}
e2e_actions: []

rules.yml -

version: “3.0”

rules:

- rule: Say goodbye anytime the user says goodbye
steps:
- intent: goodbye
- action: utter_bye

- rule: Say ‘I am a bot’ anytime the user challenges
steps:
- intent: bot_challenge
- action: utter_default

- rule: multiflow_1
condition:
- slot_was_set:
- response: Nupur
steps:
- intent: name
- action: utter_name
- action: utter_nupur
- slot_was_set:
- response: null

stories.yml -

version: "3.0"

stories:

- story: multiflow_2
steps:
- intent: name
- action: utter_name
- slot_was_set:
- response: Khare
- action: utter_surname
- slot_was_set:
- response: null

In rule multiflow_1, action utter_nupur is not predicted after utter_name.

Do you get a warning that stories and rule contradict each other when you train?

Did you try running your chatbot with “rasa interactive” and see what value the slot “response” holds when you try this?

Yes, I got this warning earlier, but it got cleared. Nope will try rasa interactive.

But I don’t get why its not predicting correct action.

Basically I was thinking maybe the training was not working, because your story and rule may contradict each other. But the conditionon the multiflow_1 rule makes me think it should be fine.

Then my next thought was, the condition for the rule to apply is not met. So your entity “response” does not hold the value “Nupur”. If you run interactive mode, you can see all slots and their current values, so then you would know if it’s not getting triggered, because the entitiy “response” does not hold the value “Nupur”. I cant see where you have an intent that sets “Nupur” as value for “response”. If you dont have one or dont want one, maybe consider setting it as a default value and then try again.

Previously I did slot_was_set after intent utter_name. Basically, utter_name has value ‘Nupur’, so I thought that it will get set into the slot ‘response’ and then utter_nupur would be predicted according to rule.

And that would then contradict the story, right? I don’t know if this is a simplified example for something else you want, but I’d do it like this:

  response:
    type: any
    mappings:
    - type: from_entity
      entity: response

utter_name:
  - text: {response}

- intent: name
  examples: |
  - my name is [Nupur](response)
  - my name is [Khare](response)
  - hi i'm [Nupur](response)
  - hi i'm [Khare](response)

- rule: multiflow_1
  steps:
  - intent: name
  - action: utter_name

- story: multiflow_2
  steps:
  - intent: name
  - action: utter_name
  - slot_was_set:
    - response: Khare
  - action: utter_surname
  - slot_was_set:
      - response: null

I don’t know what your intent “name” examples look like, but you would use the intents to set the slots. You defined response as set “from entity”, which means this is how you need to do it here too. I dont know if you can set them via rules. Simply writing it like I did above, marking the entities in your examples, will make it so that the entity is automatically extracted and saved in the slot.

You can then use slots in your responses with the {} brackets, no need for defining two different responses. If anything i would use one response with different conditions, because the response is still utter_name semantically. Would look something like this:

  utter_name:
    - condition:
        - type: slot
          name: response
          value: "Nupur"
      text: "Nupur is a cool name!"
   - condition:
        - type: slot
          name: response
          value: "Khare"
      text: "Your name is Khare"
  - text: "I don't know your name."

And then you dont need a rule with a condition but simply an utter_name after an intent name. Easy.

If you have little examples, there’s also no need to define values for the entity, because usually it only accepts the ones present in your examples anyway, unless you provide >400 different names for it to learn what a name looks like.

Im thinking your condition in rule “multiflow_1” is not met, so that’s why it never gets triggered. Using my examples for the name intent should already fix that, but I feel like you’re doing a little much for such a minor task, so feel free to try the other changes i made too.

Thanks for this!! I will try this and let you know

I tried with this, but what is happening is that the utterance related to the rule is predicted followed by the utterance of the story. I have used older version, but in the latest version also it was the same.

domain.yml

version: '2.0'
config:
store_entities_as_slots: true
session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true
intents:
- bye:
use_entities: []
- greet:
use_entities: []
- name:
use_entities: []
entities:
- bot
- kairon_action_response
- image
- audio
- video
- document
- doc_url
- response
slots:
response:
type: rasa.shared.core.slots.CategoricalSlot
initial_value: null
auto_fill: true
influence_conversation: true
values:
- nupur
- ' khare'
doc_url:
type: rasa.shared.core.slots.TextSlot
initial_value: null
auto_fill: true
influence_conversation: true
document:
type: rasa.shared.core.slots.TextSlot
initial_value: null
auto_fill: true
influence_conversation: true
video:
type: rasa.shared.core.slots.TextSlot
initial_value: null
auto_fill: true
influence_conversation: true
audio:
type: rasa.shared.core.slots.TextSlot
initial_value: null
auto_fill: true
influence_conversation: true
image:
type: rasa.shared.core.slots.TextSlot
initial_value: null
auto_fill: true
influence_conversation: true
kairon_action_response:
type: rasa.shared.core.slots.AnySlot
initial_value: null
auto_fill: false
influence_conversation: false
bot:
type: rasa.shared.core.slots.AnySlot
initial_value: 64e4d839345989d3a0c32b01
auto_fill: true
influence_conversation: false
responses:
utter_name:
- text: '{response}'
utter_bye:
- text: Take care, I'm here for you if you need anything.
- text: Adieu, always here for you.
- text: See you later, I'm here to help.
utter_nupur:
- text: your name is Nupur
utter_greet:
- text: I'm your AI Assistant, ready to assist
- text: Let me be your AI Assistant and provide you with service
utter_default:
- text: Sorry I didn't get that. Can you rephrase?
utter_please_rephrase:
- text: I'm sorry, I didn't quite understand that. Could you rephrase?
utter_surname:
- text: your surname is Khare
actions:
- reset
forms: {}
e2e_actions: []

actions.yml -

email_action: []
form_validation_action: []
google_search_action: []
http_action: []
jira_action: []
pipedrive_leads_action: []
prompt_action: []
slot_set_action:
- name: reset
set_slots:
- name: response
type: reset_slot
value: ''
two_stage_fallback: []
zendesk_action: []

rules.yml -

version: "2.0"
rules:
- rule: ask the user to rephrase whenever they send a message with low nlu confidence
steps:
- intent: nlu_fallback
- action: utter_please_rephrase
- rule: bye
steps:
- intent: bye
- action: utter_bye
- rule: greet
steps:
- intent: greet
- action: utter_greet
- rule: multiflow_2
steps:
- intent: name
- action: utter_name
- slot_was_set:
- response: Khare
- action: utter_surname
- action: reset

stories.yml -

version: "2.0"
stories:
- story: multiflow_1
steps:
- intent: name
- action: utter_name
- slot_was_set:
- response: Nupur
- action: utter_nupur
- action: reset

nlu.yml -

version: "2.0"
nlu:
- intent: bye
examples: |
- good bye
- bye
- See you later!
- Goodbye!
- intent: greet
examples: |
- Hi
- Hello
- Greetings
- Hi there
- Good day
- Howdy
- Hey there
- What's up?
- Hullo
- intent: name
examples: |
- My name is [Nupur](response)
- My surname is [Khare](response)
- Hi I am [Nupur](response)
- Hi I am [Khare](response)
- I am [Nupur](response)
- Hey, I am [Nupur](response)
- Myself [Nupur](response)
- I introduce myself as [Nupur](response)

Sorry, not sure I understand. Is this what the conversation looks like?

User: "hi im Khare"
Bot: utter_name
Bot: utter_surname
Bot: reset

and

User: "hi I'm Nupur"
Bot: utter_name
Bot: utter_nupur
Bot: reset

Rules define what must happen, while stories define what may happen. Stories are like patterns the chatbot learns to follow, as long as there is no rule being triggered. It’s best to keep that in mind when defining rules and stories. I’m using Rasa version 3, but I dont think it makes a difference here. Any reason why you’re using an older version of rasa?

Could you tell me what happens and what you want to happen instead the way I did above? Also its easier to read if you use the code formatting!

Yes, this is exactly what the conversation looks like. I will upgrade to the new version but I don’t think it may cause this issue. If I rule predicts utter_surname, then it also returns the action of the story which I have defined, here, utter_nupur. I am not able to get the issue that why after predicting rule, it is predicting story too!

Okay, well, your use of stories and rules here is odd to be honest. Having a rule and a story that are almost identical is not how they should be used. As I said, a rule defines what must happen, a story defines how things MAY happen. A story should hold larger parts of a conversation, rules only hold user intent and bot responses to that intent. I know youre doing this to avoid the warning/error that doesnt let you have 2 rules that only differ in what value was given, but this is not how you should work around that issue.

It seems you are struggling a bit with the basic logic of the framework. I recommend reading up on the rasa components again. You can find a good overview here:

As for your issue, you shouldnt be splitting this one intent into multiple rules and stories. Rules are not where you should be defining complex if else kinda structures, it’s where you keep things simple and short. Generalize the conversational flow, use entities, slots, forms,conditional responses, or even actions to handle getting different inputs. If your response depends on what value your response entity holds, you should be using a conditional response like I wrote above already:

  utter_name:
    - condition:
        - type: slot
          name: response
          value: "Nupur"
      text: "your name is Nupur"
   - condition:
        - type: slot
          name: response
          value: "Khare"
      text: "Your surname is Khare"
  - text: "I don't know your name yet, sorry."

Delete the story and make your rule this

- rule: multiflow_2
  steps:
  - intent: name
  - action: utter_name
  - action: reset

You also implemented what was needed to get the response from an entity (marking it in intents), but changed your response slot to not be “from entity” anymore. Does it even work? Did it reply back with the correct value when it did utter_name? I googled what “auto-fill” is and it says thats Rasa 3.0+, so did you not get an error for that? I also noticed in your first post is says version 3.0, later its 2.0. I don’t know what went wrong there? Anyway, response slot should look like this:

  response:
    type: any
    mappings:
    - type: from_entity
      entity: response

I also recommend naming your entities better. An entity is a type of value that often has limited possible values. A name is an entity. An email, a date, a time, etc. are all entities. Naming your entity “response” does not give any information of what should be stored in it. I’d expect it to be the latest user message, but it only hold the name within that message.

Generally, you seem to dive in a little quickly, and add a lot to achieve small tasks and then are unable to find what went wrong. I recommend making a minimal version work first, and then adding what you need to achieve what you want step by step. For example, the “use_entities: ” are probably not necessairy unless thats something specific to your version of rasa. Then you have also many entities and slots, but the only one I see you using is “response”. And then each value has an initial value, an auto_fill, and influene_conversation. In most cases you need none of that.

As for your actions, i can’t help with that, because this is not at all how its done in the newer version of rasa. You’d need an action server and write an action that handles this in python, so I have no idea if that works.