Filling slot with intent name or get intent name from history

Hi everyone I am looking for a way to set a slot when a intent have been predicted. I am working with a couple of intents like:

- intent: cancel_reservation
  - I wanna cancel the reservation number [11-333333X](id_res)
  - I need to cancel my reservation
....

- intent: reschedule_reservation:
  - I need to move my reservation,  [11-333333X](id_res) to another day
  - Can I move my reservation?

- intent: inform_id_res
  - [11-333333X](id_res)
  - [11-22222J](id_res)

I have a custom action that ideally would take the name of the intent and the entity id_res and make an api call.
Everything goes fine when I have both items in the same utterance, intetn, and entity. But in cases where I have only the intent, meaning no entities in the utterance, I need to ask for it in order to pass this value to the custom action. So, I seted up an inform_res_id intent into my nlu.

In my stories.yaml i have something like this:

- fancy_story1:
    - intent: cancel_reservation
      entities: 
      - res_id: 11-333333X
  - slot_was_set:
      - res_id: 11-333333X
- action: action_call_api_with_intent_and_entity

- not_fancy_story1:
    - intent: cancel_reservation
    - action: form_get_res_id
   - active_loop: form_get_res_id
   - slot_was_set:
    - requested_slot: res_id
  - action: utter_ask_form_get_res_id
  -   intent: inform_res_id
      entities:
       - res_id: 14-55858152-22
  - slot_was_set:
    - res_id: 14-55858152-22
  - action: action_call_api_with_intent_and_entity

→ in the second story, the intent that I got using tracker.latest_message[‘intent’].get(‘name’) method is the inform_res_id, but i would like to find a way to get cancel_reservation instead of it. How can i get this name? I have a way to access to the history of intents?

Can you help me on this ? I mean, Is my approach correct?

I think tracker.events will help you. Its list all events of user, include all intents :blush:

            reversed_events = list(tracker.events)
            print(reversed_events)
{
      "event":"user",
      "timestamp":1650464507.141205,
      "metadata":{
         "model_id":"ad8bd8b950a04b0a8c2f832c7dcb59e9"
      },
      "text":"hi",
      "parse_data":{
         "intent":{
            "name":"greet",
            "confidence":0.9999985694885254
         },
{
      "event":"user",
      "timestamp":1650464520.669942,
      "metadata":{
         "model_id":"ad8bd8b950a04b0a8c2f832c7dcb59e9"
      },
      "text":"bye",
      "parse_data":{
         "intent":{
            "name":"goodbye",
            "confidence":0.9999990463256836
         },

Oi cara! Thank you very much! It works for me

1 Like