Jump to Content
Developers & Practitioners

How to build dynamic web experiences with Conversational Agents

January 10, 2025
Wei Yih Yap

Generative AI Solutions Architect

Han Wen Kam

Conversational AI Practice Specialist, Asia Pacific

Join us at Google Cloud Next

Early bird pricing available now through Feb 14th.

Register

If you have a website, it’s table stakes to build engaging experiences that are effective at retaining existing customers, and attracting new ones. Users want tailored content, but traditional website development tools struggle to keep up with the demand for dynamic, individualized journeys. With Google Gemini and Conversational Agents (Dialogflow CX), you can now build websites that dynamically adapt their content based on what your users are looking for. 

In this blog post, you will learn how to:

  1. Create dynamic web pages that respond to user’s intents using Conversational Agents

  2. Use function tools to bridge the gap between conversation intent and web content display

What is a Conversational Agents function tool?

A Conversational Agent function tool is a feature that allows your chatbot to interact with external systems and trigger actions based on user conversations. In this article, we use it to:

  1. Detect user intents from natural language input
  2. Map those intents to specific function tool
  3. Dynamically update the UI based on the conversation flow

Let’s take an example: Retail chatbot

While everyone can benefit from these features, retailers in particular can benefit from building dynamic web pages with Conversational Agents. We'll use a retail chatbot use case to demonstrate this tool. Here’s the workflow:

https://storage.googleapis.com/gweb-cloudblog-publish/images/1_workflow_diagram.max-1100x1100.png

Step 1: Create a function tool

Set up a new Playbook function tool called Load-Swag-Content with the following input/output schemas in YAML format.

Loading...

Your console should look something like this:

https://storage.googleapis.com/gweb-cloudblog-publish/images/2_tool_setup.max-2000x2000.png

Step 2: Set up a playbook steering agent

Set up a main steering playbook to call the function tool Load-Swag-Content.

https://storage.googleapis.com/gweb-cloudblog-publish/images/3_playbook_instruction.max-1900x1900.png

Step 3: Create examples to drive Playbook agent behavior. 

In this example, when a user asks about “Backpack”, the Playbook agent will call the function tool by passing a backpack related URL as an argument to the web client.

More information on the web client in the next step.

https://storage.googleapis.com/gweb-cloudblog-publish/images/4_playbook_example.max-1500x1500.png

Step 4: Write web client JavaScript function

This client-side Javascript function receives the URL from the Load-Swag-Content function tool and updates the HTML iframe accordingly.

Loading...

We are using HTML iframe to demonstrate the function calling and parameter passing capabilities. The same concept works across different web frameworks and applications, and developers can be as creative as they want to build custom logic.

Step 5: Register the function tool

Register the Playbook function tool using registerClientSideFunction, which will map the Load-Swag-Content tool with the JavaScript function loadURL.

Loading...

You can get the toolId from the browser URL bar at the Playbook function tool page.

Step 6: Integrate Dialogflow messenger

Finally, embed the Dialogflow messenger integration with your web client.

Loading...

Sample front end source code

This is a front end sample code. You need to update configuration such as YOUR_REGION, YOUR_PROJECT_ID, YOUR_AGENT_ID, YOUR_TOOL_ID, and custom JavaScript function.

Loading...

Demo web page

Let's look at a demo use case for a virtual swag assistant. The customer is greeted at the start of the chat.

https://storage.googleapis.com/gweb-cloudblog-publish/images/5_backpack.max-2200x2200.png

When the customer wants to find out more about a Fleece Jacket, the page is dynamically updated to display relevant information.

https://storage.googleapis.com/gweb-cloudblog-publish/images/6_fleece.max-2200x2200.png

Next steps

To learn more about Conversational Agent Function tools, check out the following resources and enhance your customer experience with real-time intent-based dynamic web pages.

Posted in