Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metadata missing in action_session_start #5574

Closed
rgstephens opened this issue Apr 3, 2020 · 0 comments · Fixed by #5611
Closed

metadata missing in action_session_start #5574

rgstephens opened this issue Apr 3, 2020 · 0 comments · Fixed by #5611
Labels
type:bug 🐛 Inconsistencies or issues which will cause an issue or problem for users or implementors.

Comments

@rgstephens
Copy link
Contributor

Rasa version: 1.9.4

Rasa SDK version (if used & relevant): 1.9.0

Rasa X version (if used & relevant): not used

Python version: 3.7

Operating system (windows, osx, ...): Debian & OSX

Issue:
When metadata is passed in a new session, the metadata is correctly shown in the rasa core debug message but it is not passed to ActionSessionStart.

Video debug session.

ActionSessionStart code:

class ActionSessionStart(Action):
    def name(self) -> Text:
        return "action_session_start"

    @staticmethod
    def _slot_set_events_from_tracker(
        tracker: "DialogueStateTracker",
    ) -> List["SlotSet"]:
        """Fetch SlotSet events from tracker and carry over key, value and metadata."""

        from rasa.core.events import SlotSet

        return [
            SlotSet(key=event.key, value=event.value, metadata=event.metadata)
            for event in tracker.applied_events()
            if isinstance(event, SlotSet)
        ]

    async def run(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> List[EventType]:

        logger.info(f"run action_session_start")
        # the session should begin with a `session_started` event
        events = [SessionStarted()]

        # any slots that should be carried over should come after the
        # `session_started` event`
        events.extend(self._slot_set_events_from_tracker(tracker))

        # Grab slots from metadata
        message_metadata = []
        for e in tracker.events[::-1]:
          # Does this tracker event have metadata?
            if "metadata" in e and e["metadata"] != None:
                message_metadata = e["metadata"]
                # Does this metadata have slots?
                if message_metadata and "slots" in message_metadata:
                    for key, value in message_metadata["slots"].items():
                        logger.info(f"{key} | {value}")
                        if value is not None:
                            events.append(SlotSet(key=key, value=value))
                    break
        if len(message_metadata) == 0:
            logger.warn(f"session_start but no metadata, tracker.events: {tracker.events}")

        # an `action_listen` should be added at the end as a user message follows
        events.append(ActionExecuted("action_listen"))

        return events
@rgstephens rgstephens added the type:bug 🐛 Inconsistencies or issues which will cause an issue or problem for users or implementors. label Apr 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug 🐛 Inconsistencies or issues which will cause an issue or problem for users or implementors.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant