Build an AI agent app with Go ADK, Cloud Run, and Flutter
By Google Cloud Tech
Share:
Key Concepts
- ADK (Agent Development Kit): An open-source framework for building, operating, and deploying AI agents using Gemini models.
- Agentic Workflow: A system where AI agents can take actions, use tools, maintain context, and coordinate with other agents.
- Artifact Storage: A mechanism to store large data (like images) in Google Cloud Storage, returning only a reference to the frontend to keep API responses lightweight.
- MVVM (Model-View-ViewModel): An architectural pattern used in the Flutter app to separate UI from business logic and data sources.
- State Management: Using Providers in Flutter to manage app data and trigger UI updates automatically when state changes.
- Gemini Models: The underlying AI models used for image generation and reasoning.
1. System Architecture
The application is divided into two primary components:
- Frontend: A cross-platform Flutter app (Web, iOS, Android) that uses a declarative UI approach.
- Backend: A Go-based service running on Cloud Run, built using the ADK. The backend exposes a REST API that the Flutter app consumes via HTTP.
2. Agentic Framework (ADK)
The ADK enables agents to move beyond simple Q&A by providing:
- Tool Calling: Invoking functions (e.g., querying a product database or generating images).
- Multi-Agent Coordination: Agents can delegate tasks to one another (e.g., the Styling agent delegates to the Catalog agent).
- Session Management: Tracking conversation history and shared state across multiple interactions.
- Development UI: A built-in web interface for inspecting events, debugging, and viewing artifacts.
Agent Types:
- LLMAgent: The standard agent for general tasks.
- Workflow Agents: Specialized agents for orchestration:
- Sequential: Runs sub-agents in order.
- Parallel: Runs sub-agents simultaneously.
- Loop: Runs sub-agents repeatedly until a condition is met.
3. Implementation Details
Backend Logic (main.go)
- Instructions: Agent prompts are stored in
.mdfiles and embedded into the Go binary using theembedpackage to keep code clean. - Catalog Agent: Uses
list_products(YAML-based) andGetProductImagetools to provide product data. - Fitting Room Agent: Uses the
fitting_tool(Gemini 2.5 Flash) to overlay products onto user-provided images. - Styling Agent: Coordinates with the Catalog agent to suggest outfits based on user context (occasion/location) and supports iterative feedback.
Frontend Logic (Flutter)
- State Management: Uses
Providersto encapsulate data (e.g.,TryItOnProvider,StylingProvider). - Pattern Matching: Utilizes Dart’s pattern matching for routing between UI states (e.g., "asking for photo," "loading," "displaying result").
- AnimatedSwitcher: Provides smooth transitions between UI states (fade/scale animations) when the provider state updates.
- Data Flow: The app follows a strict request-response cycle:
- Session: Initialize or reuse a
sessionId. - Run: Send a POST request with
appName,sessionId, andnewMessage(containing text or Base64 images). - Fetch: Receive an artifact reference and perform a GET request to retrieve the generated image from Cloud Storage.
- Session: Initialize or reuse a
4. Key Processes
- Virtual Fitting Room Flow:
- User selects a product.
- User uploads a photo.
- Backend saves the photo as an artifact.
- Agent processes the image and returns a reference to the generated "try-on" image.
- Styling Flow:
- User submits a request (e.g., "Google I/O").
- Styling agent queries the Catalog agent.
- Agent generates a carousel of outfits.
- User provides feedback; the agent updates the state, and the UI automatically rebuilds to show new suggestions.
5. Notable Quotes
- "ADK is the difference between a raw model call and a production-ready system." — Annie Wang
- "Agents don't just think in the moment. They remember." — Annie Wang
6. Synthesis
The workshop demonstrates that building a sophisticated, AI-powered retail experience is achievable by combining Flutter's reactive UI capabilities with the ADK's structured approach to agent orchestration. By offloading heavy processing to Cloud Run and using Artifact Storage for image management, the developers created a responsive, scalable, and iterative shopping experience that effectively bridges the gap between online browsing and the physical fitting room experience.
Chat with this Video
AI-PoweredLoad the transcript when you're ready to chat so the initial page stays lighter.