Logging a Bot


I know that using rasa_core.run it is possible to log events to a file. Is the same possible when you let an agent handle messages, like Slack, Facebook, etc, or is it not due to data protection?

agent.handle_channels ( input_channel, port, serve_forever= True has no option to specify a log.

I also do not really understand how logging is performed in debug mode using the command line, so if some understands it in more detail, I would be happy about clarifications:)

Cheers, Henry

I asked yesterday on RASA Summit. I should work using a Tracker Store, which is implementend in rasa_core.tracker_store.py.

Searching for MongoDB I found a related topic: How to save bot conversation on mongodb?

If you have MongoDB or Redis installed as key-value stores, the tracker (composed of events as Bot Actions or User Inputs) is saved to the database. After using you bot, you can then extract an Dialog instance and get the lists of events which you then have to parse.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import logging
import rasa_core
from rasa_core.agent import Agent
from rasa_core.policies.keras_policy import KerasPolicy
from rasa_core.policies.memoization import MemoizationPolicy
from rasa_core.interpreter import RasaNLUInterpreter
from rasa_core.domain import Domain
from rasa_core.utils import EndpointConfig
from rasa_core.run import serve_application
from rasa_core.tracker_store import RedisTrackerStore
from rasa_core.tracker_store import MongoTrackerStore

logger = logging.getLogger(__name__)

domain          = Domain.load('domain.yml')
# db              = RedisTrackerStore(domain, 
#                                       host='localhost',
#                                       port=6379, db=0, password=None, 
#                                       event_broker=None,
#                                       record_exp=None )
db 			= MongoTrackerStore(
				db='rasa', username=None, 
				password=None, collection='conversations', 

def train_dialogue(domain = 'domain.yml',
				   model_path = './models/dialogue',
				   training_data_file = './data/stories.md'):
	"""Train a model"""
	nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/')
	action_endpoint = EndpointConfig(url="http://localhost:5055/webhook")				
	agent = Agent( domain = domain, 
                                policies = [MemoizationPolicy(), KerasPolicy()],
	data = agent.load_data(training_data_file)	
	agent.train(	data,
				epochs = 100,
				batch_size = 25,
				validation_split = 0.2
	return agent
if __name__ == '__main__':
	agent = train_dialogue()
	rasa_core.run.serve_application(agent , channel='cmdline')		

	#extract list of events and print its names 
	events = db.retrieve("default").as_dialogue().events
	for event in events:

This then yields something like

inform{"location": "home"}
slot{"location": "home"}

where None is generated from Utter (BotUttered) Actions. This list could be parsed into a story by some rules.

Unfortunately, and I would appreciate hints on that, this approach saves all conversations to one _id in MongoDB - and that even persistently, so rerunning the skript after closing the console keeps alls previous stories. Any idea?

you can create two collections, one which you remove once the conversation is over and copy the tracker to another one for persisted storage.

in redis, you do that with record_exp flag.

Though i am not how that would affect your conversation unless they are really small. however you should also reset all slots at the end of the conversation or at the end where you have performed the final action

Okay thanks, I have a look at redis.

  • action_restart does set all slots to none?! (I have it included and will add it to my extract!)
1 Like

Hi souvik, I wanted to know if all the conversations from different users will also be stored in the mongo tracker store?

Hi, Sorry i don’t receive any notification unless i am tagged. :smiley:

anyway, yes all conversations from different users(different sender-id) will be stored in mongo tracker store as a tracker object https://rasa.com/docs/core/server/

Check the endpoint GET /conversations/ ( str: sender_id ) /tracker

rasa_core.run.serve_application(agent , channel='cmdline')

how change the channel from ‘cmdline’ to "rest"

1 Like