arrow_back

Informed decision making using Dialogflow CX generators and data stores

Sign in Join
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

Informed decision making using Dialogflow CX generators and data stores

Lab 1 hour 30 minutes universal_currency_alt No cost show_chart Intermediate
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

Overview

What you'll build

In this lab, you use Vertex AI Agent Builder and Dialogflow CX to build, deploy and configure a virtual agent to assist people who want to donate blood and ensure they meet the required eligibility requirements. The agent uses real public data and Google's generative large language models (LLMs) during Dialogflow CX fulfillment.

Data store agents

The Vertex AI Agent Builder feature creates a special Dialogflow agent, called a data store agent.

With this feature, you provide a website URL, structured data or unstructured data (data stores), then Google parses your content and creates a virtual agent that is powered by data stores and large language models. Your customers and end users can then have conversations with the agent and ask questions about the content. Refer to the Vertex AI Agent introduction for information about this type of agent.

Generators

The generator feature is a Dialogflow CX feature that allows developers to use Google's latest generative large language models (LLMs) and custom prompts to generate agent responses at runtime. A generator can handle generic responses that involve general knowledge from a large textual dataset it was trained on or context from the conversation.

Objectives

In this lab, you learn how to perform the following tasks:

  • Use Dialogflow AI Agent to create a chat app and add unstructured data to a data store
  • Use knowledge handlers to allow end-users to have conversations with a virtual agent about the content added to a data store.
  • Configure a generator text prompt and make it contextual by using built-in generator prompt placeholders.
  • Mark words as generator prompt placeholders and later associate them with session parameters in fulfillment to use their values during execution.
  • Configure a generator to handle responses that involve knowledge from a large textual dataset and context from the current conversation.
  • Generate a formal email using generators
  • Test your agent and simulate customer questions that trigger generated responses

Setup and requirements

In this task, you use Qwiklabs and perform initialization steps for your lab.

For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.

  1. Make sure you signed into Qwiklabs using an incognito window.

  2. Note the lab's access time (for example, img/time.png and make sure you can finish in that time block.

  1. When ready, click img/start_lab.png.

  2. Note your lab credentials. You will use them to sign in to the Google Cloud Console. img/open_google_console.png

  3. Click Open Google Console.

  4. Click Use another account and copy/paste credentials for this lab into the prompts.

  1. Accept the terms and skip the recovery resource page.

Google Cloud console

After you complete the initial sign-in steps, the project dashboard appears.

GCP Project Dashboard

Ensure your project, is selected. If not, then click Select a project at the top of the console, highlight your Google Cloud project ID, and click OPEN to select your project.

If you are not using Incognito mode, you will need to ensure that the correct project and user account are selected at all times to avoid accidental charges to your Google Cloud billing account.

Task 1. Enable APIs

Before you can start using Dialogflow AI Agent in Vertex AI Agent Builder, you need to enable the Dialogflow as well as the Vertex AI Agent Builder APIs. These APIs should already be enabled for this lab, but you should verify this before moving forward.

Enable the Dialogflow API by doing the following steps:

  1. In your browser, navigate to the Dialogflow API Service Details page.

  2. If the API is not already enabled, click the Enable button to enable the Dialogflow API in your Google Cloud project.

To enable the Vertex AI Agent Builder API, follow these steps:

  1. In the Google Cloud console, navigate to the Vertex AI Agent Builder.

  2. If asked, read and agree to the Terms of Service, then click Continue and activate the API.

Click Check my progress to verify the objectives. Enable APIs

Task 2. Create a new chat app and a data store for your app

