Lab 4 Challenge: Customer Support Analyzer
Goal
Your task is to build a "Support Analyzer" agent. Instead of returning plain text, the agent must analyze the user's support ticket and return a JSON object containing the categorization, sentiment, and a brief summary of the issue.
Lab Tasks
- Open your terminal, ensure you are in your
adk-trainingdirectory, and run the following command to scaffold a new agent:adk create support_analyzer - Navigate into the newly created
support_analyzerdirectory. - Define a Pydantic Schema: In
agent.py, create a class namedSupportAnalysisthat defines three fields:category: A string (e.g., "billing", "technical", "general").sentiment: A string (e.g., "positive", "negative", "neutral").summary: A string containing a 1-sentence summary of the user's issue.
- Update the Agent Configuration:
- Set the
output_schemato yourSupportAnalysisclass. - Set the
output_keyto"last_ticket_analysis".
- Set the
- Refine Instructions: Update the agent's
instructionto ensure it understands its job is to extract these three specific pieces of information from the user's input. - Run and Verify: Run the agent using
adk web support_analyzer(from the parent directory). In the Dev UI, test it with a phrase like "My screen is completely broken and I'm very angry about it!" and verify the response is a valid JSON object. - Inspect State: After a few interactions, check the "Session State" in the Dev UI to confirm that
"last_ticket_analysis"is being populated correctly.
Python Approach (Primary)
Modify agent.py to include the Pydantic model and updated LlmAgent parameters.
from pydantic import BaseModel
from google.adk.agents import LlmAgent
# TODO: Define your Pydantic schema
class SupportAnalysis(BaseModel):
# TODO: Add fields (category, sentiment, summary)
pass
root_agent = LlmAgent(
name="support_analyzer_agent",
model="gemini-2.5-flash",
instruction="...", # TODO: Update instructions for categorization, sentiment, and summary
output_schema=..., # TODO: Link the schema
output_key=... # TODO: Set the output key
)
Self-Reflection Questions
- Why is it better to use
output_schemainstead of just asking the LLM to "respond in JSON" in the text instructions? - What happened to the agent's ability to use tools once you enabled
output_schema? Why does the ADK enforce this restriction? - Look at the Dev UI's "Session State". How could another agent in a future multi-agent system use the data stored in the
"last_ticket_analysis"key?
🕵️ Hidden Solution 🕵️
Looking for the solution? Here's a hint (Base64 decode me):
L2RvYy1hZGstdHJhaW5pbmcvbW9kdWxlMDQtbGxtYWdlbnQtZGVlcC1kaXZlL2xhYi1zb2x1dGlvbg==
The direct link is: Lab Solution