Policies
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.
Note: By 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.
Example configuration:
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: "..."
Configuring Policies
Max History
One important hyperparameter for Rasa Core policies is the max_history which controls how much dialogue history the model looks at to decide which action to take next.
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. This can be adjusted with the --augmentation flag and its associated parameters.
Action Selection
At every turn, each policy defined in your configuration will predict a next action with a certain confidence level—which determines which action is ultimately taken by the bot.
Keras Policy
The KerasPolicy uses a neural network to select the next action, where you can override its default architecture.
def model_architecture(self, input_shape: Tuple[int, int], output_shape: Tuple[int, Optional[int]]) -> tf.keras.models.Sequential:
# Build Model
Mapping Policy
The MappingPolicy directly maps intents to actions, allowing for streamlined and controlled action selection based on user intents.
Memoization Policy
This policy memorizes conversations from your training data, detecting exact matches and predicting actions accordingly.
Fallback Policy
The FallbackPolicy invokes a fallback action based on confidence thresholds for intent recognition and action prediction, which can be customized in the configuration.
Form Policy
The FormPolicy manages completing forms by predicting FormAction until all required slots are filled.