4.3. Compound States
Multiple Topics
A dialogue flow can be complex when you start adding multiple topics. In this case, you can create a separate transition dictionary for each topic.
Let us create transitions talking about music and movies:
#3: directs to the music state.
#4: directs to the movie state.
The music and movie states can be defined in separate transition dictionaries:
#5: directs to the start state.
#8: directs to the movie state.
Finally, all three transition dictionaries can be loaded to the same dialogue flow:
When the dialogue flow runs, it randomly selects one of the 3 states, music, movie, and end:
#1: randomly selects the music state.
#3: switches to the movie state when it does not understand the user input.
The randomness in the above transitions can be quite annoying because it may end the dialogue immediately after it runs or repeats the same topic over and over. This can be alleviated by using the #GATE built-in macro:
#3: puts the music topic to an open gate.
#4: puts the movie topic to an open gate.
Once an output is selected, #GATE closes the door for that output such that it will never be selected again.
The gating prevents the system from repeating the same topic, but the end state can still be selected at any time without consuming all the other topics. To ensure that the end state gets selected last, we use scoring:
#6: indicates that this is the end state.
#7: assigns the score of this state to 0.1.
By default, all states receive a score of 1; thus, assigning a score below 1 would make that state not selected at all unless there are dynamic scoring changes through macros such as #GATE.