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


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.

class rasa_core.agent.Agent(domain: Union[str, rasa.core.domain.Domain] = None, policies: Union[rasa.core.policies.ensemble.PolicyEnsemble, List[rasa.core.policies.policy.Policy], None] = None, interpreter: Optional[rasa.core.interpreter.NaturalLanguageInterpreter] = None, generator: Union[rasa.core.utils.EndpointConfig, NLG, None] = None, tracker_store: Optional[TrackerStore] = None, action_endpoint: Optional[rasa.core.utils.EndpointConfig] = None, fingerprint: Optional[str] = None)[source]

The Agent class provides a convenient interface for the most important Rasa Core functionality.

This includes training, handling messages, loading a dialogue model, getting the next action, and handling a channel.

create_processor(preprocessor: Optional[Callable[str, str]] = None) → rasa.core.processor.MessageProcessor[source]

Instantiates a processor based on the set state of the agent.

execute_action(sender_id: str, action: str, output_channel:, policy: str, confidence: float) → rasa.core.trackers.DialogueStateTracker[source]

Handle a single message.

handle_channels(channels: List[], http_port: int = 5005, route: str = '/webhooks/', cors=None) → Sanic[source]

Start a webserver attaching the input channels and handling msgs.

If serve_forever is set to True, this call will be blocking. Otherwise the webserver will be started, and the method will return afterwards.

handle_message(message:, message_preprocessor: Optional[Callable[str, str]] = None, **kwargs) → Optional[List[str]][source]

Handle a single message.

handle_text(text_message: Union[str, Dict[str, Any]], message_preprocessor: Optional[Callable[str, str]] = None, output_channel: Optional[] = None, sender_id: Optional[str] = 'default') → Optional[List[Dict[str, Any]]][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.

>>> from rasa.core.agent import Agent
>>> from rasa.core.interpreter import RasaNLUInterpreter
>>> interpreter = RasaNLUInterpreter(
... "examples/restaurantbot/models/nlu/current")
>>> agent = Agent.load("examples/restaurantbot/models/dialogue",
... interpreter=interpreter)
>>> await agent.handle_text("hello")
[u'how can I help you?']

Check if all necessary components are instantiated to use agent.

classmethod load(path: str, interpreter: Optional[rasa.core.interpreter.NaturalLanguageInterpreter] = None, generator: Union[rasa.core.utils.EndpointConfig, NLG] = None, tracker_store: Optional[TrackerStore] = None, action_endpoint: Optional[rasa.core.utils.EndpointConfig] = None) → Agent[source]

Load a persisted model from the passed path.

load_data(resource_name: str, remove_duplicates: bool = True, unique_last_num_states: Optional[int] = None, augmentation_factor: int = 20, tracker_limit: Optional[int] = None, use_story_concatenation: bool = True, debug_plots: bool = False, exclusion_percentage: int = None) → List[rasa.core.trackers.DialogueStateTracker][source]

Load training data from a resource.

log_message(message:, message_preprocessor: Optional[Callable[str, str]] = None, **kwargs) → rasa.core.trackers.DialogueStateTracker[source]

Append a message to a dialogue - does not predict actions.

persist(model_path: str, dump_flattened_stories: bool = False) → None[source]

Persists this agent into a directory for later loading and usage.

predict_next(sender_id: str, **kwargs) → Dict[str, Any][source]

Handle a single message.

toggle_memoization(activate: bool) → None[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(training_trackers: List[rasa.core.trackers.DialogueStateTracker], **kwargs) → None[source]

Train the policies / policy ensemble using dialogue data from file.

  • training_trackers – trackers to train on
  • **kwargs – additional arguments passed to the underlying ML trainer (e.g. keras parameters)

Have questions or feedback?

We have a very active support community on Rasa Community Forum that is happy to help you with your questions. If you have any feedback for us or a specific suggestion for improving the docs, feel free to share it by creating an issue on Rasa Core GitHub repository.