Checkpoints
Enable API
/ 20
Create an Agent
/ 30
Test the agent
/ 50
Dialogflow CX: Bot Building Basics
GSP928
Overview
Dialogflow CX provides a simple, visual bot building approach to virtual agent design. Bot designers now have a much clearer picture of the overall bot building process and multiple designers are able to easily collaborate on the same agent build. Dialogflow CX supports many languages for your agent to use and understand, but this lab will be using only English.
In this lab you will build a conversational agent using Dialogflow CX.
Prerequisites
You should be generally familiar with the basic concepts of conversational AI. Read through these Sample Transcripts to get an idea of what client transcripts might look like. Often the first step in creating an agent is to read through client transcripts and/or other contextual data to understand the use case and specific business requirements.
Setup
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud Console
-
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
- The Open Google Console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Console. The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username from the Lab Details panel and paste it into the Sign in dialog. Click Next.
-
Copy the Password from the Lab Details panel and paste it into the Welcome dialog. Click Next.
Important: You must use the credentials from the left panel. Do not use your Google Cloud Skills Boost credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
Click through the subsequent pages:
- Accept the terms and conditions.
- Do not add recovery options or two-factor authentication (because this is a temporary account).
- Do not sign up for free trials.
After a few moments, the Cloud Console opens in this tab.
Enable the Dialogflow API
-
In the console search field, type in "Dialogflow API".
-
Select the Dialogflow API tile.
-
Click the Enable button.
Task 1. Create your agent
- Visit the Dialogflow CX console, then select your Cloud Project name. Your Cloud Project name should match your Project ID for your lab like: qwiklabs-gcp-xx-xxxxxxxxxxx
Click Check my progress to verify the objective.
- Click Create agent. If you do not see this page, refresh your browser.
-
Name your agent
Flight booker
. -
Pick global from the Location drop-down.
-
Click Create.
-
After creating the agent, navigate to Agent Settings > General > Logging settings and check the boxes next to Enable Cloud Logging and Enable interaction logging option. It will generate logs for this agent.
-
Click Save.
Click Check my progress to verify the objective.
Knowledge check
Task 2. Intents
Intents are the reasons an end-user has for interacting with the agent, for example, ordering something. You can create an intent for every topic they may want to navigate.
Intents can be reused across Pages and Flows. Each intent is defined by training phrases end-users typically ask. These can be annotated or "labeled" to collect specific parameters, such as arrival city or departure date.
Dialogflow CX will suggest annotations as you include training phrases for the intent; they can also be manually annotated to collect the parameter values you want to extract from the end-user's interaction with your agent.
Recommended: in order to reuse intents as well as make maintenance easier, name your intents with clear and explicit names.
Format of intent: category.some_description
Example of formatting:
-
Core Intents:
main.book_a_flight
-
Common intent but not core:
supplemental.flight_emissions
-
Reusable intents:
confirmation.yes
,confirmation_no
,redirect.live_agent
.
Create your first intent
- Click Manage > Intents > Create :
-
Display Name:
main.book_a_flight
-
Under the Training Phrases header, add each of the following phrases into Dialogflow, click Enter after each phrase:
- Book a flight
- Can you book my flight to San Francisco next month
- I want to use my reward points to book a flight from Milan in October
- My family is visiting next week and we need to book 6 round trip tickets
- Four business class tickets from Taiwan to Dubai for June 2nd to 30th
- I need a flight Saturday from LAX to San Jose
- Book SFO to MIA on August 10th one way
- Help me book a ticket from 4/10 to 4/15 from Mexico City to Medellin Colombia please
- I am booking a surprise trip for my mom, can you help arrange that for May 10th to May 25th to Costa Rica
- Do you have any cheap flights to NYC for this weekend
- I want to fly in my cousin from Montreal on August 8th
- I want to find two seats to Panama City on July 4th
- For my wedding anniversary we want to go to Seattle for Christmas
- Click Save.
- Some words are highlighted because Dialogflow has automatically labeled the entities, such as a date, place, or number.
Task 3. Flows and pages
Flows are used to define topics and the associated conversational paths. Every agent has one flow called the Default Start Flow. This single flow may be all you need for a simple agent.
More complicated agents may require additional flows, and different development team members can be responsible for building and maintaining these flows.
Every flow starts with a Page, and is made of one or multiple different pages thereafter to handle the conversation within a particular flow. The current page an end-user is on is considered the "active page". Each page can be configured to collect any required information from the end-user.
Build from your Default Start Flow
The page your agent starts from is called the Default Start Flow. Pages store routing logic, responses (known as Fulfillment), specific actions to take if an intent cannot be matched (known as no-match) or receives no-input (which is when the agent does not receive a response in time).
- Click Build.
- Click Start to open the page.
- From the expanded options on the Start page, select the + icon next to Routes.
- Select the intent main.book_a_flight from the drop-down, then click Save.
-
Next, in the Routes section, click the main.book_a_flight route.
-
Scroll down to Transition and choose + new Page from the drop-down.
-
Name the page
Ticket information
and click Save.
- Exit out of the windows to return to the main display of flows to see your new Ticket information page connected to the Start page.
The beginning of the flow now includes a greeting, and will then proceed to the Ticket information page when the main.book_a_flight
intent is matched. On the Ticket Information page you will collect parameters from the end-user so they can book their flight.
Task 4. Entities and parameters
-
Entities define the type of information you wish to extract from an end-user, ex: city you want to fly to. Use Dialogflow's built-in " system entities'' for matching dates, times, colors, email addresses, and so on.
-
System entities can also be “extended” to include values that are not part of the default system values. If you need to create a fully customized entity, you can do so by creating a Custom Entity type for matching data that is custom to your business and not found as a system entity.
-
Parameters are information supplied by the end-user during a session, such as date, time, and destination city. Each parameter has a name and an entity type. They are written in snake_case (lowercase with underscores between words)
Create your first set of parameters
Next you will use an entity to extract a required parameter from the end-user.
- Click on the page Ticket Information, then the + by Parameters to collect flight data.
- Enter
departure_city
in the Display name field. - Choose
@sys.geo-city
from the Entity type drop-down. - Scroll down to Initial prompt fulfillment > Agent Says and add
What city would you like the flight to depart from?
- Click Save.
- Exit out of this window to make another parameter.
- Click the + by Parameters again to create 4 additional parameters one by one with the following name, entity type, and how the agent will prompt the end-user.
Display name | Entity type | Agent says |
---|---|---|
departure_date | @sys.date | What is the month and day of the departure? |
destination_city | @sys.geo-city | What is your destination city? |
return_date | @sys.date | What is the month and day for the returning flight? |
passenger_name | @sys.any | What is the passenger's name? |
When finished they are listed like this:
Knowledge check
Task 5. Conditions
Once the agent has collected the necessary 5 flight booking parameters, you want to route the end user to another page using a routing condition, which you will create next.
- Exit out of the parameter window to return to the Ticket information page again.
- Scroll down to locate Routes and click the + sign next to it.
- Scroll down to Condition > Condition rules > select "Match AT LEAST ONE rule (OR)"
- In the Parameter field enter
$page.params.status
. - Choose the
=
sign in the Operand drop-down. - In the Value field enter:
"FINAL"
(ensure you include the double quotes). - Click Save.
Knowledge check
Task 6. Fulfillment
Now add a response to say to the end-user when all 5 of their booking parameters are collected. These responses are called Fulfillment.
- From the condition you just made, scroll down a bit and locate the section called Fulfillment.
- Under Agent says type the following:
Thank you for that information. Let me check on the availability of your ticket
. - Click Save.
(Now stay on this page while you read on to the next step of confirming information.)
Task 7. Confirming information
After offering a response (or fulfillment), you need to create a transition to a new page that will repeat back to the end-user if the travel information collected (parameters) are correct.
- Continue to scroll down (past the fulfillment you just created) until you reach Transition.
- On the Page field, select the drop down to choose + new Page.
- Type
Confirm trip
in the field called Page name.
- Click Save.
- Exit out of the window.
- Take a look at the flow of your 3 pages.
Repeating back the parameters collected from end-users
Session Parameters store information previously collected from the end-user and are active throughout the session. They also help you repeat information back to the end-user.
For example, we can have the agent repeat back a passenger's name: "Thanks for providing that information, $session.params.passenger_name." This displays to the end-user as "Thanks for providing information, John Day."
They are formatted as follows:
- Prefix: $session.params.
- Entity Name: passenger_name
So referencing the departure city would look like: $session.params.departure_city
- Starting from the Build view, click on the Confirm Trip page > Entry fulfillment > Edit fulfillment field.
-
Since you used 5 parameters, you can repeat them back to the user via the following session parameters. Paste the following text within the Agent says section:
- Then click Save.
- This is what it will look like to the end-user when the virtual agent repeats back the collected session parameters:
Positive confirmation route
- Exit out of the window to return to your Confirm Trip page. Click + next to Routes.
- Click the Intents drop-down , then click + new Intent.
- In Display name type
confirmation.yes
. - In Training phrases enter
yes
then Enter (you can add more phrases like "correct", "yup", etc., to improve the NLU matching for this intent).
- Click Save.
- After saving, scroll down to the Fulfillment section and enter
Great, your flight is booked!
-
Then click Save.
-
Click the back arrow, next to Route.
Negative confirmation route
Now add logic to route an end-user to recollect their flight parameters if they say the information is incorrect.
- Still on the Routes section select Add route.
- From the Intents drop-down choose + new Intent.
- Name the intent
confirmation.no
in the Display name field.
- Scroll down to the Training phrases section type
no
then click Enter.
- Click Save.
- Next, scroll down to the section called Transition > Page, then choose Ticket information from the drop-down.
- Scroll up to Parameter presets and click Add a parameter . Enter the following 5 values and assign their value to null without the quotation marks.
Parameter | Value |
---|---|
departure_city |
null |
destination_city |
null |
departure_date |
null |
return_date |
null |
passenger_name |
null |
The purpose of this is to remove the value that was previously collected from the end user to allow them to submit a new value. If this step is missed, it might result in an infinite loop scenario in your bot!
- Click Save.
- Exit out of the window to return to the Build view, you will now see how all 3 pages flow. Note that the last page has two arrows between the Confirm trip and Ticket information page because the
confirmation.no
intent is linked back.
Knowledge check
Task 8. Testing
-
To test that your agent works as intended, click on Test Agent in the upper right corner of the screen.
-
Interact with the agent as if you were the end-user. As you move through the main flow, notice the pages, intents, and transitions you created.
Depending on how you arranged your parameter collection, you can try typing in the following sample dialogue:
- I'd like to book a flight
- Austin
- Tomorrow
- Boston
- Next Friday
- Mickey Mouse
- Yes
This should result in a successful transaction through your agent, commonly known as the “happy path”.
Here is an example of the above agent testing in the Test Agent console:
Click Check my progress to verify the objective.
Task 9. Exporting your agent
When you build an agent for one project, you can export it to use in a different project. You can export your agent and save it to use in future labs or to continue building in your own personal project!
- In the Agent drop down at the top of the Dialogflow CX console, click View all agents.
- On the Agent list screen, click the context menu next to your agent and then click Export.
- On the Export Agent screen, choose Download to local file, then click Export.
Congratulations!
You have built a Dialogflow CX Agent and become familiar with the foundational concepts.
Finish your quest
This self-paced lab is part of the Create Conversational AI Agents with Dialogflow CX quest. A quest is a series of related labs that form a learning path. Completing this quest earns you a badge to recognize your achievement. You can make your badge or badges public and link to them in your online resume or social media account. Enroll in this quest to get immediate credit. See the Google Cloud Skills Boost catalog to see all available quests.
Next steps / learn more
-
Bookmark the Dialogflow CX Documentation
-
Go through the entire Dialogflow CX Video playlist
Manual Last Updated: January 20, 2023
Lab Last Tested: January 20, 2023
Copyright 2023 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.