How to build a multi-agent app with ADK and Gemini

By Google Cloud Tech

Share:

Key Concepts

  • AI Agents: Autonomous entities that can perform tasks and interact with their environment.
  • Agent Development Kit (ADK): A Google framework for building and orchestrating AI agents.
  • Root Agent: A generalist agent that routes tasks to specialized agents.
  • Updater Agent: A specialized agent designed to modify content based on specific instructions.
  • Critic Agent: A specialized agent that identifies areas for improvement in content.
  • Gemini Models: Google's family of AI models, including Gemini Pro (high quality), Gemini Flash Lite (fastest, most cost-efficient), and Gemini Flash (balanced).
  • Sessions: A mechanism in ADK to maintain state and memory for natural conversations between users and agents.
  • Tools: Functions or APIs that agents can use to perform actions or retrieve data.
  • Single Responsibility Principle: A software development principle applied to agents, where each agent focuses on a single, well-defined task.
  • Cloud Run: A managed compute platform that lets you run stateless containers.
  • Vertex AI Agent Engine: A Google Cloud service for deploying and managing AI agents.

Collaborative AI and Human Content Creation with ADK

This video demonstrates a workflow where AI agents and humans collaborate to refine content, specifically a blog post generated from a YouTube video transcript. The core idea is to leverage AI for tedious tasks and complex reasoning, allowing humans to focus on creative direction and strategic improvements.

Generating and Initializing the Blog Post

The process begins with generating a blog post from a YouTube video link. The initial draft, while functional, is described as "robotic" and lacking conversational flow. An example of this is the opening sentence: "The allure of serverless computing is the promise of abstracting away infrastructure management."

Enhancing Conversational Tone and Adding a Hook

The primary challenge addressed is transforming the robotic text into a more engaging and conversational style. This is achieved by instructing an AI agent to update the post.

  • Manual vs. AI Editing: The presenter highlights the inefficiency and inconsistency of manually editing such changes across a document, contrasting it with the ease and speed of AI.
  • AI-driven Revision: The AI agent is tasked with making the text more conversational. It successfully removes the initial complex sentence and replaces it with a more direct and engaging opening: "So you're diving into serverless computing, right?"
  • Identifying Missing Elements: The AI agent is then prompted to suggest improvements. It identifies that the blog post lacks a strong "hook."
  • Implementing the Hook: The agent is instructed to implement the suggestion of adding a hook. This results in a new, compelling opening: "Your serverless function works until a library throws a File Not Found error." This hook is relatable and directly addresses a potential pain point for developers.

The Architecture of AI Agents

The underlying technology enabling this collaboration is Google's Agent Development Kit (ADK). The system is built using three distinct agents:

  1. Root Agent:

    • Role: A generalist and router.
    • Functionality: Receives user input and directs it to the appropriate specialized agent.
    • Code Simplicity: The code for the root agent is described as simple, defining its prompt, output, and knowledge of the other specialist agents.
  2. Updater Agent:

    • Role: A specialized agent.
    • Functionality: Focuses on updating the blog post based on specific instructions (e.g., "make it more conversational").
  3. Critic Agent:

    • Role: A specialized agent.
    • Functionality: Excels at identifying areas for improvement in the current draft of the blog post.
    • Output: Saves its suggestions to an output key named "blog_post," which is then utilized by the updater agent.

Agent Collaboration and Communication

The agents communicate and pass information through defined output keys. For instance, the critic agent's suggestions are stored in the "blog_post" key, and the updater agent's prompt incorporates this output, demonstrating how they collaborate.

Development and Testing with ADK

ADK provides tools for efficient development and debugging:

  • adk web Command: This command launches a web interface that allows developers to interact with their agents, test prompts, and observe agent calls for debugging purposes.
  • Agent Orchestration: ADK manages the calling of multiple agents in the correct sequence, which is crucial for automated use cases where several agents need to work together without human intervention.

Deployment Options

Once agents are developed and tested, they can be deployed to:

  • Vertex AI Agent Engine: A dedicated service for deploying and managing AI agents.
  • Cloud Run: A managed compute platform for running stateless containers, offering independent scaling and the ability to expose agents via an API.

Web Application Integration

The deployed ADK agents can be integrated into web applications.

  • HTTP Requests: The web app sends HTTP requests to the Cloud Run service hosting the ADK app.
  • agent_gateway.py: This Python file in the web app handles the communication with the ADK app, including composing requests, sending them to the AGENT_URL (an environment variable), and parsing responses.
  • Sessions for State and Memory: Sessions are critical for maintaining context and memory in conversations. Without a session, the agent wouldn't understand references like "item two." This state management is vital for natural, multi-turn interactions.

Advantages of Using ADK over Direct Gemini API Calls

The presenter outlines several key benefits of using ADK:

  1. State and Memory Management: ADK's session management provides the crucial ability to retain conversational context.
  2. Developer Experience: Tools like adk web simplify testing and debugging.
  3. Orchestration of Multiple Agents: ADK handles the complex task of coordinating multiple agents, allowing developers to focus on the agent's core functionality.

The Power of Specialized Agents

The use of multiple specialized agents is justified by the single responsibility principle. It's easier to build, test, and debug agents that perform one task well. This modularity prevents complex prompts from confusing the AI and improves maintainability.

Deployment Strategy: Separate Cloud Run Service

Deploying the ADK app as a separate Cloud Run service offers several advantages:

  • Independent Scaling: The ADK service can scale up or down independently of the main web application.
  • Reusability: Other applications can call the ADK service.
  • Agile Updates: Prompts and agent logic can be tuned and redeployed more frequently without impacting the main application.

Session Persistence for Production

While session memory is stored in RAM for development (fast, no setup), production applications require more permanent storage:

  • Cloud Run: ADK can be configured to store sessions in a relational database.
  • Agent Engine: Offers built-in session services.

Broader Use Cases for ADK

ADK is not limited to text and content generation. It can be used for:

  • Analyzing Data: Agents can be equipped with tools to process and interpret data.
  • Orchestrating API Calls: Agents can interact with external services.
  • Taking Actions: Agents can perform tasks on behalf of the user, such as publishing a blog post by calling a blogging platform's API.

Learning Resources

For those interested in building agents with ADK:

  • ADK GitHub Repository: Contains example apps and the code for the video.
  • Links in Video Description: The presenters will share relevant GitHub repository links.

Conclusion

Google's ADK simplifies AI agent development by allowing developers to focus on the creative aspect of defining agent behavior. It enhances debugging capabilities and improves the overall quality of AI-driven applications through modularity and intelligent orchestration. The collaboration between humans and AI agents, facilitated by tools like ADK, leads to superior outcomes compared to relying solely on one or the other.

Chat with this Video

AI-Powered

Load the transcript when you're ready to chat so the initial page stays lighter.

Ready to summarize another video?

Summarize YouTube Video