Hello Rasa community,
I’ve been trying to create a custom policy in Rasa 3.x to check for intent repetition and trigger a predefined action if the last three intents from the user are the same. I’ve defined the policy in a Python module and added it to my configuration file. However, when I try to train my model, I’m encountering a NameError
indicating that ‘IntentRepetitionPolicy’ is not defined.
Here is the code I’ve used to define the custom policy in my Python module (custom_policy.py
):
from rasa.core.policies.policy import Policy from rasa.shared.core.constants import USER from typing import List, Text, Dict, Any
class IntentRepetitionPolicy(Policy): def init(self, config: Dict[Text, Any]): super().init(config)
def predict_action_probabilities(
self, tracker, domain, interpreter
) -> List[float]:
user_messages = tracker.get(USER)
last_three_user_intents = [message.get("intent").get("name") for message in user_messages[-3:]]
if len(set(last_three_user_intents)) == 1:
return [1.0] # Action probabilities
return [0.0] # Action probabilities (fallback not activated)
In my config.yml
file, I’ve included the policy with the correct name:
policies:
- name: custom_policy.IntentRepetitionPolicy priority: 1
Despite these configurations, I still get the NameError
when training my model. I have verified the module name and the path, and they seem correct.
Could anyone please help me understand what might be causing this issue and how to resolve it? Any guidance or suggestions would be greatly appreciated.
Thank you in advance for your assistance!
Best regards, Alessandro