Use entities and slot filling in copilots
A significant part of copilot conversations in Copilot Studio is natural language understanding, which is the ability for the AI to understand a user's intent. For example, the user might say "I tried to use my gift card but it doesn't work" and the copilot knows to route the user to the topic related to gift cards not working, even if that exact phrase isn't listed as a trigger phrase.
One fundamental aspect of natural language understanding is to identify entities in a user dialog. Watch the video to get started with entities.
An entity can be thought of as a unit of information that represents a certain type of a real-world subject, like a phone number, zip code, city, or even a person's name. With the knowledge granted by entities, a copilot can smartly recognize the relevant information from a user input and save it for later use.
Prebuilt entities
Entities in copilots let you store information in similar groups.
Out of the box, Copilot Studio comes with a set of prebuilt entities, which represent the most commonly used information types in real-world dialogs, such as age, colors, numbers, and names.
With the knowledge granted by entities, a copilot can smartly recognize the relevant information from a user input and save it for later use.
To help understand that notion, the Money entity can be used as an example.
Open your copilot in Copilot Studio and select Settings at the top of the page and then Entities in the menu.
A list of the prebuilt entities that are available is shown.
Select the Money entity to open the details pane for the entity.
Here you can see an explanation of this entity and the ways it can be used to look for information related to money or currency from a user's input.
For example, when a user inputs "It costs 1000 dollars," using this money entity the copilot knows that "1000 dollars" represents the money type of information. When the copilot extracts this entity and saves it to a variable, it saves "1000" as a number even though the surrounding information was text.
Custom entities
The prebuilt entities cover commonly used information types. On some occasions, such as when building a copilot that serves a specific purpose, you might need to teach the copilot's language understanding model domain-specific knowledge.
For instance, let's say you want to build a copilot for an outdoor store. In this case, you need to teach the copilot to acknowledge the "outdoor gears product" category in a dialog.
First, create a custom entity. In this case, you can create an entity that gives the copilot the knowledge of all outdoor product categories.
Open your copilot in Copilot Studio and select Settings at the top of the page and then Entities in the menu.
Select Add an entity > New entity.
A new pane opens where you can choose the type of entity: either a Closed list entity or a Regular expression (regex) entity.
Closed list entities
Closed list entities let you define a list of items. These entities are best used for small lists that are easy to manage and that have simple item labels.
Selecting this option when creating an entity shows a pane where you can specify the name of the entity, an optional description, and enter the items you want included in the entity.
When you enter items, you can:
- Select each item and change its name.
- Select the trash can icon to delete the item from the list.
- Select + Synonyms (or select the listed synonyms if they're already added) to open the Edit synonyms pane.
You can add synonyms to manually expand the matching logic for each item in the entity's list. For example, in the "hiking" item, you can add "trekking" and "mountaineering" as synonyms.
For each entity, you can also enable Smart matching.
Smart matching is part of the intelligence supported by the copilot's language understanding model. With this option enabled, the copilot will interpret the user's input using fuzzy logic, based on the listed items in the entity.
In particular, the copilot will autocorrect misspellings and expand its matching logic semantically. For example, the copilot can automatically match "softball" to "baseball".
When you're finished creating or editing your entity, select Save to save and return to the list of entities. Select Close to discard your changes (you'll be given an option to go back to editing the entity in case you accidentally selected the wrong option).
Regular expression (regex) entities
Regular expression (regex) entities let you define logical patterns that you can use to match and extract information from an input. Regex entities are great for complex pattern matching against a user's input, or if you need to allow for specific variations in how a user might format or enter their input in a conversation.
For example, you could use a regex entity to identify items such as a tracking ID, a license number, a credit card number, or an IP address from a string the user enters into the copilot.
Selecting this option when creating an entity will show a pane where you can specify the name of the entity, an optional description, and enter the regex pattern that should be used to match and extract entity items from the input.
A Copilot Studio regex entity uses the .NET regular expressions syntax.
By default, pattern matching is case sensitive, to make it case insensitive use the (?i)
regular expression option in your pattern string. Some basic examples are included in the regex entity pane, and additional information on the syntax and more examples can be found in the Regular Expression Language - Quick Reference topic.
If you need to make the regular expression accommodate multiple patterns you can use the alternation operator |
to concatenate regular expressions. For example, you could combine two regex patterns to look for both the old and new formats of a product ID code.
When you're finished creating or editing your entity, select Save to save and return to the list of entities. Select Close to discard your changes (you'll be given an option to go back to editing the entity in case you accidentally selected the wrong option).
Use entities in a conversation
Now that you've done the work of giving the copilot the knowledge about outdoor gear by creating that product category entity and a few other custom entities, you can start to use them when constructing a copilot conversation.
Go to the Topics page for the copilot you want to edit.
Open the topic for an entity you want to collect.
Select the Add node icon
and then select Ask a question.
Under Identify, select the entity you created in Custom entities.
You can also optionally select items to show as buttons. For example, if you'd like to show some categories as buttons for users to conveniently choose from as their input, you can choose Select options for user and then pick them from the list that contains the items you added when you created the custom entity.
Name the variable for the output of the user's response, if necessary.
Slot filling
Slot filling is a natural language understanding concept that means saving an extracted entity to an object. However, in Copilot Studio, slot filling means placing the extracted entity value into a variable.
We'll continue to use the camping activities topic as an example, which is triggered by typing "I want something to do" in the test chat.
The topic is successfully triggered and the copilot asks for the type of activity, also showing the button choices specified when authoring the Ask a question node. In the dialog tree, tracking between topics also shows the copilot is running to the question node you just edited.
A user can use the predefined choices by selecting one of the buttons. Alternatively, they can also type in something like "trekking" and see that it maps to "hiking", because those words were defined as synonyms.
In tracking between topics, it shows the dialog is correctly routed to the path in which the product category value is "Hiking". You can inspect the variable value from the variable watch window at the bottom of the authoring canvas. In the watch window, it shows the variable value is "Hiking".
Essentially, slot filling has happened by inserting the extracted entity "Hiking" into the variable VarCampType
.
You can also use what is known as "proactive slot filling" where the user can specify multiple pieces of information that map to multiple entities. The copilot is able to understand what information belongs to which entity automatically. In cases where it's unsure of the intended mapping, it will prompt the user to be more specific by providing choices.
In this example, the user wrote "I'm bored but I like mountaineering." This message includes both the trigger phrase that the user wants help with outdoor activities and also provides a second piece of information, "mountaineering", which is an entity-defined synonym for hiking. In this case, the copilot fills in both the entity for choosing an outdoor activity, and for the type of activity.
In tracking between topics, you can see the copilot takes in this user input, and intelligently skips the question node asking for the type of activity.
The copilot is always actively listening to the user input, remembering information upfront so it can skip unnecessary steps as appropriate.
Let's restart the testing again and try another case. In this round, you can add a couple more question nodes asking for things like how much time you have for the activity (using the Duration entity) as well as the price range (using the Money entity).
This time when the product category question is presented, instead of telling the copilot only the product category, the user can say "I want to buy a pair of hiking boots under $100". In this example, the copilot isn't only able to route to the correct hiking product category path, but also actively fill the slots asking for the type of hiking gear and the target price range information.
Proactive slot filling can be manually controlled at the node level. If you'd like to always prompt for the question within a specific node, regardless of whether the slot has been filled from previous user responses, you can disable the Skip question option for that question node. Perform the following steps to disable the Skip question option.
Select the More icon (…) of the Question node, and then select Properties. The Question properties panel appears.
On the Question properties panel, select Question behavior.
On the Question behavior panel, under Skip question, select Ask every time, and then select Save at the top of the page.