Now, you'll create a new chat app for your virtual agent and configure it with a data source. The purpose of the agent that you'll build is to assist customers who have questions about blood eligibility. You will use the Australian Red Cross Lifeblood as the source of truth and you will create a data store based on unstructured data from the blood eligibility website.

  1. To create a new chat app in Vertex AI Agent Builder, you can either follow one of the below steps:

    a. Navigate to the Vertex AI Agent Builder console, then click +New app near the top of the console.

    b. Navigate to the Dialogflow CX console, click +Create new agent then selecting the Auto-generate option, then you'll be redirected to the following step in the Vertex AI Agent Builder console.

  2. From the Vertex AI Agent Builder console, select Chat as the type of app that you want to create.

  3. Input a Company name of Save a Life. This parameter is used to define the company that your agent represents and the scope of your agent.

  4. Specify an Agent name of Blood Donation Agent.

  5. Leave all other options as the default value. Click Continue.

  6. Click Create new data store.

Data Store Button

  1. Select the Cloud Storage option and paste the below path in the BROWSE box, which contains sample data for this lab, and note that the gs:// prefix is not required.
cloud-samples-data/dialogflow-cx/arc-lifeblood
  1. Select Unstructured documents as the type of data you are importing.

  2. Click Continue.

  3. Specify a Data store name of Australian Red Cross Lifeblood Unstructured.

  4. Click Create to create the data store.

Note: This may take up to 1 minute to create the data store.
  1. In the list of data stores, select the newly created Australian Red Cross Lifeblood Unstructured.

  2. Click Create to create your chat app.

Note: Generally, it can take up to 4 hours for your documents to be available and ready for use by your agent while your newly added domains are being indexed depending on the number of documents or size of your domain. For this lab, it will take 10-15 minutes.

Congratulations! You are finished building your knowledge-powered chat app that's ready to help potential donors, so take a moment to celebrate!

But there's still more work to do to make the agent accessible to your users. In the next section, you'll use a knowledge handler to enable conversations between the agent and end-users about eligibility requirements.

Click Check my progress to verify the objectives. Create a new chat app

Task 3. Configure the agent to answer blood eligibility FAQs

Provide the date store prompt

While the document collection process is running in the background, let's give the agent a brand by editing the data store prompt.

  1. From the Vertex AI Agent Builder console, click the name of your chat app, which will redirect you to the Dialogflow CX console for further testing and customization.

  2. In the Dialogflow CX console and from within your agent, click Agent settings (top right corner of the page)

Agent Settings

  1. Go to the Generative AI tab.

Generative AI

  1. Click on Data store tab.

Data store tab

Fill out the form as below to generate the following data store prompt: Your name is Donate, and you are a helpful and polite chatbot at Save a life, a fictitious organization. Your task is to assist humans with eligibility information.

Agent context

  1. Click the Save button located at the top of the tab.

Click Check my progress to verify the objectives. Generate the data store prompt

Enable generative fallback for the Default Start Flow's no-match event

  1. Switch to the Build tab on the top-left of the Dialogflow console (beside of Manage) and open the Start Page.

  2. Click the sys.no-match-default event handler. Unless the box is already checked, enable the generative fallback feature.

Enable the generative fallback feature

Check the agent's data store

  1. On the Start Page click Edit data stores to look into Data store settings.

Edit data stores

  1. Notice how the data store you have previously created has been already selected for you by Dialogflow.

Data store selected

  1. Scroll down to Agent Responses under Fulfillment. A fulfillment is the agent response to the end user. Dialogflow has pre populated Agent says with the parameter $request.knowledge.answers[0] which at run time contains the top answer to the user's question.

Agent response from data store

Task 4. Test the agent

Wait until the documents are available and ready for use by your agent to check out how good the answers are. You can check if the documents are available by going to the Vertex AI Agent Builder console and clicking on the view link under Connected data stores beside of the Blood Donation Agent app and then clicking on Australian Red Cross Lifeblood Unstructured.

Imported Data Store

If you are not in the Dialogflow CX console, then from the Vertex AI Agent Builder console, click the name of your chat app, which will redirect you to the Dialogflow CX console.

  1. Click Test Agent to open the Simulator.

Agent Simulator

  1. Ask questions that you expect to find in the FAQ page of the website. For example:
  • What age do I need to be to donate?
  • Can pregnant women donate?
  • I've just come back from a trip to Africa. Can I donate?
  • How can I schedule an appointment?

