Now Available: Use Multi-Value Slots to Build More Natural Conversations

Karthik Ragubathy Jan 19, 2021
Share:
CLI Dialog Management
Blog_Header_Post_Img

 

Today we are excited to announce the general availability of Multi-Value Slots, taking a step toward enabling Alexa Skills to understand more complex commands and utterances. As skill developers, you spend a lot of time developing interactions to be more natural and conversational so your customers can have a memorable experience with your skill. One thing that makes conversations more natural is the ability to speak out multiple values of the same type in a single sentence, similar to what we do in our daily conversations. For example, my partner and I could be discussing dinner plans, and I would say, “What can we cook with potatoes and broccoli for dinner?” If you want your customers to be able to have similar conversations with your Alexa skill, you can use Multi-Value Slots in your skill.

Without Multi-Value Slots, here’s how you might have implemented that conversation within your skill.

Customer : Alexa, open recipe suggestions.
Alexa : Welcome to recipe suggestions. Tell me the first ingredient you have today?
Customer : I have potatoes.
Alexa : Got it. what’s the second ingredient you want today?
Customer : Some broccoli
Alexa : Got it. Based on the ingredients you have, Italian Potatoes and Broccoli sounds like a good idea.

With Multi-Value Slots, your Alexa Skill can collect multiple slot values for one slot in the intent. So your conversation looks like this

Customer : Alexa, open recipe suggestions
Alexa : Welcome to recipe suggestions. What are the ingredients you have today?
Customer : I have some potatoes and broccoli.
Alexa : Awesome. As per your ingredients, you can cook Italian Potatoes and Broccoli today.

Multi-Value Slots reduce the amounts of turns in a conversation. Instead of having to ask the customer multiple questions or stringing together multiple slots to get the desired values, you can now use a single slot and capture all the values with Multi-Value Slots.

To enable Multi-Value Slots within your skill, here’s what you need to do

  1. In the Developer Console, open your Skill and open the intent which contains a slot you wish to modify into a Multi-Value Slot. For my recipe suggestions skill, I have a SuggestRecipeIntent which uses the slot ingredients

Intent with utterances that support Multi-Value slot

  2. Clicking on the slot opens up the Slot Detail page. Here ingredients is a custom slot type named Vegetables that I created. On this page, enable the Multi-Value setting to indicate that the slot can collect multiple values. Once done, save and build your model. 

 

Enable Multi-Value option on the Slot Detail Page

    3. To handle and process the slot values in your skill’s backend, we will have to make some changes to the backend code. For this skill, I am using the ASK SDK in Nodejs hosted in a Lambda function. We start off by defining a getFirstResolvedEntityValue function, which looks at the resolutionsPerAuthority slot object and retrieves entity with highest confidence score.  

 

Copied to clipboard
const getFirstResolvedEntityValue = (element) => {
    const [firstResolution = {}] = element.resolutions.resolutionsPerAuthority || [];
    return firstResolution && firstResolution.status.code === 'ER_SUCCESS_MATCH'
        ? firstResolution.values[0].value.name
        : null;
};

    4. Once we retrieve the entities, we will call the getFirstResolvedEntityValue helper function and get a list of all the values. We can now concatenate all the multiple slot values in a single string or use it for further processing.

Copied to clipboard
// Concatenates all captured slot values to a single string.
const getReadableSlotValue = (handlerInput, slotName) => {
    const rootSlotValue = Alexa.getSlotValueV2(handlerInput.requestEnvelope, slotName);
    const PAUSE = '<break time="0.25s"/>';
    const slotValueStr = !rootSlotValue
        ? 'None'
        : Alexa.getSimpleSlotValues(rootSlotValue)
              .map(
                  (slotValue) =>
                      getFirstResolvedEntityValue(slotValue) || `${slotValue.value}`
              )
              .join(' ');
    return `${slotName} ${PAUSE} ${slotValueStr}`;
};

    5. And finally, within the SuggestRecipeIntentHandler, we will call the getReadableSlotValue function and pass the ingredients slot. This will return us the single string generated and we can use it to inform the customer that we are searching for recipes. 

Copied to clipboard
// Handler for SuggestRecipe Intent which uses Multi-value slots to populate slot values.
const SuggestRecipeIntentHandler = {
    canHandle(handlerInput) {
        return (
            Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' &&
            Alexa.getIntentName(handlerInput.requestEnvelope) === 'SuggestRecipeIntent'
        );
    },
    handle(handlerInput) {
        const ingredientResponse = getReadableSlotValue(handlerInput, 'ingredients');
        const speakOutput = `Searching for recipes with ${ingredientResponse}`;
        return handlerInput.responseBuilder.speak(speakOutput).getResponse();
    },
};

