Conversational Agents: Bot Building Basics

Builds conversational interfaces (for example, chatbots, and voice-powered apps and devices).


ENABLE API:




Task 1. Create your agent

Visit the Conversational Agents console, then select your Cloud Project named qwiklabs-gcp-03-d324fb1857f7.

https://dialogflow.cloud.google.com/v2/projects


An agent is a virtual agent that handles conversations with your end-users. It is a natural language understanding module that understands the nuances of human language.






Click Create agent > Build your own.




Name your agent Flight booker.

Pick global from the Location drop-down.

Click Create.







Conversational Agents Console
In Conversational Agents, you can build AI agents that chat naturally and serve your needs

Agent graph
Get a big picture view of your agent with the graph. It shows how your Playbooks and Flows link up.

Playbooks
Playbooks guide your AI agent. They’re instructions for how agents handle generative chats and tasks.

Flows
Flows can add more structure to conversations. Define rules that deal with chat topics and paths in consistent ways.

Tools
Tools let agents do even more. Connect playbooks to data sources and external systems to expand your agent’s knowledge and abilities.

Settings
Set up agent-level settings here. For example, the LLM model you want to use, or a list of banned phrases.

Simulator
Want to test your agent? Use the simulator to see how it responds in a live conversation.



After creating the agent, navigate to Settings > (Agent)Settings > General > Logging settings and check the boxes next to Enable Cloud Logging and Enable Conversation History option. It will generate logs for this agent.



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.

Conversational Agents 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
From the left navigation pane, click Flows.

Click Manage > Intents > + Create :







Under the Training Phrases header, add each of the following phrases into Conversational Agents, 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
Note: For higher model accuracy, using 20-50 training phrases with short and long response options is recommended.





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 Page 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 Conversational Agent'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 responses > + Add dialogue response > Agent dialogue 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.

xit 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 dialogue
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:

The primary reason that an end-user is interacting with your agent is captured by which resource type?


Intents


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.


ask 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 responses click Add dialogue response, select Agent dialogue and then type the following: Thank you for that information. Let me check on the availability of your ticket and click Add.

Click Save.

(Now stay on this page while you read on to the next step of confirming information.)



Task 8. Testing

To test that your agent works as intended, click on Toggle Simulator in the upper right corner of the screen.

In the Start resource dropdown, select Default Start Flow.

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:





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 Conversational Agents console, click View all agents.






Now open downloaded file.




No comments:

Post a Comment

Conversational Agents: Bot Building Basics

Builds conversational interfaces (for example, chatbots, and voice-powered apps and devices). ENABLE API: Task 1. Create your agent Visit th...