Hello,
I need to run a form N times, where N is chosen by the user before starting the form.
The problem I am facing is that after the second iteration, the rule for submitting the form is not triggered.
Here is the relevant part of my rules.yml
file
- rule: Start form after choosing N
steps:
- intent: choose_N
- action: action_start_form
- rule: Submit form
condition:
- active_loop: my_form
steps:
- action: my_form
- active_loop: null
- slot_was_set:
- requested_slot: null
- action: action_end_form
I have defined my_form
normally in domain.yml
, together with the necessary slots.
Here is the relevant part of my action.py
file
class ActionStartForm(Action):
def name(self) -> Text:
return "action_start_form"
def run(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict
) -> List[EventType]:
N = int(tracker.get_slot('N'))
current_iteration = int(tracker.get_slot('current_iteration'))
## Here I have custom utterances which depend on N and current_iteration ....
return [FollowupAction('my_form')]
class ActionEndForm(Action):
def name(self) -> Text:
return "action_end_form"
def run(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict
) -> List[EventType]:
N = int(tracker.get_slot('N'))
current_iteration = int(tracker.get_slot('current_iteration'))
events = []
if current_iteration != N:
form_slots = domain['forms']['my_form']['required_slots']
iteration = {slot: tracker.get_slot(slot) for slot in form_slots}
iterations = tracker.get_slot('iterations').copy()
iterations.append(iteration)
events = [SlotSet(key=slot, value=None) for slot in form_slots]
events.append(SlotSet(key="current_iteration", value=current_iteration+1))
events.append(SlotSet(key="iterations", value=iterations))
events.append(FollowupAction(name="action_start_form"))
else:
dispatcher.utter_message(response="utter_thanks")
return events
The slots used are defined as
iterations:
type: any
initial_value: []
mappings:
- type: custom
N:
type: float
min_value: 1
max_value: 5
mappings:
- type: from_entity
entity: N
intent: choose_N
current_iteration:
type: float
initial_value: 1
min_value: 0
max_value: 10
mappings:
- type: custom
What happens is that when choose_N
is triggered, the form starts correctly. Once all the required_slots
are filled the correct Submit form
rule is triggered, and therefore the action_end_form
. Such action is then able to trigger action_start_form
for the second iteration: form is activated, loop goes on, but once the required_slots
are filled, Rasa predicts action_default_fallback
instead of entering once again the Submit form
rule.
Do you understand why? Or do you see a different and more efficient way of handling this?