Help with implementing Custom Tracker Store

Hi there, I am trying to create a Custom Tracker Store so that I can log each interaction with my chatbot through a third party API.

I have read https://rasa.com/docs/core/tracker_stores/#tracker-store but I don’t understand the following:

  1. How to extend the TrackerStore base class

  2. Where to put my file that extends the TrackerStore base class

  3. How to set the store_type in endpoints.yml to be the path to my module Class

Please can somebody show me examples of the above?

Many thanks

4 Likes

I’m also in the process of writing a custom tracker. Here are the steps I’ve gone thru:

  1. Copy the existing rasa tracker_store.py which is in github here.

  2. Let’s call the new file myTracker.py and place in the project root directory. Edit your copy of the standard tracker_store. Remove all of the class definitions except one that you’ll model your tracker after (I’m using the MongoTrackerStore as my template). You’ll have to add in a reference to the TrackerStore by inserting this at the top of your file: from rasa_core.tracker_store import TrackerStore

Hack away on your copy of the MongoTracerStore, let’s say you’ve called your copy of the class MyTrackerStore.

Throw a logger message at the beginning of your init function so you know that it’s been invoked when the Core starts.

  1. Based on the settings above, the endpoints.yml entry will look like this:
tracker_store:
    store_type: myTracker.MyTrackerStore
    url: localhost
2 Likes

I have my custom tracker store working and realized there I forgot to mention the requirement of the url parameter as stated in the docs. If you’re copying the existing MongoTrackerStore as your template, you must add a url parameter to the class __init__ call.

Hi @stephens have you create a custom tracker code?

1 Like

Hi Greg,

Is your example maybe available? it could be useful (for not python programmers like me) to have a shared example of a custom tracker store. My proposal is a FileStore just to store “chat history” as flat file system log files! BTW, see also my previous question here.

Thanks/ giorgio

Hi Giorgio,

That example was from my prior employer and is not publicly available. I am now at Rasa but you can use the existing tracker_store.py to get started. You would pick the class for the tracker store you are currently using or override the save method for that store.

However, I would no longer take this approach to create a logfile of the tracker events. Instead, you can use the default RabbitMQ service to create the store. I did this for a recent personal project of mine and described it in a blog post here.

Greg

1 Like

Thanks @stephens for the link to your interesting blog. Yes, the RabbitMQ could be a convenient option for high traffic scenario.

I feel the original @andymayer request is a very common need for any (beginner) RASA developer and the lack of any conversations logging feature, perplex newbies (like me).

So Ok, one could:

  • instantiate a custom Tracker class,
  • or get tracker data feed via a message queue as you suggest (maybe optimal in case of really heavy traffic, to split logging from the engine load,
  • or log externally (easy to do if client application interfaces RASA through RASA Core REST APIs, by example). Also, one could use RASA X to do nice analytics!

But my praise to RASA team is to supply ready-made simple log file option for the rasa run server. Just as a baseline.

Makes sense?

Thanks

Hey I have implemented this custom tracker for the firestore.

check it here Custom Tracker to save conversation history into Firebase Firestore

This approach is not working for me :frowning:

I followed the exact same approach you mentioned. Btw, I am using python 3.6 and rasa 2.8.12.

Basically, the tracker stored in the mongodb does not have a history of the actions, which is causing the contextual flow to break.

The tracker store does contain a history of the actions run for each session.

@stephens the link you shared for a blog post seems to be not found. It loads a 404 error.

The post is now here

Thank you @stephens . I was trying to implement a custom tracker store using Couchbase as the DB. Being a novice, I’m finding it very difficult. Any advice or reference as to how to proceed in this situation?

I don’t have much to add beyond my post above, Since Couchbase is a NoSQL db, I would start by copying the Mongo class which is here.

Hi @stephens , I followed the same steps given above, Below is the directory structure for my project: root_directory → customTrackers.py

I have updated the endpoints .yml as below:

tracker_store:
    store_type: customTrackerStore.CustomTrackerStore
    url:  https://dynamodb.us-east-1.amazonaws.com
    region: us-east-1

my rasa version is as below: Rasa Version : 3.6.13 Minimum Compatible Version: 3.5.0 Rasa SDK Version : 3.6.2 Python Version : 3.10.11

However when i run my application using below command:

rasa run --enable-api --cors “*” --debug

Iam continuously getting

\io.py:99: UserWarning: Tracker store with type ‘customTrackerStore.CustomTrackerStore’ not found. Using InMemoryTrackerStore instead.

Any suggestions what changes i should make for this to work.

Note in the docs it show:

tracker_store:
  type: path.to.your.module.Class

In your case, there is no file or directory named customTrackerStore and you should be using type not store_type. Assuming your class in the customTrackers.py is called CustomTrackerStore, it should be:

tracker_store:
  type: customTrackers.CustomTrackerStore
1 Like

Hi @stephens , I have tried changing the way you have mentioned, However RASA is still unable to find the trackerstore. Also It does not throw any detailed exception or error on how it is unable to find it, Any help on this is greately appreciated.

Hi @stephens , It is working now. Thank you very much.

I followed the exact same approach you mentioned. Btw, I am using python 3.6 and rasa 2.8.12.

i am also getting same error when start rasa core from services

UserWarning: Tracker store with type ‘mongo_tracker_store.Ff’ not found. Using InMemoryTrackerStore instead.