Dynamically adding buttons to a slot response in a form

Hi,

I’ve got a slot filling form all working quite nicely with some custom validation logic within each slot. All working well so far.

However, I would like to help the user with buttons when I need them to disambiguate if the entity entered did not exactly match the entity from a list (based on my cosine similarity validation logic). I therefore need to dynamically add buttons to the default “utter_<form_name>” in my domain file.

Is there a way to override the action that displays the utter in my form?

Thanks!

Hi @pomegran I believe you can do this. Let me make sure I understand the problem. You are validating the user input of a slot. During that validation you’re checking if that value is acceptable using some criteria. If the value is valid you’d like to continue with the form. If the value is not valid you’d like to offer some dynamic button choices of the closest options based on your cosine similarity results?

Am I interpreting your problem correctly?

Yep, that’s exactly it Matthew. I have my utter_<> in my domain setup already, but I’d like to dynamically add buttons to it based on a validation criteria (cosine similarity match) I currently have setup.

Great. Could you share what you have setup in the domain so far?

Sure. The domain is very simple:

version: '2.0'
config:
  store_entities_as_slots: true
session_config:
  session_expiration_time: 60
  carry_over_slots_to_new_session: true
intents:
- report_damage:
    use_entities: true
- help_me:
    use_entities: true
entities:
- panel
- damage_type
- damage_severity
slots:
  panel:
    type: rasa.shared.core.slots.TextSlot
    initial_value: null
    auto_fill: true
    influence_conversation: true
  damage_type:
    type: rasa.shared.core.slots.TextSlot
    initial_value: null
    auto_fill: true
    influence_conversation: true
  damage_severity:
    type: rasa.shared.core.slots.TextSlot
    initial_value: null
    auto_fill: true
    influence_conversation: true
responses:
  utter_help:
    text: You need to enter the appropriate information.
  utter_ask_damage_form_panel:
  - text: Which panel was the damage on?
  utter_ask_damage_form_damage_type:
  - text: Can you tell me the type of damage please?
  utter_ask_damage_form_damage_severity:
  - text: Can you describe the damage severity please?
  utter_damage_form_complete:
  - text: The panel is <{panel}>, the damage_type is <{damage_type}> and the damage severity is <{damage_severity}>
actions:
- validate_damage_form
- action_default_fallback
- action_damage_form_complete
- action_reset_all_slots
forms:
  damage_form:
    damage_severity:
    - auto_fill: true
      entity: damage_severity
      initial_value: null
      type: from_text
    damage_type:
    - auto_fill: true
      entity: damage_type
      initial_value: null
      type: from_text
    panel:
    - auto_fill: true
      entity: panel
      initial_value: null
      type: from_text
e2e_actions: []

Hi @pomegran ,

It’s possible. You need to use custom actions instead of utter_ask{slot_name}, you need to use action_ask_{slotname} and write logic in the custom actions.

Follow this docs for more info.

Morning!

Ok, just to be clear, I just need to create a custom action called e.g. ‘action_ask_panel’? How does this get called in a form? Does it get called "under the hood’?

I’ll take a look this morning though, thanks for the speedy response!

After creating the action_ask_panel in your actions.py, list down the action_ask_panel in domain.yml file under actions just like any other action name.

The action will be called automatically by the Form Logic.

1 Like

Yep, got it. Thank you - works as you say (don’t know how I missed this in the docs).

For anybody else using this, also remove your “utter” for the slot as this takes precedence (if it exists).

Thanks for your help! :grinning: