Use entities and slot filling in agents

A significant part of agent 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 agent 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, an agent can smartly recognize the relevant information from a user input and save it for later use.

Prebuilt entities

Entities in agents 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, an agent 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.

  1. Open your agent 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.

    Entities pane.

  2. Select the Money entity to open the details pane for the entity.

    Money entity description.

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 agent knows that "1000 dollars" represents the money type of information. When the agent 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 an agent that serves a specific purpose, you might need to teach the agent's language understanding model domain-specific knowledge.

For instance, let's say you want to build an agent for an outdoor store. In this case, you need to teach the agent 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 agent the knowledge of all outdoor product categories.

  1. Open your agent in Copilot Studio and select Settings at the top of the page and then Entities in the menu.

  2. Select Add an entity > New entity.

    Select New entity.

  3. Select the desired 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.

Screenshot of the entity creation window, with the Closed list option highlighted.

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.

Screenshot of the entities list pane.

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.

Screenshot of the Edit synonyms pane.

For each entity, you can also enable Smart matching.

Smart matching is part of the intelligence supported by the agent's language understanding model. With this option enabled, the agent interprets the user's input using fuzzy logic, based on the listed items in the entity.

In particular, the agent can autocorrect misspellings and expand its matching logic semantically. For example, the agent 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.

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 agent.

Screenshot of the entity creation window, with the Regex option highlighted.

After you select this option, 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.

Screenshot of the regex entity pane.

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. For more information on the syntax, and for more examples, see Regular Expression Language - Quick Reference.

If you need the regular expression to 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.

Use entities in a conversation

Now that you've done the work of giving the agent 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 an agent conversation.

  1. Go to the Topics page for the agent you want to edit.

  2. Open the topic for an entity you want to collect.

  3. Select the Add node icon and then select Ask a question.

  4. Under Identify, select the entity you created in Custom entities.

    Question node with entity selection.

  5. 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.

    Screenshot that shows a selection of entity values to be shown as buttons at runtime.

  6. 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.

Let's continue to use the camping activities topic, which is triggered by typing "I want something to do" in the test chat, as an example.

The topic is successfully triggered and the agent 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 agent is running to the question node you just edited.

tracking between topics.

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 happens by inserting the extracted entity "Hiking" into the variable VarCampType.

Variable watch window.

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 agent is able to understand what information belongs to which entity automatically. In cases where it's unsure of the intended mapping, it prompts 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 agent fills in both the entity for choosing an outdoor activity, and for the type of activity.

Multiple and proactive slot filling.

In tracking between topics, you can see the agent takes in this user input, and intelligently skips the question node asking for the type of activity.

The agent 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) and the price range (using the Money entity).

This time when the product category question is presented, instead of telling the agent only the product category, the user can say "I want to buy a pair of hiking boots under $100." In this example, the agent 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.

tracking between topics for product and price categories.

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.

  1. Select the More icon () of the Question node, and then select Properties. The Question properties panel appears.

    Open Question properties panel.

  2. On the Question properties panel, select Question behavior.

  3. On the Question behavior panel, under Skip question, select Ask every time, and then select Save at the top of the page.

    Skip question.