4.1. State Referencing

Start State

Let us create transitions for a virtual agent that handles time, weather, and playing music:

transitions = {
    'state': 'start',
    '`What can I do for you?`': {
        '[{time, clock}]': {
            '`It\'s 3PM.`': 'end'
        },
        '[{weather, forecast}]': {
            '`It\'s sunny outside`': 'end'
        },
        '[play, raining tacos]': {
            '`It\'s raining tacos. From out of the sky ...`': 'end'
        },
        'error': {
            '`Sorry, I didn\'t understand you.`': 'start'
        }
    }
}
  • #5: shows the current time (although it is correct only twice a day at the moment).

  • #8: informs the current weather in Sunnyville.

  • #11: plays the song "Raining Tacos".

  • #14: print the error message and references to the start state.

Notice that when the user input does not match any of the conditions, it prints the error message and loops back to the start state.

Custom States

It is possible to name any transition you create as a state:

  • #6: names the state as time.

  • #9: names the state as weather.

  • #13: names the state as play_raining_tacos.

  • #17: references to the play_raining_tacos state.

Exit State

State referencing can be abused to create transitions that never end (infinite loop). It is important to design an exit state so you can terminate the conversation without throwing errors:

  • #6,10,14,17: loops back to the start state.

  • #19-21: creates an exit state to terminate the dialogue.

What is the main difference between an error transition and an exit state?

Last updated

Was this helpful?