How do I use state?

How the State is used in Voice or Chat experiences

Agents like Flow, Surveys, manage state, but it important to understand how to manage state in Experience designer.

Starting with an example, the following flowchart depicts user interaction with Alexa in which Yes and No are valid utterances to two questions. (An utterance is the word or phrase used by a user when speaking to Alexa.) For this flow to work correctly, there needs to be a way to differentiate the Yes responses, which is done by setting the state.

The blue diamonds represent responses from Alexa and correspond to Say nodes. The responses that can have a Yes or No answer are I heard you need help, is that correct? and Is this an emergency?

The State defines the context/session in which the next intent is triggered.

As you can see by the flow, a Yes utterance to I heard you need help, is that correct? produces a different response than a Yes Utterance to Is this an emergency? The same is true for a No utterance.

When Alexa responds to a Yes or No utterance, you set the state in that Say node. You will then need Intent nodes with a state corresponding to the state set in the Say node for the flow to continue.

Accounting for unexpected responses

When building a flow, it’s important to account for responses that do not fit into the model you create.

For any flow that requires a certain utterance to continue, you need to account for those utterances that are not expected and query the user until you receive an expected answer. You can do this using a None Intent with the state set.

A None Intent fires if a user says something that maps to an Intent that is not valid for the current state, such as answering orange to a yes or no query.

Note: Alexa/Google maps everything a user says to an Intent.

In the interaction diagrammed above, assuming the user must reply either Yes or No when asked if this an emergency, you can set the state to emergency in the Say node that asks that question. You include a YesIntent and NoIntent to account for the expected answers for this state. You also use a None Intent, which accounts for answers other than those expected for this State.

If there is no None Intent for the current state, the system looks for a None Intent defined at a global level. That is the one that is not defined for a particular state. The same is true for the following Intents:

  • CancelIntent

  • HelpIntent

  • StopIntent

Note: Inheritance is the notion that the flow will first look for state-specific None, Cancel, Help, and Stop intents and, not finding one, will look for non-state-specific, or global None, Cancel, Help, and Stop.

Accounting for any state

See this video explaining states with the intent node

You can create an intent node with a state of AnyState, which means if the intent occurs (that is, no matter what the Last state was set to, or if the last state was set to No State), this intent node will fire.

Unless

  1. There is no last state, and there is an intent node that matche the intent with No State set.

  2. There is another intent node on the canvas that has the state selector set to the current state.

  3. The last Say node has the check box “Disable Any State Check for Next Request” checked.

Example: In this example will add 3 intent nodes for the intent test, that respond by the utterance “test”
1st node State = “No State”
2nd node State = “Any State”
3rd node State = “t0”

  1. User types--> “TEST” -- > the intent with State = “No State” will fire. This will set the Last State value to “t0”

  2. The user again types → “Test” → the intent with State = “t0” i.e the one connected to the debug node “State equal” will fire. This will set the Last State value to “t1”

  3. The user again types → “Test” → the intent with State = “Any State” i.e the one connected to the debug node “anyState” will fire. This will set the Last State value to “t2”

    Next:

  4. Delete the intent node, with State = “No State”

  1. Refresh the chatBot, so there is no state in the session.
    The user again types → “Test” → the intent with State = “Any State” will fire. This will set the Last State value to “t2”

    If that Say node with the state set to “t2” also has:

    Then only an Intent node with Intent Test and State = T2 will fire. If one does not exist, then the None Intent will fire.

 

 

How to use the state to affect the logical flow of the voice experience

The best place to set a state in a flow is after an interaction. That makes the Say node a perfect place to do this.

The state can be found in the Intent Request node and Say node.

The Say node has a field for the state. The default is No State, which means that any intent can run next.

The drop-down for the Say node lists all possible states you can set. The list shows a number of the possible choices that are intents; either Amazon-specific intents such as YesIntent or intents you created. However, in the Sandbox State Demo, there are also values on this list like help and emergency, which are not intents but state names that are created in intents. The Set State drop-down list is populated by intent names and the launch node State comma-separated list.

Setting state in a flow

When you have states to choose from (whether those noted in this flow or all intents available in your skill), you can use them to direct the logic of the flow.

  1. Create an Intent Request node (or nodes) that will only fire for a specific state.

  2. Create or choose the intent.

  3. Choose the value of the State.

  4. Continue creating the intent by adding slots and utterances.

  5. Click Done

Note what the Intent Request node you just created looks like. It lists the skill, the intent, and the state. Reading this as it applies to the State Demo flow, this is the YesIntent for MySkill that only fires when the state is set to help.

The state is stored in a session LastIntent. You can also set the state via a function.

msg.orbita.session.LastIntent = ‘stateX’; return msg;

State examples

Use case 1: a project with many yes or no questions.

  • If the last question is Do you want to quit the survey? with the say node having state = quit.

  • If the user utterance is Yes, then YesIntent is triggered if the node has intent = Yes, and the State = quit.

Use case 2: a project only one help intent node.

  • If you want the HelpIntent to execute no matter what state you are in, you can set the HelpIntent node parameter state to AnyState. In this case, the help intent would respond no matter what the LastIntent is set to.

Use case 3: several Help nodes on the canvas.

  • Consider the parameter state in Say node is set to abcState. A HelpIntent node whose parameter state is set to Any State and another HelpIntent whose parameter state is set to abcState. When the user utterance is help, the HelpIntent with parameter state = abcState would execute; not the HelpIntent node parameter state to Any State.

See also

State Demo, which was included in your Orbita sandbox, demonstrates the flowchart above. It includes documentation specific to the flow.

Related Articles