How do I initialize a DialogueStateTracker in my custom action?

I am trying to use a DialogueStateTracker, that would allow me to export the current story to a file. This is my custom Action:

class ActionTagFeedback(Action):
"""Tag a conversation in Rasa X as positive or negative feedback, save the positive Story. Negative Stories should be reviewed. """

def name(self):
    return "action_tag_feedback"

def run(self, dispatcher, tracker, domain) -> List[EventType]:
	

    feedback = tracker.get_slot("sentiment")

    if feedback == "pos":
    	label = '[{"value":"postive feedback","color":"76af3d"}]'
    	DST = DialogueStateTracker(tracker.events, tracker.slots)
    	DST.export_stories_to_file(export_path="data/stories.md")
    elif feedback == "neg":
        label = '[{"value":"negative feedback","color":"ff0000"}]'
    else:
    	return []
    tag_convo(tracker, label)

    return []

This is the error I am getting:

Exception occurred while handling uri: 'http://localhost:5055/webhook'
Traceback (most recent call last):
  File "c:\users\januwefeldmann\anaconda3\envs\rasa\lib\site-packages\sanic\app.py", line 976, in handle_request
    response = await response
  File "c:\users\januwefeldmann\anaconda3\envs\rasa\lib\site-packages\rasa_sdk\endpoint.py", line 102, in webhook
    result = await executor.run(action_call)
  File "c:\users\januwefeldmann\anaconda3\envs\rasa\lib\site-packages\rasa_sdk\executor.py", line 387, in run
    events = action(dispatcher, tracker, domain)
  File "C:\Users\JanUweFeldmann\Documents\ChatbotNotebooks\actions.py", line 197, in run
    DST = DialogueStateTracker(tracker.events, tracker.slots)
  File "c:\users\januwefeldmann\anaconda3\envs\rasa\lib\site-packages\rasa\core\trackers.py", line 135, in __init__
    self.slots = {slot.name: copy.deepcopy(slot) for slot in slots}
  File "c:\users\januwefeldmann\anaconda3\envs\rasa\lib\site-packages\rasa\core\trackers.py", line 135, in <dictcomp>
    self.slots = {slot.name: copy.deepcopy(slot) for slot in slots}
AttributeError: 'str' object has no attribute 'name'

I assume the format of tracker.slots doesn’t quite fit the DialogueStateTracker, but I am not sure if this is how I am supposed to initialize the DST at all. Can anyone point me in the right direction? I would be very grateful.

@Taufred Why do you want to export the current story to a file? Rasa X makes it easy to save conversations as stories and / or tests and push them to a remote Git repository, so that might be a better route

Thanks for the reaction @tyd! I would like to implement some kind of feedback learning loop, that would automatically add to the training data after deployment. This is part of a research project I am doing, so having to do it manually with Rasa X would not be ideal.

@Taufred I am skeptical about automatically adding it to the training data without a human in the loop. You can read about why we think you need to actually read through the conversations here.

Your initialisation of DST looks fine to me. I was able to get it to successfully dump to a file, though I did not try it with slots. What are slots are in your tracker? This might be a bug in Rasa Open Source that you can report here

I thought the slots parameter was mandatory, what did you give the DST instead? There are multiple slots, like the sentiment and some text entities. Can you show me the code you used @tyd? That would really help!

@Taufred I used your code (including the slot parameter). However, I tried it with a conversation that did not include any slots and it worked

So that means your tracker.slots returned an empty list/dict or None? I will try that, but sadly it won’t explain why it doesn’t take my slots or if that even is the right method of initialization :slightly_frowning_face:. Thanks for the help anyway!

@tyd I tried it with an empty list instead of the slot parameter. That worked but it didn’t write in the story format, more like a giant list of events in one line. What happened when you ran it? Is there a function that can write the Dialogue to a file in the story format?

can anyone make any changes in that DialogueStateTracker actually I’m trying to resolve this error from 2 days. can someone please help me out

1 Like