Create a Dialogflow ES agent

Use the Dialogflow ES console to build and test an agent.

Before you begin

Before you begin, complete the following steps:

Create an agent

  1. Go to the Dialogflow ES console.
  2. Sign in to the Dialogflow console if prompted. For more information, see Dialogflow console overview.
  3. In the sidebar menu, click Agents.
  4. Select the Your deployed agents tab.
  5. Click Create agent.
  6. Enter the agent name, default language, and default time zone.
  7. Enter an existing project. To let the Dialogflow console create a project, select Create a new Google project.
  8. Click Create.

Intents

Intents categorize an end-user's intention for one conversation turn. For each agent, you define many intents that together handle a complete conversation.

Default intents

When you create an agent, Dialogflow creates two default intents for you:

  • Default Welcome Intent: This intent matches when the end-user begins a conversation with your agent. It returns a response that lets the end-user know what your agent does or what they can say to begin a conversation.
  • Default Fallback Intent: This intent matches when the agent cannot match the end-user expression to any other intent.

To see these intents, go to the intent list for your agent:

  1. Go to the Dialogflow ES console.
  2. Select the agent you created.
  3. Click Intents in the sidebar menu.

The middle of the Dialogflow console shows the list of intents for the agent.

Intents list screenshot

Test the Default Fallback Intent

Simulator screenshot

The Dialogflow simulator is on the right side of the console. With the simulator, you can test your agent by speaking or typing messages.

Try the agent now:

  1. Click the Try it now field.
  2. Type What is your name?.
  3. Press Enter.

The agent's response appears in the Default Response section. Since your input didn't match any intent, the Default Fallback Intent was matched, and you received one of the default replies.

Create an intent

The steps in this section create an intent that answers the question "What is your name?" For each intent, you define many training phrases. A training phrase is an example of what an end-user might type or say to your agent, also known as an end-user expression. Define training phrases that help Dialogflow match expressions to an intent.

Create an intent:

  1. Click the add intent button next to Intents in the sidebar menu.
  2. Enter get-agent-name in the Intent name field.
  3. In the Training Phrases section, click Add training phrases.
  4. Enter the following training phrases:

    • What is your name?
    • Do you have a name?
    • Tell me your name

    Training phrases screenshot

  5. In the Responses section, enter the following in the Text Response section:

    • My name is Dialogflow!

    Training phrases screenshot

  6. Click the Save button and wait until the Agent Training dialog indicates that training is complete.

Test your intent

Simulator screenshot

In the simulator, type What's your name? and press Enter.

The agent responds to the expression correctly, even though the expression differs slightly from the training phrases provided.

Dialogflow uses training phrases as examples for a machine learning model to match end-user expressions to intents. The model checks the expression against every intent in the agent, assigns a score to each intent, and matches the highest scoring intent. If the highest scoring intent has a very low score, the fallback intent is matched.

Parameters and entities

When an intent is matched at runtime, Dialogflow provides the extracted values from the end-user expression as parameters. Each parameter has a type, called the entity type, which dictates exactly how the data is extracted. Unlike raw end-user input, parameters are structured data that can easily be used to perform some logic or generate responses.

To control how data is extracted when building an agent, annotate parts of your training phrases and configure the associated parameters.

Create parameters

Create intent parameters:

  1. Click the plus button next to Intents in the sidebar menu.
  2. Name the intent set-language at the top of the intent form.
  3. Add the following training phrases:
    • I know English
    • I speak French
    • I know how to write in German
  4. Click the Save button and wait until the Agent Training dialog indicates that training is complete.

    Annotated training phrase screenshot

Dialogflow automatically detects parameters in training phrases that are recognized as system entities. These are entities provided by Dialogflow for many common data types, such as location, color, and date.

After you add training phrases, Dialogflow creates a row in the Action & parameters table:

Annotated training phrase screenshot

  • Required: Not checked; this parameter is optional.
  • Parameter Name: Automatically named language because it is recognized as a language.
  • Entity: Recognized as a @sys.language system entity.
  • Value: The identifier used when referencing the value of this parameter.
  • Is List: Not checked; this parameter is not a list.

Use parameter data in a response

You can use the value of a parameter in your responses. For example, you can use the $language parameter reference in your responses when building an agent. At runtime, the agent replaces it with the language specified in the end-user expression.

Add a response that uses a parameter:

  1. Go to the Responses section.
  2. In the Text Response section, add the following: Wow! I didn't know you knew $language.
  3. Click the Save button and wait until the Agent Training dialog indicates that training is complete.

