Add an action that runs on form start/initialization, before `active_loop` is set yet
See original GitHub issueh3. What problem are you trying to solve?
I want to add form-entry logic that should only run once when a form is activated. In 2.x this was possible by modifying the run
method of a FormValidationAction
to run certain logic only when requested_slot
was None
, a heuristic for the form beginning. In 3.x [this was cleaned up| https://github.com/RasaHQ/rasa/pull/10295/files#r807244104] so that the validation action doesn’t run unless the loop is active, which makes sense, but has the side effect of not allowing form initial logic.
h3. What’s your suggested solution?
Add a new default action type, FormInitializationAction
that can be subclassed as FormValidationAction
is and called by name rule the same way e.g. initialize_<form_name>
. Other options that came up: * Add a method to FormValidationAction
that runs only in the case that the form action has just been predicted but the loop is not active yet i.e. in the same place as the validation action used to run in 2.x. e.g. run_on_entry()
. Problem with this: This would require changes in Rasa SDK as well, since the action server only offers a way to call the run
method of an action, not any other method. The principle has been to keep form running logic (i.e. when what happens) entirely in Rasa Open Source to avoid any dependency of Rasa SDK for those who run action servers not using Rasa SDK. h3. Examples (if relevant) This used to work in 2.8.x, in 3.x the entry logic will never run: class CustomFormValidationAction(FormValidationAction, ABC): def name(self): return async def run( self, dispatcher: “CollectingDispatcher”, tracker: “Tracker”, domain: “DomainDict”, ) -> List[EventType]: events = await super().run(dispatcher, tracker, domain) if tracker.get_slot(“requested_slot”) is None: # CONDITION NEVER MET IN 3.x dispatcher.utter_message(text=“I am the form entry logic!”) return events h3. Is anything blocking this from being implemented? (if relevant) No response h3. Definition of Done * [ ] default action added/called from Rasa OSS * [ ] default action template added in Rasa SDK * [ ] documentation updated
</form_name>
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Exalate commented: melindaloubser1 commented:
Exalate commented:
melindaloubser1 commented:
This is the workaround I’ve come up with. Please let me know if it covers your use case too - you can clone the
form_intial_logic_3.x
branch here: [https://github.com/melindaloubser1/moodbot/tree/form_initial_logic_3.x| https://github.com/melindaloubser1/moodbot/tree/form_initial_logic_3.x] to try it out. For this case I was looking for an utterance to be returned on form initialization and nothing more i.e.Your input -> /intro I am the extra run logic and I should run at the beginning of a form! what is your name? Your input -> melinda submitted melinda
Add a slot
form_initialized
with a custom type mapping as the first required slot for every form that needs initialization logic.Add a custom slot extraction method for
form_initialized
. This will run on every user turn. It will set the slot to False unless the slot is both currently set (it’s set by the form below) and the form is still active. This takes care of resetting the slot once a form is closed.Create a form validation base class that runs extra logic when
form_initialized
is False, and includes a validation method forform_initialized
that just sets the slot toTrue
. The validation method will only run after the form was initialized.Subclass the custom validation action for any forms requiring initialization logic.
This is what the actions end up looking like:
And the domain:
Exalate commented: venushong667 commented:
Exalate commented:
venushong667 commented:
{“form_initialized”: False}
{“form_initialized”: True}
{“form_initialized”: True}
{name}
"
Sorry for the late reply. Yes, your solution did the job very well as the form_initialized slot is being extracted in every turn of conversation, it is able to trigger the
FormValidation
to run and so the extra_run_logic where initialize function can be implemented. Thanks for the solution!