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 themusic
state.#4
: directs to themovie
state.
The music
and movie
states can be defined in separate transition dictionaries:
#5
: directs to thestart
state.#8
: directs to themovie
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 themusic
state.#3
: switches to themovie
state when it does not understand the user input.#5
: switches to themusic
state when it does not understand the user input.#7
: goes back to thestart
state when it understands the user input, and randomly selects themovie
state.#9
: goes back to thestart
state when it understands the user input, and randomly selects themusic
state.#11
: goes back to thestart
state when it understands the user input, and randomly selects theend
state.
Gating
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.
Scoring
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 theend
state.#7
: assigns the score of this state to0.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
.
Last updated