Carry intent and entities with rasa form

Is there a way to preserve non-slotted entities through a rasa from?

Say someone asks a question like: “show me the stock price for google”. With an action, I can either return the current stock price or the stock price history. To clarify this ambiguity, I am using a form to capture a time period entity (time_period) which can be either current_price or historical_price. (if there is a more elegant way to do this please let me know).

So the “happy path” story is presented like this:

* get_stock_price
    - form_get_stock_price
    - form{"name": "form_get_stock_price"}
    - form{"name": null}
    - action_get_stock_price

The form action, form_get_stock_price has a requirement of just time_period. For reasons not obvious in this example, I cannot make other entities like “google” or “stock price” a required slot. action_get_stock_price is a normal Action that fetches the stock price based on the given entities.

If I have a dialog like this:

Me: Show me the stock price for google (get_stock_price)
Bot: Would you like the current price or historic prices? (utter_ask_get_stock_price)
Me: historical prices (inform_get_stock_price)

I receive an object that only has the time_period entity and the intent set as inform_get_stock_price.

Is there a way that I can easily carry over entities and intents such that I instead receive an object that has the intent set as “get_stock_price”, and the “time_period” entity appended onto the entity list originally obtained in the first question (e.g. entities := [“google”, “stock_price”, “historical_price”]).

Should I remove the action_get_stock_price and put its logic into the form action (form_get_stock_price)?

Please let me know if anything needs clarification.

Hello @ttlekich,

Well, Slot IS a way to preserve entities. If you need to handle logic base on the time_period entity, there is no reason to not save it in a slot for usage.

Secondly, if the action_get_stock_price only fetch price based on the given entities, then yes you could just do it in the submit function of the form.

Lastly, if you can not save time_period entity to a slot for some reason, then in the submit function, you can get the entities of last message this way:

// Return a list of entities in the last message
entities = tracker.latest_message["entities"]
// Each entity is a dict like this:
    {
      "start": 12,
      "end": 15,
      "value": "Huy",
      "entity": "name",
      "confidence": 0.994839359640985,
      "extractor": "CRFEntityExtractor"
    }

Then you can iterate through the list and get the value of the time_period entity (if there is any). Of course it’ll be easier to just save it in a slot.

Lastly, if you can not save time_period entity to a slot for some reason, then in the submit function, you can get the entities of last message this way

Thank you for the reply. This is the strategy I ended up with! It’s nice to have some confirmation.