As conversational AI becomes a core part of the user experience, it's crucial for application developers to build chatbots that not only provide accurate information, but also know the right time to escalate to a human agent.
This blog post will show you how to create a self-escalating chatbot using Google Cloud's generative AI solutions such as Vertex AI, Conversational Agents (Dialogflow CX), and others. The solution offers several benefits:
- Improved user experience: Users receive accurate information and timely assistance, even for complex questions.
- Reduced agent workload: Agents receive concise summaries of previous interactions, allowing them to address issues efficiently.
- Enhanced chatbot capabilities: The chatbot can learn from escalated queries, continuously improving its ability to handle future interactions.
- Increased scalability and security: Cloud Run Functions (CRF) provides a scalable and secure platform for running the webhook function.
Let’s get started.
1. Build the knowledge base
Let’s say we want a chatbot to answer questions related to tourism in India. We’ll start by leveraging Vertex AI Agent Builder and Conversational Agents (Dialogflow CX) to create it.
- Unstructured datastore: We index an article on "Tourism in India" as an unstructured datastore within Vertex AI. This allows the chatbot to access and retrieve relevant information from the article in real time, providing comprehensive answers to user queries.
- Conversational Agents (Dialogflow CX): We design the conversational flow using Conversational Agents (Dialogflow CX), enabling the chatbot to understand user intent and respond appropriately.
2. Gauge user satisfaction
To ensure user satisfaction, we incorporate a crucial step in the conversation flow: asking the user if they are satisfied with the chatbot's response. This is done using "yes" and "no" chips specified as part of custom payload, providing a clear and intuitive way for users to express their feedback.
3. Escalate with generative AI
If the user expresses dissatisfaction by clicking "no," the chatbot initiates the escalation process. This is where the power of generative AI comes in.
-
Generators: We create a generator in Conversational Agents (Dialogflow CX) named "Summarize_mail" that utilizes a zero-shot prompt (direct prompt with no examples) to summarize the conversation. This summary is then used to generate the content of an email, providing context to the human agent.
Here's the zero-shot prompt we use:
-
Model configuration: This generator utilizes the Gemini-1.5-flash model with a temperature of 0.3, helping to ensure coherent and informative summaries.
4. Trigger the email with Cloud Run Functions (CRF)
To send the email, we use a webhook to connect our Conversational Agents (Dialogflow CX) agent to a serverless function deployed on Cloud Run Functions. This function handles the email sending logic.
We utilize the Cloud Run Functions console inline editor to write and deploy the following Python code:
-
Cloud Run Functions (CRF) configuration: We configure the CRF with the following settings:
-
Runtime: Python 3.12
-
Environment: 2nd Gen
-
Entry point: handle_webhook
-
Trigger type: HTTPS
-
Memory allocated: 256 MiB
-
Ingress settings: Allow all traffic
-
Requirements (requirements.txt): functions-framework==3.*
Not sure which CRF version to choose for Dialogflow CX Webhooks? Here’s a quick way to decide:
-
1st Gen: Simpler to set up and deploy, suitable for basic webhooks with less demanding performance requirements.
-
2nd Gen: Offers more flexibility, control, and scalability, making it a better choice for complex webhooks or high-traffic scenarios.
More details here
5. Connect the pieces
Specify the URL of our deployed CRF as the webhook URL in Conversational Agents (Dialogflow CX), ensuring that the escalation process is triggered correctly when needed.
Here’s how it all comes together
This breakdown provides a comprehensive understanding of the Conversational Agents (Dialogflow CX) flow design, emphasizing the escalation process and the role of the CRF. Remember to adapt the flow, messages, and email content to suit your specific needs and branding.
Flow Name: (e.g., "Customer Support Flow")
Pages: There are two pages, ‘Start Page’ and ‘Escalate’.
1. Start Page
-
Purpose: Initiates the conversation with the welcome intent greeting the user and gauges user satisfaction.
-
Greeting entry fulfillment:
-
Agent says: "Hi name! Please let us know how we can help you."
-
Datastore response entry fulfillment:
-
Agent says: "Are you satisfied with the response?"
-
Custom payload: (This creates the "Yes" and "No" chips)
JSON
-
Routes:
-
Condition: "Yes" chip selected
-
Transition: Start page (Marks the conversation as successful)
-
Agent says: "Thank you! Is there anything else we can help with?”
-
Condition: "No" chip selected
-
Transition: "Escalate" Page
-
Agent says: "Sorry to hear that!" (Acknowledges user dissatisfaction)
2. Escalate
-
Purpose: Offers the user the option to escalate to a human agent.
-
Entry fulfillment:
-
Agent says: "Would you like to escalate?"
-
Custom payload: (Same "Yes" and "No" chips as the "Start Page")
-
Routes:
-
Condition: "No" chip selected
-
Transition: "Start Page"
-
Agent says: "Sure, Thank you!" (Allows the user to continue with the bot)
-
Condition: "Yes" chip selected
-
Transition: "Escalation Webhook"
-
Webhook: Cloud Run Functions (Triggers the escalation process)
-
Intents:
-
We describe the two intents ‘confirm.yes’ and ‘confirm.no’ with training phrases described as ‘yes’ and ‘no’. This corresponds to the user clicking on ‘yes’ and ‘no’ chips or simply writing the phrases or the similar ones.
-
To learn more about Intents, please click here.
Cloud Run Functions (Escalation Webhook)
-
Trigger: HTTPS Eventarc trigger (Activated when the "Escalate" page transitions to the webhook)
-
Functionality:
-
Gather conversation history: Retrieve and process the complete conversation history from the Conversational Agents (Dialogflow CX) session using the $conversation in the generator prompt which captures the conversation between the agent and the user, excluding the very last user utterance and the agent's utterances thereafter.
-
Summarize conversation: Generate a concise summary of the conversation ($conversation), highlighting key user requests or issues.
-
Extract user information: Obtain the user's email address (and any other relevant details) from the Conversational Agents (Dialogflow CX) session or your user database.
-
Compose email: Create an email with:
-
Subject: (e.g., "Escalated Conversation from [User Email]")
-
Recipient: The support agent's email address
-
CC: The user's email address
-
Body:
-
User information (e.g., name, ID)
-
Conversation summary
-
Link to the full conversation in Conversational Agents (Dialogflow CX) (if available)
Send email: Use an email sending library (e.g., sendgrid, mailgun,smtp) or your email provider's API to send the email.
Return response (optional): Send a response back to Conversational Agents (Dialogflow CX) to inform the user that their request has been escalated (e.g., "The mail is successfully sent!”, "Your request has been escalated. An agent will contact you shortly.").
Chatbot testing and results
After completing the above steps, you can click on ‘Publish’ and then ‘Try it now’ to test the chatbot.
These are a few example user journeys:
1. The user is not satisfied with the response and does not want to escalate as well.
2. The user is not satisfied with the response and escalates as well. The sample triggered mail is shown below in the right image.
This approach shows how you can combine various Google Cloud technologies, including Vertex AI, to build intelligent and user-friendly chatbots. As conversational AI continues to evolve, we can expect even more innovative solutions that enhance customer experiences. To learn more and contribute feedback, visit our Google Cloud community on Medium.