Policies

Policies

Warning: This document is for an old version of Rasa. The latest version is 1.10.26.

Policies Overview

The rasa.core.policies.Policy class decides which action to take at every step in the conversation.

Configuring Policies

Your project’s config.yml file takes a policies key which you can use to customize the policies your assistant uses.

policies:
  - name: "KerasPolicy"
    featurizer:
    - name: MaxHistoryTrackerFeaturizer
      max_history: 5
      state_featurizer:
        - name: BinarySingleStateFeaturizer
  - name: "MemoizationPolicy"
    max_history: 5
  - name: "FallbackPolicy"
    nlu_threshold: 0.4
    core_threshold: 0.3
    fallback_action_name: "my_fallback_action"
  - name: "path.to.your.policy.class"
    arg1: "..."

Max History

One important hyperparameter for Rasa Core policies is the max_history. This controls how much dialogue history the model looks at to decide which action to take next.

Data Augmentation

When you train a model, Rasa Core will create longer stories by randomly gluing together the ones in your stories files.

Action Selection

At every turn, each policy defined in your configuration will predict a next action with a certain confidence level. The bot’s next action is then decided by the policy that predicts with the highest confidence.

Keras Policy

The KerasPolicy uses a neural network implemented in Keras to select the next action.

def model_architecture(self, input_shape: Tuple[int, int], output_shape: Tuple[int, Optional[int]]) -> tf.keras.models.Sequential:
    ...

Fallback Policy

The FallbackPolicy invokes a fallback action if intent recognition has low confidence.

Configuration:

policies:
  - name: "FallbackPolicy"
    nlu_threshold: 0.3
    ambiguity_threshold: 0.1
    core_threshold: 0.3
    fallback_action_name: 'action_default_fallback'

Note

You can include either the FallbackPolicy or the TwoStageFallbackPolicy in your configuration but not both.

Form Policy

The FormPolicy is an extension of the MemoizationPolicy which handles the filling of forms. Once a FormAction is called, the FormPolicy will continue until all required slots in the form are filled.

👋 I can help you get started with Rasa and answer your technical questions.