-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
custom action_session_start can't access user message metadata #7420
Comments
I've checked, and found that:
So it's the 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 def get_metadata(self, request: Request) -> Optional[Dict[Text, Any]]:
return request.json.get("metadata", None) |
Probably it makes sense to include the snippet from above to the mainline 🤔 |
Thanks for debugging this. Where do you add the implementation of |
There is no metadata passed in run method and tracker is empty, metadata used to be in tracker at session start. |
@degiz what ever you mentions doesn't work if we are overwriting First approach Producer part: def _action_call_format(
self, tracker: "DialogueStateTracker", domain: "Domain"
) -> Dict[Text, Any]:
"""Create the request json send to the action server."""
from rasa.shared.core.trackers import EventVerbosity
tracker_state = tracker.current_state(EventVerbosity.ALL)
.
value = {
"next_action": self._name,
"sender_id": tracker.sender_id,
"tracker": tracker_state,
"domain": domain.as_dict(),
"version": rasa.__version__,
}
if self._name == ACTION_SESSION_START_NAME:
value["metadata"] = self.metadata
return value So this will basically send metadata to our actions server for action Consumer part: tracker.metadata = action_call.get("metadata",{}) Note: here we are using tracker to pass the metadata to action run method. Second approach @amn41 What do you think which approach we should take? Also in first approach not sure about consumer part I feel it's not that very clean. Can you give some pointer around it? I would be happy to open PR with any approach |
Hey @kaustuk
This will cause a session restart each time you attach metadata, so that's unlikely an option.
This sounds quite ok! I'm not sure if the |
Hey @theresazobel
I meant |
Hi @degiz thanks for the reply.
What do you think about consumer part in first approach? Is it good enough? or should do something else? will create PR to 2.2.x branch, is that fine? |
cc @RasaHQ/enable-squad |
For first approach don't you have to change rasa sdk also? |
@NareshDen Yeah correct we need to change into Rasa SDK as well. The producer part of the approach would be part of rasa open source and consumer part is for Rasa SDK. |
Hey @amn41 did you got chance to look into this? what do you think about the approach I mentioned above? Should I create both the PRs(for producer and consumer)? PS: We need this feature to set some slots before conversation start. it would be helpful if you could look into this ASAP or point to someone who can help us out here. |
I think we should do this (for now). That's the quickest solution and qualifies as a bug fix. Note that this leads to the issue that we have two
It doesn't as this code only get's applied in General opinion on this: @kaustuk I can do a quick PR or you change your existing one, which option do you prefer? (cc @RasaHQ/enable-squad ) |
@degiz Which bug are you referring to? |
The only reason I can imagine which speaks against this solution is if you have an |
@kaustuk The issue I'm having is that I don't know the motivation of the PR which removed this. Would it be okay to come up with a proper solution (avoiding duplicate |
@wochinge Just thinking out loud. In second approach, we can modify the if condition to rasa/rasa/core/actions/action.py Line 507 in c6e32f6
So by this only 1 Don't know if it has any side effects or not. What do you think? |
The first I was thinking about it a bit more and I think a nice solution would be to append a
|
@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. |
What side effect are you thinking of.
This sounds like a breaking change. Existing implementations count on Minor point but the idea of a slot called |
If users decide dynamically in their custom
You mean in case
We can make the slot value an arbitrary payload.
👍🏻 Open for renaming suggestions. Note that the entire idea is that we log the metadata as event so the custom |
To initialize a conversation, the only way to get metadata is through tracker(in some form of event) before session starts. If action_session_start_metadata is set, will it available in action_session_start? I thought tracker is always empty and tracker is updated after. Not sure also if there is limitation on slot value, metadata could be large sometime. I don't understand "custom action_session_started to not restart the session". Why would somebody do that at session_start? |
Yes, it would be an event before
It's only empty for the first session. However, we can insert events before forwarding the tracker to the action server.
As long as it's serializable we should be fine. It's not different to having the
Do you mean why would somebody not want to restart the session upon executing @rgstephens unless there are further comments in response to my previous one I'd go forward and implement a solution so we can release this with 2.3. |
I'd like to clarify that in the proposed solution, If so, then this is a breaking change from how it worked in the past and anyone migrating from 1.x to 2.3 will still not receive metadata? |
We can add it after the custom action was run. To be clear: the metadata was never attached to
The breaking change was done when removing this in 2.0. I don't want to re-introduce a buggy (two |
I verified that the bug which was supposedly fixed by #5767, doesn't happen. I inserted metadata with 1.x on every user message, this is the tracker: {
"sender_id": "tobi2",
"slots": {},
"latest_message": {
"intent": {
"name": "greet",
"confidence": 0.9992140531539917
},
"entities": [],
"intent_ranking": [
{
"name": "greet",
"confidence": 0.9992140531539917
},
{
"name": "affirm",
"confidence": 0.0005684308125637472
},
{
"name": "mood_unhappy",
"confidence": 0.0001770617818692699
},
{
"name": "mood_great",
"confidence": 0.000020368892364786007
},
{
"name": "bot_challenge",
"confidence": 0.00001121014247473795
},
{
"name": "goodbye",
"confidence": 0.000007328536412387621
},
{
"name": "deny",
"confidence": 0.0000015816849554539658
}
],
"response_selector": {
"default": {
"response": {
"name": null,
"confidence": 0.0
},
"ranking": [],
"full_retrieval_intent": null
}
},
"text": "hi"
},
"latest_event_time": 1612865478.57138,
"followup_action": null,
"paused": false,
"events": [
{
"event": "session_started",
"timestamp": 1612865450.723252,
"metadata": {
"metadata": "hardcoded by tobi". # session start with metadata
}
},
{
"event": "action",
"timestamp": 1612865450.7233338,
"name": "action_session_start",
"policy": null,
"confidence": null
},
{
"event": "session_started",
"timestamp": 1612865450.72334
},
{
"event": "action",
"timestamp": 1612865450.7233531,
"name": "action_listen",
"policy": null,
"confidence": null
},
{
"event": "user",
"timestamp": 1612865450.9300501,
"metadata": {
"metadata": "hardcoded by tobi". # user message with passed metadata
},
"text": "hi",
"parse_data": {
"intent": {
"name": "greet",
"confidence": 0.9992140531539917
},
"entities": [],
"intent_ranking": [
{
"name": "greet",
"confidence": 0.9992140531539917
},
{
"name": "affirm",
"confidence": 0.0005684308125637472
},
{
"name": "mood_unhappy",
"confidence": 0.0001770617818692699
},
{
"name": "mood_great",
"confidence": 0.000020368892364786007
},
{
"name": "bot_challenge",
"confidence": 0.00001121014247473795
},
{
"name": "goodbye",
"confidence": 0.000007328536412387621
},
{
"name": "deny",
"confidence": 0.0000015816849554539658
}
],
"response_selector": {
"default": {
"response": {
"name": null,
"confidence": 0.0
},
"ranking": [],
"full_retrieval_intent": null
}
},
"text": "hi"
},
"input_channel": "rest",
"message_id": "097716f9b7d846c8abfbebb210a58bde"
},
{
"event": "action",
"timestamp": 1612865450.9343739,
"name": "utter_greet",
"policy": "policy_0_MemoizationPolicy",
"confidence": 1.0
},
{
"event": "bot",
"timestamp": 1612865450.934377,
"text": "Hey! How are you?",
"data": {
"elements": null,
"quick_replies": null,
"buttons": null,
"attachment": null,
"image": null,
"custom": null
},
"metadata": {}
},
{
"event": "action",
"timestamp": 1612865450.938633,
"name": "action_listen",
"policy": "policy_0_MemoizationPolicy",
"confidence": 1.0
},
{
"event": "user", # next user message with metadata - no session restart
"timestamp": 1612865478.567907,
"metadata": {
"metadata": "hardcoded by tobi"
},
"text": "hi",
"parse_data": {
"intent": {
"name": "greet",
"confidence": 0.9992140531539917
},
"entities": [],
"intent_ranking": [
{
"name": "greet",
"confidence": 0.9992140531539917
},
{
"name": "affirm",
"confidence": 0.0005684308125637472
},
{
"name": "mood_unhappy",
"confidence": 0.0001770617818692699
},
{
"name": "mood_great",
"confidence": 0.000020368892364786007
},
{
"name": "bot_challenge",
"confidence": 0.00001121014247473795
},
{
"name": "goodbye",
"confidence": 0.000007328536412387621
},
{
"name": "deny",
"confidence": 0.0000015816849554539658
}
],
"response_selector": {
"default": {
"response": {
"name": null,
"confidence": 0.0
},
"ranking": [],
"full_retrieval_intent": null
}
},
"text": "hi"
},
"input_channel": "rest",
"message_id": "6451251e0092416a973f659ca96c3ed4"
},
{
"event": "action",
"timestamp": 1612865478.569858,
"name": "utter_greet",
"policy": "policy_1_TEDPolicy",
"confidence": 0.9876126646995544
},
{
"event": "bot",
"timestamp": 1612865478.569862,
"text": "Hey! How are you?",
"data": {
"elements": null,
"quick_replies": null,
"buttons": null,
"attachment": null,
"image": null,
"custom": null
},
"metadata": {}
},
{
"event": "action",
"timestamp": 1612865478.57138,
"name": "action_listen",
"policy": "policy_1_TEDPolicy",
"confidence": 0.944972038269043
}
],
"latest_input_channel": "rest",
"active_form": {},
"latest_action_name": "action_listen"
} |
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: #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):
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 trickyaction_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 theUserUttered
event). We hence have the task to make metadata available to the custom action before this action actually happened.Visualization of the problem:
InputChannel
extras metadata and passes it along with theUserMessage
processor
finds out this is the first message in the conversation and runsaction_session_start
which is a custom actionaction_session_start
runs but has no access on the metadata from theUserMessage
action_session_started
+ theSessionStarted
event on the trackerThe proposed solution is outlined here
The text was updated successfully, but these errors were encountered: