These docs are for version 1.x of Rasa Open Source.

---

# Policies

- [Configuring Policies](https://legacy-docs-v1.rasa.com/1.10.18/core/policies/#configuring-policies)
  - [Max History](https://legacy-docs-v1.rasa.com/1.10.18/core/policies/#max-history)
  - [Data Augmentation](https://legacy-docs-v1.rasa.com/1.10.18/core/policies/#data-augmentation)
- [Action Selection](https://legacy-docs-v1.rasa.com/1.10.18/core/policies/#action-selection)
- [Keras Policy](https://legacy-docs-v1.rasa.com/1.10.18/core/policies/#keras-policy)
- [Embedding Policy](https://legacy-docs-v1.rasa.com/1.10.18/core/policies/#embedding-policy)
- [TED Policy](https://legacy-docs-v1.rasa.com/1.10.18/core/policies/#ted-policy)
- [Mapping Policy](https://legacy-docs-v1.rasa.com/1.10.18/core/policies/#mapping-policy)
- [Memoization Policy](https://legacy-docs-v1.rasa.com/1.10.18/core/policies/#memoization-policy)
- [Augmented Memoization Policy](https://legacy-docs-v1.rasa.com/1.10.18/core/policies/#augmented-memoization-policy)
- [Fallback Policy](https://legacy-docs-v1.rasa.com/1.10.18/core/policies/#fallback-policy)
- [Two-Stage Fallback Policy](https://legacy-docs-v1.rasa.com/1.10.18/core/policies/#two-stage-fallback-policy)
- [Form Policy](https://legacy-docs-v1.rasa.com/1.10.18/core/policies/#form-policy)

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

There are different policies to choose from, and you can include multiple policies in a single [`rasa.core.agent.Agent`](https://legacy-docs-v1.rasa.com/1.10.18/api/agent/#rasa.core.agent.Agent).

### Note
Per default a maximum of 10 next actions can be predicted by the agent after every user message. To update this value you can set the environment variable `MAX_NUMBER_OF_PREDICTIONS` to the desired number of maximum predictions.

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

```yaml
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.

You can set the `max_history` by passing it to your policy’s `Featurizer` in the policy configuration yaml file.

### Note
Only the `MaxHistoryTrackerFeaturizer` uses a max history, whereas the `FullDialogueTrackerFeaturizer` always looks at the full conversation history. See [Featurization of Conversations](https://legacy-docs-v1.rasa.com/1.10.18/api/core-featurization/#featurization-conversations) for details.

As an example, let’s say you have an `out_of_scope` intent which describes off-topic user messages. If your bot sees this intent multiple times in a row, you might want to tell the user what you can help them with. So your story might look like this:

```yaml
* out_of_scope
   - utter_default
* out_of_scope
   - utter_default
* out_of_scope
   - utter_help_message
```

For Rasa Core to learn this pattern, the `max_history` has to be at least 4.

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

### Note
The memoization based policies are not affected by augmentation (independent of the `augmentation_factor`) and will automatically ignore all augmented stories.

## Action Selection
At every turn, each policy defined in your configuration will predict a next action with a certain confidence level. For more information about how each policy makes its decision, read into the policy’s description below. 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](http://keras.io/) to select the next action.

```python
def model_architecture(
    self, input_shape: Tuple[int, int], output_shape: Tuple[int, Optional[int]]
) -> tf.keras.models.Sequential:
    """Build a keras model and return a compiled model."""
    ...
```

## Mapping Policy
The `MappingPolicy` can be used to directly map intents to actions. The mappings are assigned by giving an intent the property `triggers`, e.g.:

```yaml
intents:
 - ask_is_bot:
     triggers: action_is_bot
```

## Memoization Policy
The `MemoizationPolicy` just memorizes the conversations in your training data. It predicts the next action with confidence `1.0` if this exact conversation exists in the training data, otherwise it predicts `None` with confidence `0.0`.

## Fallback Policy
The `FallbackPolicy` invokes a [fallback action](https://legacy-docs-v1.rasa.com/1.10.18/core/fallback-actions/#fallback-actions) if at least one of the following occurs:

1. The intent recognition has a confidence below `nlu_threshold`.
2. The highest ranked intent differs in confidence with the second highest ranked intent by less than `ambiguity_threshold`.
3. None of the dialogue policies predict an action with confidence higher than `core_threshold`.

### Configuration:
```yaml
policies:
   - name: "FallbackPolicy"
     nlu_threshold: 0.3
     ambiguity_threshold: 0.1
     core_threshold: 0.3
     fallback_action_name: 'action_default_fallback'
```

## Two-Stage Fallback Policy
The `TwoStageFallbackPolicy` handles low NLU confidence in multiple stages by trying to disambiguate the user input.

### Configuration:
```yaml
policies:
   - name: TwoStageFallbackPolicy
     nlu_threshold: 0.3
     ambiguity_threshold: 0.1
     core_threshold: 0.3
     fallback_core_action_name: "action_default_fallback"
     fallback_nlu_action_name: "action_default_fallback"
     deny_suggestion_intent_name: "out_of_scope"
```

## Form Policy
The `FormPolicy` is an extension of the `MemoizationPolicy` which handles the filling of forms. Once a `FormAction` is called, the `FormPolicy` will continually predict the `FormAction` until all required slots in the form are filled.
