Usually fsm can be uesed in dialoge system ,i dont see why rasa abandon it ?
Hello!
You can model simple FSM using RulePolicy
-
create default rasa project via
rasa initcommand -
add this slot mappings to model state transitions
intents:
- greet
- goodbye
actions:
- action_state_transition
slots:
state:
type: categorical
initial_value: greet
influence_conversation: true
values:
- greet
- goodbye
mappings:
- type: custom
new_state:
type: categorical
initial_value: greet
influence_conversation: false
values:
- greet
- goodbye
mappings:
- type: from_intent
intent: goodbye
value: goodbye
condition:
- slot_was_set:
- state: greet
- type: from_intent
intent: greet
value: greet
condition:
- slot_was_set:
- state: goodbye
responses:
utter_greet:
- text: "Hey! How are you?"
utter_happy:
- text: "Great, carry on!"
utter_goodbye:
- text: "Bye"
utter_iamabot:
- text: "I am a bot, powered by Rasa."
- define state handlers as follows:
rules:
# GREET
- rule: Entrypoint
condition:
- slot_was_set:
- state: greet
steps:
- action: action_state_transition
- action: utter_greet
- rule: Bye
condition:
- slot_was_set:
- state: greet
steps:
- intent: goodbye
- action: utter_iamabot
- action: action_state_transition
wait_for_user_input: false
- rule: Greet
condition:
- slot_was_set:
- state: greet
steps:
- intent: greet
- action: utter_happy
# GOODBYE
- rule: Entrypoint
condition:
- slot_was_set:
- state: goodbye
steps:
- action: action_state_transition
- action: utter_goodbye
- rule: Bye
condition:
- slot_was_set:
- state: goodbye
steps:
- intent: goodbye
- action: utter_happy
- rule: Greet
condition:
- slot_was_set:
- state: goodbye
steps:
- intent: greet
- action: utter_iamabot
- action: action_state_transition
wait_for_user_input: false
- add custom action:
from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet
from rasa_sdk.executor import CollectingDispatcher
class ActionStateTransition(Action):
def name(self) -> Text:
return "action_state_transition"
def run(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]
) -> List[Dict[Text, Any]]:
return [SlotSet('state', tracker.get_slot('new_state'))]
State Machine is:
- 2 states
greetandgoodbye - on intent
goodbyebeing in stategreetgo to stategoodbye - on intent
greetbeing in stategoodbyego to stategreet - on intent
greetbeing in stategreetno transition - on intent
goodbyebeing in stategoodbyeno transition
You are also able to use mapping conditions to model simple constrain of transitions and custom mappings to model complex transition logic
Thank you!
I am really thankful to your reply , but can you post the whole context of domain.yml, that will be a great help for me! Best for you ,Bro!
1 Like
I’ve edited previous reply. If it works for you, please mark post as a solution to help others find it quickly.
It works, thank you !
1 Like