Managing multi-topic conversation flows with Amazon Lex Session API checkpoints

In daily conversations, you often jump back and forth between multiple topics. For example, when discussing a home improvement project related to new windows and curtains, you might have questions like, “How about closing out on curtain styles and then revisiting colors?” When AWS launched Amazon Lex Session API, you learned how to address such digressions in the conversation. You can use Session API actions to switch an intent and continue the conversation. But in everyday interactions, you might have to deal with multiple digressions: “Let’s finish selecting windows before we get to curtains.”

How do you design conversation flows that contain a series of digressions? If you are like me, you’d have a dozen questions before even considering a specific product in a home improvement project.

With session checkpoints, you can easily design a conversation to support a switch to one of many topics. You can model the home improvement conversation as two intents: OrderWindows and OrderCurtains.  Now it is easy to switch topics. The flows for OrderWindows would have a checkpoint. If the user is ordering curtains but wants to complete selecting windows first, you could move the conversation back to the OrderWindows using “windowSelection” checkpoint.

Managing session checkpoints

The Amazon Lex runtime API provides operations that enable you to manage session checkpoints for a conversation. The PutSession and GetSession calls enable you to define and retrieve checkpoints.  Here’s how you can use the APIs to manage the conversation flows described earlier. Please review the bot schema for bot details.

Follow these steps to manage the conversation flow:

  1. Store the current state of the conversation
  2. Retrieve the previously stored state and continue the conversation

Store the current state of the conversation

Call the GetSession API with no filters to retrieve the current state of the conversation between your bot and the user. The GetSession API call is followed by a PutSession API call, which applies a checkpoint ‘windowSelection’ onto the OrderWindows intent. The PutSession call is shown in the code example:

PutSession Request:  Applying 'windowSelection' checkpoint on 'OrderWindows' intent

response = client.put_session (
	botName='HomeImprovementBot',
	botAlias='Prod',
	userId='abc1234',
	recentIntentSummaryView=[
	  {
	    "intentName": "OrderCurtains",
	    "slots": {
	      "curtainSize": "None",
	      "curtainStyle": "None"
	    },
	    "confirmationStatus": "None",
	    "dialogActionType": "ElicitSlot",
	    "slotToElicit": "curtainSize",
	    "checkpointLabel": "None"
	  },
	  {
	    "intentName": "OrderWindows",
	    "slots": {
	      "windowSize": "large",
	      "windowStyle": "None"
	    },
	    "confirmationStatus": "None",
	    "dialogActionType": "ElicitSlot",
	    "slotToElicit": "windowStyle",
	    "checkpointLabel": "windowSelection"
	  }
	]
)

Retrieve the previously stored state

At this point, the OrderCurtains intent has completed. Issue a GetSession API call, while passing a ‘windowSelection’ checkpointLabelFilter. This call results with the matching intent (OrderWindows), which received the checkpoint label in the previous step.

Continue with the conversation

Finally, issue a PutSession API call, setting the next step in the conversation to be continued where the user left off in OrderWindows. The following code example lists the details for GetSession:


GetSession Request:  Filtering on 'windowSelection' CheckpointLabel

--- GetSession Request with filter: ---
 
response = client.get_session(
	botName='HomeImprovementBot',
	botAlias='Prod',
	userId='abc123',
	checkpointLabelFilter='windowSelection'
)

--- Filtered GetSession Response: --- 
{
  "recentIntentSummaryView": [
    {
      "intentName": "OrderWindows",
      "slots": {
        "windowSize": "large",
        "windowStyle": "None"
      },
      "confirmationStatus": "None",
      "dialogActionType": "ElicitSlot",
      "slotToElicit": "windowStyle",
      "checkpointLabel": "windowSelection"
    }
  ],
  "sessionAttributes": {},
  "sessionId": "XXX",
  "dialogAction": {
    "type": "ElicitSlot",
    "intentName": "OrderCurtains",
    "slots": {
      "curtainSize": "None",
      "curtainStyle": "None"
    },
    "slotToElicit": "curtainSize"
  }
}

Getting started with Session API checkpoints

In this post, you learned how to use Session API checkpoints to manage multiple digressions. You can define Session API checkpoints using the AWS SDK. You can download the bot schema for the conversation in this post to implement a quick application. For more information, see the Amazon Lex documentation.


About the Author

Shahab Shekari works as a Software Development Engineer at Amazon AI. He works on scalable distributed systems and enhancing Lex user experiences. Outside of work, he can be found traveling and enjoying the Pacific Northwest with his dogs, friends and family.

 

 

View Original Source (aws.amazon.com) Here.

Leave a Reply

Your email address will not be published. Required fields are marked *

Shared by: AWS Machine Learning

Tags: