Entities are Dialogflow's mechanism 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 or amounts with units. Any important data you want to get from a user's request will have a corresponding entity.

There are three types of entities:

System entities

Dialogflow is equipped with numerous system entities, which 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

If you need to extract information about concepts beyond those covered by Dialogflow's system entities, you can define your own developer entity types. For example, a brand might create an entity type to recognize its unique set of product names.

Session entities

It is also possible to define entity types that apply only to a specific conversation. For example, you might create an entity type to represent the time-sensitive options available to a particular user when making a booking. These are called session entity types.

What you'll learn

Prerequisites

We will use the same appointment scheduler chatbot that we build in the previous codelabs and enhance it.

  1. Navigate to Go to the Dialogflow Console.
  2. Select the AppointmentScheduler agent that we created in the previous codelab.

  1. Click on "Intents"

  1. Click on "Schedule Appointments" to open the intent settings
  2. You will notice that in the current intent settings there are training phrases like "Set an appointment for 4pm tomorrow" where Date and Time are automatically extracted as system entities date and time. Feel free to add more training phrases to see how Dialogflow extracts the system entities automatically.

  1. 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, phone numbers are some of the common examples of system entities. Find more here.

Create Developer Entities

  1. So far we have been addressing our Appointment scheduler in a generic manner. Let's suppose our scheduler is for a state's Department of Motor Vehicles (DMV) service.
  2. Drivers license and registration are two main services that DMV offers, so let's create those entities.
  3. Click on Entities

  1. Click on "Create Entity" button

  1. Add the Entity Name "AppointmentType" and add "Vehicle registration" and "Driver license" as the two entity entries with a few synonyms and Click Save. See the screenshot for examples to enter.

  1. You can add more rows with more services as entity types.
  2. You can check the box "Allow automated expansion" to add more entities automatically. Automated expansion of developer entities allows an agent to recognize values that have not been explicitly listed in the entity. If a user's request includes an item that isn't listed in the entity, automatic expansion recognizes the undefined item as a parameter in the entity. The agent sees the user's request is similar to the examples provided, so it can derive what the item is in the request.
  1. [For your information] Upload or download entities in bulk:
  1. Click on the three dots near ""Create Entity" button.
  2. You will see "upload Entity" button

  1. Then you can upload a file in CSV or JSON format.

  1. Should end this by saying "click Save"

Edit Intent to accommodate the newly created developer entity

  1. Click on "Intent" on the left pane
  2. Add the training phrase into "Schedule Appointment" intent.
  1. "Set an appointment for drivers license for 3pm tomorrow". You will see that Drivers license is identified as a developer entity "AppointmentType" that we set up in the previous section. System entities time and date are also automatically identified.

  1. Add a few more training phrases like these.
  1. License renewal appointment on Monday
  2. Set an appointment at 2pm on Monday for license
  3. Vehicle registration appointment for Monday

  1. Remember slot filling from the first Codelab? Review slot filling here. In short, to book an accurate appointment, we need all three pieces of information: Appointment Type, Date and Time. If the user only provided one or two pieces then Dialogflow will ask for the left over information before it acts on the response.
  2. We need to make "AppointmentType" a required field just like time and date. To do so, click on the Checkbox near AppointmentType.

  1. Then add a prompt, if the user does not provide appointment type, this prompt will be used. Example prompt: "What services are you looking to get? DMV offers Driver's license and vehicle registration services."
  2. When done, Save the changes.

Let's test our chatbot, you can test it in the simulator or use the web or google home integration we have learnt in previous codelabs.

Test case 1: In this case user only asks to set an appointment without the three pieces of information. Hence, Dialogflow's slot filling asks for the date, time and appointment type using the Slot filling prompts that we set up in "Action and Parameters" section of the intent.

  1. User: "Set an appointment"
  2. Chatbot response: "What date?"
  3. User: "May 23"
  4. Chatbot response: "What time would you like to come in?"
  5. User: "10am"
  6. Chatbot response: "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 user asks to set an appointment with partial information. Hence, Dialogflow's slot filling asks for the date, time and appointment type using the Slot filling prompts that we set up in "Action and Parameters" section of the intent.

  1. User: "Need an appointment for 4pm tomorrow"
  2. Chatbot response: "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 user provides all the information in one shot. Dialogflow processes the information and provides a response with appointment confirmation.

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

If you are planning on doing the other labs in this series, don't do the cleanup now, do it after you are done with all the labs in the series.

Delete the Dialogflow Agent

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

Check out these other resources: