Understand entities in Dialogflow

1. Before you begin

Entities are a mechanism in Dialogflow for identifying and extracting useful data from natural-language inputs. While intents allow your agent to understand the motivation behind a particular user input, entities are used to pick out specific pieces of information that your users mention—anything from street addresses to product names and amounts with units. Any important data that you want to get from a user's request will have a corresponding entity.

The following list explains the three types of entities:

  • System entities, which come with Dialogflow, allow agents to extract information about a wide range of concepts without any additional configuration. For example, system entities are available for extracting dates, times, and locations from natural-language inputs.
  • Developer entities, which you define, extract information about concepts beyond those covered by system entities. For example, a brand might create a developer entity to recognize its unique set of product names.
  • Session entities, which you also define, only apply to a specific conversation. For example, you might create a session entity to represent the time-sensitive options available to a particular user when making a booking.

Prerequisites

Before proceeding, you need to complete the following codelabs:

  1. Build an appointment schedule with Dialogflow
  2. Integrate a Dialogflow chatbot with Actions on Google

You also need to understand the basic concepts and constructs of Dialogflow, which you can glean from the following videos found in the Build a chatbot with Dialogflow pathway:

What you'll learn

  • How to create and use system entities in Dialogflow
  • How to create and use developer entities in Dialogflow
  • How to test the agent

What you'll build

  • An enhanced version of an already-built Dialogflow agent
  • Developer entities in Dialogflow
  • System entities in Dialogflow

What you'll need

  • A web browser and an email address to log into Dialogflow console

2. How to enable and use system entities in Dialogflow

  1. Navigate to the Dialogflow console.
  2. Select the AppointmentScheduler agent that you previously created.

ecedc445a9578e3b.png

  1. Click Intents.

37ee739b69fa1ae7.png

  1. Click Schedule Appointments to open the intent settings.

You'll notice training phrases like "Set an appointment for 4 PM tomorrow," where Date and Time are automatically extracted as @sys.date and @sys.time. Feel free to add more training phrases to see how Dialogflow automatically extracts the system entities.

7dcdad1372191f90.png

As you saw, system entities allow agents to extract information about a wide range of concepts without any additional configuration. Data like address, emails, currency, and phone numbers are some of the common examples of system entities. Find more, see System Entities.

3. How to enable and use developer entities in Dialogflow

Create developer entities

So far, you addressed your appointment scheduler in a generic manner. Now, suppose that your scheduler is for a state's department of motor vehicles office, which mainly offers driver licenses and registration services. Create those entities.

  1. Click Entities.

4d8924f1d4edc0d1.png

  1. Click Create Entity.

b77e94e5e47adbc7.png

  1. Enter "AppointmentType" as the Entity name, then add "Vehicle registration" and "Driver license" as the two reference values with a few synonyms as seen in the following image. Click Save.

51562b4327dbaf1.png

You can add more rows with more services as entity types.

  1. Click Save.

Edit intent to accommodate the newly created developer entity

  1. Click Intent.
  2. Enter "Set an appointment for drivers license for 3 PM tomorrow" into the schedule appointment intent.

You'll see the automatic recognition of drivers license, at 3 PM, and tomorrow as developer and system entities.

5fb91b31806f06f.png

  1. Enter the following training phrases:
  2. License renewal appointment on Monday
  3. Set an appointment at 2 PM on Monday for license
  4. Vehicle registration appointment for Monday

5addff06908c61f8.png

  1. You need to make AppointmentType a required field, similar to time and date. To do so, go to Actions and Parameters, then select the checkbox in the AppointmentType row.

c43e72c5c1a43f5c.png

  1. Add a prompt, such as "What services are you looking to get? DMV offers driver's license and vehicle registration services." If the user doesn't provide an appointment type, then the prompt will be used.
  2. Click Save.

4. Test your chatbot

You can test your chatbot in the Actions simulator, or use the web or Google Home integration that you previously learned.

Test case 1

In this case, the user only asks to set an appointment without the three pieces of information, so Dialogflow asks for the date, time, and appointment type using the slot-filling prompts that you set.

  1. User: "Set an appointment."
  2. Chatbot: "What date?"
  3. User: "May 23."
  4. Chatbot: "What time would you like to come in?"
  5. User: "10 AM"
  6. Chatbot: "What services are you looking to get? DMV offers driver's license and vehicle registration services."
  7. User: "License."
  8. Chatbot: "You are all set for your vehicle registration appointment on 2019-05-23 at 10:00:00. See you then!"

Test case 2

In this case, the user asks to set an appointment with partial information, so Dialogflow asks for the date, time, and appointment type using the slot-filling prompts that you set.

  1. User: "Need an appointment for 4 PM tomorrow."
  2. Chatbot: "What services are you looking to get? DMV offers driver's license and vehicle registration services."
  3. User: "License."
  4. Chatbot: "You are all set for your drivers license appointment on 2019-04-24 at 16:00:00. See you then!"

Test case 3

In this case, the user provides all the information. Dialogflow processes the information and provides a response with appointment confirmation.

  1. User: "Set an appointment for vehicle registration at 2 PM tomorrow."
  2. Chatbot: "You are all set for your vehicle registration appointment on 2019-04-24 at 14:00:00. See you then!"

5. Clean up

If you plan to complete other Dialogflow codelabs, then skip this section for now and return to it later.

Delete the Dialogflow agent

  • Click fe9c61cc27fb9f2e.png next to your existing agent.

520c1c6bb9f46ea6.png

  • In the General tab, scroll to the bottom and click Delete This Agent.
  • Type Delete into the dialog and click Delete.

6. Congratulations

You built a chatbot that handles custom inputs with developer entities. You're now a chatbot developer!

Learn more

Check out the following resources to learn more: