Help with rules

Hi, how do I put a rule that says i want action address_confirm to succeed ask_order, if in the initial stages of the story, a slot was set to “B”. else, save_order will succeed ask_order.

Please, I feel like its an easy solution, but I cant figure out

Can anyone help? :frowning:

Hi @arkaprabha-majumdar :wave: do you have some existing stories / rules you could share to demonstrate the behavior you’re looking for?

I have stories like this:

ask name
ask address
ask delivery_at_home_or_collect_from_shop
...10-15 lines of other actions
deny
confirm_address
confirm order
...

what I want is that the confirm address action at the end should only be predicted after the last deny if the slot delivery_at_home_or_collect_from_shop = “home” otherwise it should just move on to “confirm order” action.

Thanks! Two things. First, you can probably handle this by putting a slot_was_set event into your story like this:

steps:
  ...all other actions...
  - action: ask_delivery_at_home_or_collect_from_shop
  - slot_was_set:
    - delivery_at_home_or_collect_from_shop: "home"
  - intent: deny
  - action: confirm_address
  - action: confirm_order

Then have a second story for when the user says shop where you wouldn’t include confirm_address:

steps:
  ...all other actions...
  - action: ask_delivery_at_home_or_collect_from_shop
  - slot_was_set:
    - delivery_at_home_or_collect_from_shop: "shop"
  - intent: deny
  - action: confirm_order

In your domain.yml file you will also have to change your delivery_at_home_or_collect_from_shop slot to have influence_conversation=true.

Second, have you looked into forms? Looking at your story though it looks like you’re collecting a lot of information from the user (ask_name, ask_address, ask_delivery_at_home_or_collect_from_shop etc.) It looks like all of these steps could be put into a form so you don’t have to write each of them in each story. When you process the form at the end you can add logic for determining if based on the user input you have to confirm their address or not.

I have the stories all made and the confidence isn’t going past .64 something… i have my fallback at .7 Should I reduce the fallback confidence?

Looking at this more you’d probably be better off putting this into a Form. With the form you can collect all the details about your user’s order and store that information in slots. If a user wants home delivery you can leverage the dynamic form behavior on your action server to confirm their address. Your code on the action server would look something like this:

class ValidateDeliveryForm(FormValidationAction):
    def name(self) -> Text:
        return "validate_delivery_form"

    async def required_slots(
        self,
        slots_mapped_in_domain: List[Text],
        dispatcher: "CollectingDispatcher",
        tracker: "Tracker",
        domain: "DomainDict",
    ) -> Optional[List[Text]]:
        additional_slots = []
        if tracker.slots.get("delivery_at_home_or_collect_from_shop") == "home":
            # If the user wants home delivery then ask to confirm their address.
            additional_slots.append("confirm_address")

        return additional_slots + slots_mapped_in_domain

    async def extract_confirm_address(
        self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
    ) -> Dict[Text, Any]:
        if tracker.slots.get("requested_slot") == "confirm_address":
            text_of_last_user_message = tracker.get_intent_of_latest_message()

            return {"confirm_address": text_of_last_user_message}

When a user answers that they want home delivery the form will dynamically prompt for the user to confirm their address. Using the form helps avoid having to write a bunch of stories to collect data from the user. With the form you can also validate user responses are they are provided to make sure what they are providing valid responses.

Ahh what I used is this:

  1. added another slot called fetch_delivery_home_or_shop
  2. added a function that gets the slot for delivery_at_home_or_collect_from_shop and fills true/false in the new slot
  3. added a rule with the new slot as condition.

:smiley: btw, thanks for the formAction option. I’ll try that out too.

Man, I think you can help me with another short problem if you dont mind. image

The action_listen after action_record_order is extracting other stuff and trying to fill slots, so how do I stop the extraction for that specific action_listen :slight_smile:

Certainly. Can you post what action_record_order is doing along with a few examples of your quantity intent?