Slot filling allows you to design a conversation flow for parameter value collection within a single intent.
This is useful when an action can't be completed without a specific set of parameter values.
Building an agent
Imagine you want to create an agent for a t-shirt shop. In order to place an order, you need to know the following information:
Knowing this, you can expect a user's conversation to go something like this:
User: I'd like to buy a t-shirt.
Agent: Great, first tell me a couple of things.
Agent: How many do you want?
Agent: What color would you like?
Agent: What size?
Agent: Got it, that was three, black t-shirts in medium. Did I get that right?
Agent: Alright thanks, would you like to keep shopping or checkout?
To use slot-filling, you set these three parameter values to be required. If users omit one or more of the parameters in their response, your agent prompts them to provide values for each missing parameter. The following sections describe how to use slot-filling.
- For the "color" parameter, use
- For the "number" parameter, use
For the "size" parameter, create a custom developer entity, like this:
Add User Says examples
Create a new intent and add examples to the User Says section. These should represent what you can expect a user to say when placing an order. Some examples are:
- I want to buy some t-shirts.
- I need 3 t-shirts
- Do you have any large red t-shirts?
As you add these entries, parameter values within the example should be picked up automatically and annotated:
You'll want to adjust the "number" parameter to use the correct system entity. To do this, click on
@sys.number and choose
@sys.number-integer from the list:
Making parameters required and adding prompts
In the parameter table, check the Required option for all three parameters. This will reveal a Prompts column in the table and a link. Click on this link to set the prompts used to collect the required information from the user:
Adding prompt variations
To make your agent less repetitive, add variants of the prompt for the same parameter:
If a user provides an answer that isn't matched to the entity, the prompts will be repeated until the user provides a valid answer or cancels.
Reference parameter values
You can reference parameter values in prompts, but be sure you only refer to parameter values you've collected prior to the prompt.
For instance, if you collected the value for "color" before "size", you can refer to the "color" by entering the following prompt:
- How many
$colort-shirts would you like to buy?
You can reorder the parameters, which also changes the order the prompts are asked. To reorder parameters, hover your mouse over the parameter row and use the arrow icon to drag to the row up or down. Click the Save button to commit the changes:
Adding a summary response
Now that you've gathered all of the information needed for the order, add a response to the intent that summarizes the parameters:
Parameter values from contexts
If you need to use a parameter you collected in a previous intent or from your server via a query request, you can pass it through a context.
To collect a parameter value from a context, you need to manually define the Value in the following format:
If the parameter value can be obtained from either a context or in a slot filling flow, leave the Value as is and define the Default Value as:
Canceling slot filling dialog
There are two possible scenarios for leaving a slot filling dialog:
- When a user says an exit phrase like "Cancel", "Stop it", "That's enough", etc, the agent replies "Okay, canceled" and clears slot filling contexts.
- If a user input is matched by one of the other intents in the agent. In this case, slot filling contexts are not cleared and it's possible to return to the slot filling dialog with the next query.
In the JSON response to a query, the
actionIncomplete field is set to
true if a slot filling dialog has started, but hasn't been completed. Otherwise,