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.
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:
Agent(domain, policies=None, featurizer=None, interpreter=None, tracker_store=None)¶
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)¶
Handle messages coming from the channel.
handle_message(text_message, message_preprocessor=None, output_channel=None, sender_id=u'default')¶
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.
>>> 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?']
load(path, interpreter=None, tracker_store=None, action_factory=None)¶
Persists this agent into a directory for later loading and usage.
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(resource_name=None, model_path=None, remove_duplicates=True, **kwargs)¶
Train the policies / policy ensemble using dialogue data from file
train_online(resource_name=None, input_channel=None, model_path=None, **kwargs)¶
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(resource_name, output_file, max_history, nlu_training_data=None, fontsize=12)¶