And that’s it, your skill can now capture multiple slot values and enable natural conversations with your customers. You can also refer to our cookbook for sample code on implementing Multi-Value Slots in your skill. As you leverage the power of Multi-Value Slots to create more engaging experiences, it’s important to understand how it works in different scenarios so you can design the right experience for your skill. Here are a few tips to enable you to use them even better.

  1. Test your interaction model : Once you have built your model, use the Test page in the Developer Console to test your Multi-Value Slots with a variety of utterances. Try testing your slots with both single values and a list of values.

    When you type utterances in the Test page, separate the slot values with either spaces, or spaces and commas.
    For example, both these utterances would work
    "potato broccoli and spinach"
    "potato, broccoli, and spinach"

    Apart from manually testing them, you can also use the Utterance Profiler and the NLU Evaluation tool to improve your model’s accuracy. If you discover values that Alexa fails to recognize, add the values to your slot type to improve recognition.

  2. Avoid Ambiguities : If your slot accepts values that have multiple values in them, ensure they are added as slot values. For example, include values such as sour cream and onion chips in a GroceryList slot type. This would ensure that when the customer says “add sour cream and onion chips to my cart” you receive these values as “sour cream” and “onion chips” instead of “sour”, “cream”, “onion,” or “chips”.

    When the utterance is ambiguous, depending on the slot type values it could be interpreted in multiple ways.

        a. When the slot type catalog only contains "sour cream" and "onion chips" as separate values, Alexa interprets the utterance as separate values ("sour cream", "onion chips").

        b. When the slot type catalog contains all three ("sour cream and onion chips", "sour cream", "onion chips"), Alexa chooses the longest slot value and therefore interprets the utterance as a single value "sour cream and onion chips". In this case, users can still get the separate values by changing the way they word the utterance. For example, "add onion chips and sour cream" would return the two separate values ("sour cream", "onion chips"). 

        c. If you are using multiple value slot with Dynamic Entities, avoid including entities that can cause ambiguities in your catalog. For example, in the above example adding values like sour and cream will give you less accurate results in identifying the value “sour cream”.

    While you can use the slot types for numbers, dates, and times, you will find that you get will get more accurate results with custom slot types and built-in list slot types such as AMAZON.Actor, AMAZON.Animal.

    When using a Custom Slot Type, ensure that your catalog has all the possible values. If you create a large list of custom slot values and encounter limit on the size of interaction model, prioritize the most likely values. Multi-Value Slots will favor recognizing the longest value entity. Since recognition is better when there are less than five items within the utterance, ensure your slot design does not force the customer to list more than five items at a time. 

  3. Use the Controls Framework : When building a complete skill that uses Multi-Value Slots, you may want assistance with state management, validations, confirmation, interaction-model building, and APL for multimodal data input. Today, we are also releasing a new Control in the Controls Framework that offers these features built-in and with extensive customizations. The MultiValueListControl enables you to easily integrate Multi-Value Slots into your skills easily. To add Multi-Value support to your skill, integrate the MultiValueListControl as a child control to your skill. Here’s how you can use it within your Skill’s backend code. 

Copied to clipboard
let listControl = new MultiValueListControl({
    id: 'myShoppingList',
    validation: function(vals) { // validation function
     ...
   }, 
    listItemIDs:['Pepperoni', 'Cheese', 'Sausage', 'Olives'], // slotIDs of the slotType to suggest/present
    slotType: 'PizzaToppings', // 
    confirmationRequired: () => true,
    prompts: {
        confirmValue: () => 'Is that all?',
    },
});

rootControl.addChild(mvsControl);

One benefit of using MultiValueListControl is that it can also help validate input values from customers. Here’s how that conversation would look

Customer: Add pepperoni and cheese to my pizza.
Alexa: OK, added pepperoni and cheese, is that all?
Customer: Can you add anchovies as well?
Alexa: Sorry, we don’t have anchovies as a topping. Please choose a value from pepperoni, cheese, sausage, or olives.
Customer: Olives.
Alexa: OK, added olives. Is that all?


You can learn more about MultiValueListControl here

By implementing Multi-Value Slots and following these best practices, you will be able to design voice experiences where your customers can have natural conversations. You can learn more about Multi-Value Slots in our technical documentation and the overview video

Subscribe