Agent Simulator example

Notice the answers are retrieved from the Australian Red Cross Lifeblood site. As stated on this page there are minimum and maximum ages for blood donation. The minimum age is 18 and the maximum age is 75 for first-time donors. Further evidence of the fact we are pulling information from the data store is given by the little star icon appearing on the agent response and by the original JSON response.

Agent Simulator generative outcome

  1. Lastly, let's try and challenge the agent with a question totally unrelated to blood donation. For example:

What's the weather like in Melbourne?

The agent should respond something like: I'm sorry, I can only help you with eligibility information for blood donation. How can I help you today?

This answer has AI generated content in it and derives from the text prompt that Dialogflow has created starting from the knowledge connector setting provided before: "Your name is Donate, and you are a helpful and polite chatbot at Save a Life. Your task is to assist humans with eligibility information". This text prompt contains the company name, the agent name and most importantly what is in its scope which is used by Dialogflow to generate the agent response.

Well done! So far you are using the data store to assist people with frequently asked questions related to blood donation. In the next part of the lab we will look at how to bind a generator text prompt to the same content to make informed decisions.

Task 5. Set up the agent for the eligibility quiz

Our next task is to design the agent to determine the user's eligibility to donate blood. There are strict requirements donors must meet such as age, weight, existing conditions, recent travels, etc. For the scope of this lab we will only consider age and weight. A generator will use Google's large language models (LLMs) to dynamically make an informed decision based on the context of the conversation and the knowledge base.

Configure new routes and parameters

  1. Open the Start Page and click Edit data stores.

  2. Change the existing agent's response to $request.knowledge.answers[0] Would you like to take the eligibility quiz to find out if you can donate blood, and start changing lives?.

Agent says data store output

  1. Click the Save button.

  2. We now need to design the agent to handle "yes" and "no" responses. To begin with, create a confirmation.yes intent and a confirmation.no intent. Go to Manage then click Intents. Click the Create button. Type in confirmation.yes as the display name. Under Training phrases, type in yes and hit Add. Repeat this process to add yeah, yes please and okay as training phrases and click Save.

Intents like the confirmation.yes intent you defined in the previous step can be reused across multiple pages. Follow these guidelines about intent reuse.
  1. Return to Build and click on Start Page. Then on the Start Page create a route for the confirmation.yes intent that transitions to a new page Eligibility Quiz as shown below.

Transition page to Eligibility Quiz

  1. In the Transition pane, select Page > + new page and set page name as Eligibility Quiz.

  2. Click Save.

  3. As mentioned before, we will simplify the quiz and we will only consider the age and the weight of the user to determine whether or not they're eligible to donate. Click the three dot menu for the Eligibility Quiz page and click Edit (to the left of the the flow diagram on the Build page). Add a new form parameter age-weight, pick @sys.any as the entity type. Provide "What is your age and weight?" as the initial prompt fulfillment. We want to collect both age and weight in one go. Save all the changes.

Age-weight required parameter

Create and configure the eligibility generator

The generator feature is a Dialogflow CX feature that allows developers to use Google's latest generative large language models (LLMs) during Dialogflow CX fulfillment. Generators to generate agent responses at runtime. A generator can handle generic responses that involve general knowledge from a large textual dataset it was trained on or context from the conversation.

We shall create a new generator that will compare the information provided by the user (such as age and weight) with the eligibility requirements to determine whether the user can donate.

  1. On the Dialogflow CX console go to the Manage tab, select Generators and click Create new.

Generators

  1. Next, provide Blood Donation Eligibility as the display name and write the following text prompt.
Check the users eligibility against the following criteria: the minimum age is 18 and the maximum age is 75. Weight should be above 50 Kg. The user age and weight is $last-user-utterance. Be nice and tell the user if they are eligible to donate (also tell them why not in case)
  1. Leave the default model quality control settings. Then click Save to create the generator.