Test your parameter

Simulator screenshot

In the simulator, type I know Russian. You can see that Dialogflow correctly extracts the language parameter with the value Russian, and Russian was correctly inserted where the parameter reference was used in the response.

Create your own entities

In most cases, you need to gather specific data from users that is not provided by system entities. You can create custom entities to handle this.

Create a custom entity:

  1. Click the add entity button next to Entities in the sidebar menu.
  2. Enter language-programming for the name of the entity.
  3. Add the following entity entries (rows):

    Reference Value Synonyms
    JavaScript JavaScript, js, ECMAScript
    Java Java
    Python Python, py
  4. Click the Save button and wait until the Agent Training dialog indicates that training is complete.

Entity use screenshot

Dialogflow can handle simple cases like plurality and capitalization. Add all possible synonyms for your entries. The more synonyms you add, the better your agent can identify your entities.

Use your new entity

Add training phrases to the set-language intent that use the new entity:

  1. Click Intents in the sidebar menu.
  2. Click the set-language intent.
  3. Add the following training phrases:
    • I know javascript
    • I know how to code in Java
  4. Observe that the programming languages in these training phrases are automatically annotated and added to parameters in the Action and Parameters section.
  5. In the Responses section, add the following second text response: $language-programming is an excellent programming language.
  6. Click the Save button and wait until the Agent Training dialog indicates that training is complete.

Test your new entity

Simulator screenshot

In the simulator, enter I know how to code in py. Dialogflow correctly extracts py for the language-programming parameter, identifies it as the Python entity, and inserts the value into the response.

Contexts

To control the flow of the conversation, you can use contexts.

Add a follow-up intent

Follow-up intents let you control a conversation without manually creating and managing contexts.

When you create a follow-up intent, an output context is added to the parent intent, and an input context of the same name is added to the child intent. This means the follow-up intent is matched only when the parent intent is matched in the previous conversational turn.

Add a custom follow-up intent to the set-language intent:

  1. Select the set-language intent you created in previous steps.
  2. In the Response section, update the text response:
    • Wow! I didn't know you knew $language. How long have you known $language?
  3. Click the Save button and wait until the Agent Training dialog indicates that training is complete.
  4. Click Intents in the sidebar menu.
  5. Point the cursor at the set-language intent and click Add follow-up intent.
  6. Click Custom in the list.
  7. Click the Save button and wait until the Agent Training dialog indicates that training is complete.

Dialogflow automatically names the follow-up intent set-language - custom.

Followup screenshot

Intent matching with follow-up intents

Follow-up intents are matched only after the parent intent is matched. Because the set-language - custom intent is matched only after the set-language intent, the user has just been asked the question, "How long have you known $language?" Add training phrases for likely user answers to that question:

  1. Click Intents in the sidebar menu.
  2. Click the set-language - custom intent.
  3. Add the following training phrases:
    • 3 years
    • about 4 days
    • for 5 years
  4. Click the Save button and wait until the Agent Training dialog indicates that training is complete.

Test your follow-up intent

Enter I know French in the simulator, and then answer the question How long have you known French with about 2 weeks.

Despite there being no response for the second expression (about 2 weeks), you see the expression is matched to the correct intent (set-language - custom), and the duration parameter is correctly parsed (2 weeks).

Intents and contexts

Inspect the set-language intent to see that set-language-followup is listed as an output context prefaced by the number 2. This number is called the lifespan.

Output context screenshot

After the set-language intent is matched, the set-language-followup context is active and attached to the conversation for two turns (lifespan of 2). Therefore when you respond to a question like How long have you known $language?, the set-language-followup context is active.

Inspect the set-language - custom intent to see that set-language-followup is listed as an input context, which is the same as the output context for the set-language intent.

Any intents with an input context that matches an active context are prioritized when Dialogflow matches intents.

Contexts and parameters

Contexts store parameter values, and you can access the values of parameters defined in the set-language intent when its output context is active. In the set-language - custom intent, you only asked for the duration the user has known the language, and not the referenced language itself.

To reference the language in the response:

  1. Update the set-language - custom intent text response to I can't believe you've known #set-language-followup.language for $duration!
  2. Click the Save button and wait until the Agent Training dialog indicates that training is complete.

The #set-language-followup.language reference is a parameter reference for an active context.

Test the context parameter

Enter I know French in the simulator, and then respond to the question with 1 week. Notice that the language parameter value is retrieved from the context.

Production

Before running your agent in production, implement the production best practices.

What's next

Try the Fulfillment quickstart.