| .. | ||
| email_generator_agent | ||
| README.md | ||
| requirements.txt | ||
📧 Structured Output in Google ADK
A tutorial demonstrating how to implement structured output using Google's ADK (Agent Development Kit) framework. This example uses an email generator agent to show how to create type-safe, structured responses with Pydantic schemas and Gemini 2.5 Flash model.
Tutorial Features
-
📝 Structured Output Implementation:
- Learn how to use Pydantic schemas for type-safe output
- Understand how to define structured response formats
- See how Google ADK handles structured responses
-
🎯 Email Generator Example:
- Practical example using email generation as the use case
- Shows how to create professional email content with proper structure
- Demonstrates real-world application of structured output
-
🔧 Google ADK Best Practices:
- Simple agent definition with clear instructions
- Proper use of output schemas for reliable results
- Minimal codebase demonstrating core concepts
How to Run
-
Setup Environment
# Clone the repository git clone https://github.com/Shubhamsaboo/awesome-llm-apps.git cd awesome-llm-apps/google_adk_tutorials/structured_output_agent/email_generator_agent # Install dependencies pip install -r requirements.txt -
Configure API Keys
- Get Google AI API key from Google AI Studio
- Set up your API credentials for Gemini access
-
Run the Agent
# Start the ADK web interface from the root folder cd google_adk_tutorials/structured_output_agent adk webThen:
- Open the web interface in your browser
- Select the "email_generator_agent"
- Enter your email request (e.g. "Write a professional email to schedule a meeting with a client")
- The response will be a structured JSON with subject and body fields
Tutorial Overview
This tutorial demonstrates structured output implementation in Google ADK:
- Agent Definition: Learn how to create a
LlmAgentwith Gemini 2.5 Flash - Output Schema: Understand how to use Pydantic models for structured responses
- Instructions: See how to write clear prompts for structured output
- Structured Response: Learn how to handle JSON responses with defined schemas
Code Structure
agent.py: Contains the main agent definition and Pydantic schema__init__.py: Module initialization for easy imports
Dependencies
google-adk: Google's Agent Development Kitpydantic: Data validation and settings management
How Structured Output Works
This tutorial shows how Google ADK handles structured output:
- Input Processing: Takes natural language requests and processes them through the agent
- Content Generation: Uses Gemini 2.5 Flash to generate content based on instructions
- Output Structuring: Automatically formats responses according to the Pydantic schema
- Response Validation: Ensures the output matches the defined structure and types
This approach demonstrates how to create reliable, type-safe responses in Google ADK applications.