rasa: custom action_session_start can't access user message metadata

Rasa version: 2.1.1

Rasa SDK version (if used & relevant): 2.1.2

Rasa X version (if used & relevant): n/a

Python version: 3.7.9

Operating system (windows, osx, …): ubuntu 20.04

Issue: Same issue as: https://github.com/RasaHQ/rasa/issues/6348

“Trying to pass metadata to slots using action_session_start; the events key on the tracker data, on the action server request, is arriving empty.”

This issue is not present on 1.10.14.

Error (including full traceback):

2020-11-30 14:58:06 WARNING  actions.actions  - session_start but no metadata, tracker.events: []

Command or request that led to error:


Content of configuration file (config.yml) (if relevant):


Content of domain file (domain.yml) (if relevant):


Additional Details (added by @wochinge )

The use case for this is that the first user message contains metadata which is supposed to be passed onto the action_session_started action. To make this a bit more tricky action_session_started is overriden by a custom action.

The problem is a custom action can only access information from the past. However, action_session_started is the first event in the conversation and there is no past (as we execute the session initializtion before we log the UserUttered event). We hence have the task to make metadata available to the custom action before this action actually happened.

Visualization of the problem:

  1. User sends first message
  2. InputChannel extras metadata and passes it along with the UserMessage
  3. processor finds out this is the first message in the conversation and runs action_session_start which is a custom action
  4. action_session_start runs but has no access on the metadata from the UserMessage
  5. processor logs action_session_started + the SessionStarted event on the tracker
  6. the processer runs the NLU prediction and logs it on the tracker (together with the metadata)
  7. the processor predicts and executes further bot actions

The proposed solution is outlined here

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 30 (25 by maintainers)

Most upvoted comments

What side effect are you thinking of.

If users decide dynamically in their custom action_session_started to not restart the session, they’d have to also revert the potentially session_started event which was added for the metadata. Unfortunately nobody asked in the removal PR what the actual reason was to remove this so I can only guess that this might have been the reason. Having two session_started events definitely wouldn’t be clean.

This sounds like a breaking change. Existing implementations count on action_session_start including metadata.

You mean in case action_session_start isn’t overriden? We can still keep this.

The user can also structure their metadata in any fashion they want.

We can make the slot value an arbitrary payload.

Minor point but the idea of a slot called action_session_start_metadata is confusing because it implies to me that it is an Event.

👍🏻 Open for renaming suggestions. Note that the entire idea is that we log the metadata as event so the custom action_session_started action can access this data.

The first SessionStarted event unfortunately would have side effects for users who decide dynamically in their custom action_session_start action whether to restart the session (it’s in my opinion an unlikely use case, but it might happen).

What side effect are you thinking of.

I was thinking about it a bit more and I think a nice solution would be to append a SlotSet event for an unfeaturized slot instead of using a second SessionStarted. We could e.g. use the convention that there is a slot action_session_start_metadata which stores the metadata

This sounds like a breaking change. Existing implementations count on action_session_start including metadata. The user can also structure their metadata in any fashion they want. The proposed change seems like it would require a formal definition of a metadata object that isn’t currently required.

Minor point but the idea of a slot called action_session_start_metadata is confusing because it implies to me that it is an Event.

The first SessionStarted event unfortunately would have side effects for users who decide dynamically in their custom action_sesion_start action whether to restart the session (it’s in my opinion an unlikely use case, but it might happen).

@wochinge Understood. Thanks for the reply.

Assuming you guys would be busy with minor release If we can decide on solution, then I can also help with creating the PR.

I’ve checked, and found that:

  • This line removed in the screenshot was causing a bug, and we’ve fixed it, so it shouldn’t be there indeed
  • Metadata is passed to the action_session_start here

So it’s the action that will have a property metadata, that contains the metadata. Check default implementation ActionSessionStart here, it uses exactly that.

Please note however, that it’s up to the income channel to make sure that metadata is actually passed from the webhook down the stack. In case of rest channel, user has to implement get_metadata method, like this:

def get_metadata(self, request: Request) -> Optional[Dict[Text, Any]]:
    return request.json.get("metadata", None)

if action.name() == ACTION_SESSION_START_NAME: action.metadata = metadata If you do this, this metadata is only passed to default action_session_start ( which is inside rasa OSS ), but we do custom implementation of this action ( which is remote ) and then this metadata is not available. As call to remote action does not have that parameter and attribute you set on "action.metadata = metadata " will not transmit to custom remote action. As tracker is empty, metadata info is lost. async def run( self, output_channel: "OutputChannel", nlg: "NaturalLanguageGenerator", tracker: "DialogueStateTracker", domain: "Domain", ) -> List[Event]

There is no metadata passed in run method and tracker is empty, metadata used to be in tracker at session start.