The text prompt is sent to the generative model during fulfillment at runtime. It should be a clear question or request in order for the model to generate a satisfactory response. You can use special built-in generator prompt placeholders in your text prompt:

  • $conversation The conversation between the agent and the user, excluding the very last user utterance.
  • $last-user-utterance The last user utterance.

The text prompt you have configured expects the user to provide age and weight in once conversational turn (the last-userutterance).

Use the generator in fulfillment and configure all the required parameters

  1. Return to the Build tab on the top left. On the Eligibility Quiz page, add a new route which will occur when all parameters have been filled. Select the "Match AT LEAST ONE rule (OR)" option under Condition rules and enter the condition requirement $page.params.status = "FINAL" and click Save.

Configure conditions

  1. Within Route, go to the Generators section of the Fulfillment pane and expand it. Then, click Add generator and select the Blood Donation Eligibility generator. After selecting the generator you need to define the output parameter like $request.generative.eligibility-outcome that will contain the result of the generator after execution.

Generator association

  1. Use the output parameter in the agent response and save the route. You are now ready to test it all.

Generator in agent response

Task 6. Retest your agent

  1. Click Test Agent to open the Simulator again.

Agent Simulator

  1. On the Simulator start a new conversation with the agent. First ask about age requirements and then proceed to the eligibility quiz. Test the "eligible" path first, so enter an age between 18-75 and a weight above 50 Kg.

Agent Simulator generator response eligible example

  1. Then check the eligibility check fails when one or both the requirements are not met.

Agent Simulator check parameters in response

  1. Great, the generator works as expected! Or does it? What happens if the user provides the age but not the weight (or the other way around)?

Agent Simulator output final

Task 7. Generator prompt tuning

Collecting age and weight in one ago doesn't seem to work unless both age and weight are provided. We should instead create a form that collects both values as entity parameters. To make the prompt contextual of all the eligibility requirements (such as the age and the weight) we can use placeholders by adding a $ before the word. We will later associate these generator prompt placeholders with session parameters in fulfillment and they will be replaced by the session parameter values during execution.

  1. Open the Eligibility Quiz page and add two separate form parameters: one for weight and one for age. Pick @sys.number-integer as the entity type and mark the parameters required. Provide the initial prompt fulfillments such as How old are you? and What is your correct weight?. Save all the changes.

Elegibility quiz entity types

  1. Before we can change the text prompt of the generator since we are going to add two new custom placeholders we first need to remove the generator from the route fulfillment. Click Save.

Remove generator placeholder

  1. Go to the Manage tab, select Generators and update the text prompt of the Blood Donation Eligibility generator with: Check the users eligibility against the following criteria: the minimum age is 18 and the maximum age is 75. The weight must be at least 50 kg. The user is $age years old and weighs $weight Kg. Craft an email and politely explain to the user if they're eligible to donate and if not why. Click Save.

Notice that we haven't just made the text prompt contextual of the age and weight form parameters, we have also changed the last sentence to be able to generate a formal email to the user which contains the official outcome of the eligibility quiz.

Update generator

  1. Return to the Build tab. On the Eligibility Quiz page, select the route and expand the Generators section of the Fulfillment pane. Then, click Add generator and select the Blood Donation Eligibility generator. After selecting the generator you need to associate the new prompt placeholders with the respective session parameters. Moreover, you need to re-set the output parameter. Click Save.
  • age : $session.params.age
  • weight : $session.params.weight
  • Output parameter : $request.generative.eligibility-outcome

Link generator

  1. Retest the agent again. The eligibility check takes now into account both age and weight and the wording has changed from a conversational tone to a more polite response that is ready to be sent out without any potential human in the loop.

Agent test generator

Congratulations!

Today we've investigated generators in the context of eligibility quizzes. You have seen that generators use LLMs to generate agent responses and when powered by a knowledge base they can also make well-informed decisions. Surely there are many other use cases that can be implemented leveraging generators and data stores and we can't wait to get to know them!

Learn more

Continue learning about Agent Builder AI and generative AI with these guides and resources:

Google Cloud Training & Certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated May 02, 2024

Lab Last Tested May 02, 2024

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.