Why cant my actions.py file access the value stored in Entity?

After the new update, I tried to access a string value stored in my Entity, using get_latest_entity_values function on the tracker. I also tried to write it exactly how its written in Rasa’s Official tutorial for “Custom Actions”: Conversational AI with Rasa: Custom Actions - YouTube

However, it starts giving me " KeyError: ‘entity_units’ ".

Is this error only for me, or are other people also facing this? To solve my problem, I instead used get slot functions, and they worked perfectly. Have entities become outdated or something?

@BrookieHub Hi, can you please share rasa --version and what is your use case and what you trying to archived.

@BrookieHub Can you share the error screenshot.

Heeey @nik202! Thank you so much for the reply!

1. These are the details of my versions:

Rasa Version      :         2.8.3
Minimum Compatible Version: 2.8.0
Rasa SDK Version  :         2.8.1
Rasa X Version    :         None
Python Version    :         3.8.0

2. I fixed the “KeyError:”, since it was a Python problem. But then I stumbled into another problem. This is how the entity stores its value in the slot:

Moreover, the code line I am using to try and access the entity, is as follows:

Units = str(tracker.get_latest_entity_values("units"))

return [SlotSet("units", Units)]

Waiting for your response :D!

@BrookieHub

Units = next(tracker.get_latest_entity_values("units"), None)

return [SlotSet("units", Units)]

@BrookieHub can you please share complete action.py file

# This files contains your custom actions which can be used to run

# custom Python code.

#

# See this guide on how to implement these action:

# https://rasa.com/docs/rasa/custom-actions

# This is a simple example for a custom action which utters "Hello World!"

from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker

from rasa_sdk.events import SlotSet

from rasa_sdk.executor import CollectingDispatcher


class ActionTest1(Action):

    def name(self) -> Text:

        return "action_receive_entity"

    def run(self, dispatcher: CollectingDispatcher,

            tracker: Tracker,

            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        Units = str(tracker.get_latest_entity_values("units"))

        return [SlotSet("units", Units)]

@BrookieHub are you able to solve this issue ? sorry was busy and for late reply.

Heey no problem, I just resorted to using Slots instead of Entity, cuz entity doesn’t seem to work very well with the actions.py

@BrookieHub No worries, close this thread and mark above post as solution for others. Good Luck with your project.