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.
#5
: directs to the start
state.
#8
: directs to the music
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.
#5
: switches to the music
state when it does not understand the user input.
#7
: goes back to the start
state when it understands the user input, and randomly selects the movie
state.
#9
: goes back to the start
state when it understands the user input, and randomly selects the music
state.
#11
: goes back to the start
state when it understands the user input, and randomly selects the end
state.
#1
: randomly selects the end
state and terminates the dialogue.
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.
#4
: has no gate to open (so it can be selected at any time).
Once an output is selected, #GATE
closes the door for that output such that it will never be selected again.
It is important to have at least one output with no gate; otherwise, the system will crash unless one of the outputs leads to the end state.
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
.