Warning: This document is for the development version of Rasa Core. The latest version is 0.8.2.

# Agent¶

The agent allows you to train a model, load, and use it. It is a facade to access most of Rasa Core’s functionality using a simple API.

Note

Not all functionality is exposed through methods on the agent. Sometimes you need to orchestrate the different components (domain, policy, interpreter, and the tracker store) on your own to customize them.

Here we go:

class rasa_core.agent.Agent(domain, policies=None, featurizer=None, interpreter=None, tracker_store=None)[source]

Bases: object

Public interface for common things to do.

This includes e.g. train an assistant, or handle messages with an assistant.

continue_message_handling(sender_id, executed_action, events)[source]
classmethod create_tracker_store(store, domain)[source]
handle_channel(input_channel, message_preprocessor=None)[source]

Handle messages coming from the channel.

handle_message(text_message, message_preprocessor=None, output_channel=None, sender_id=u'default')[source]

Handle a single message.

If a message preprocessor is passed, the message will be passed to that function first and the return value is then used as the input for the dialogue engine.

The return value of this function depends on the output_channel. If the output channel is not set, set to None, or set to CollectingOutputChannel this function will return the messages the bot wants to respond.

Example: >>> from rasa_core.agent import Agent >>> agent = Agent.load("examples/restaurantbot/models/dialogue", ... interpreter="examples/restaurantbot/models/nlu/current") >>> agent.handle_message("hello") [u'how can I help you?'] 
classmethod load(path, interpreter=None, tracker_store=None, action_factory=None)[source]
persist(model_path)[source]

start_message_handling(text_message, sender_id=u'default')[source]
toggle_memoization(activate)[source]

Toggles the memoization on and off.

If a memoization policy is present in the ensemble, this will toggle the prediction of that policy. When set to false the Memoization policies present in the policy ensemble will not make any predictions. Hence, the prediction result from the ensemble always needs to come from a different policy (e.g. KerasPolicy). Useful to test prediction capabilities of an ensemble when ignoring memorized turns from the training data.

train(filename=None, model_path=None, remove_duplicates=True, **kwargs)[source]

Train the policies / policy ensemble using dialogue data from file

train_online(filename=None, input_channel=None, model_path=None, **kwargs)[source]

Runs an online training session on the set policies / ensemble.

The policies will be pretrained using the data from filename. After that the model will get trained on dialogues from the input channel. During the dialogue the annotations and state of the agent can be changed to correct wrong behaviour.

visualize(filename, output_file, max_history, nlu_training_data=None, fontsize=12)[source]