Courseware / AI Agents / course-092
Mastering Sophisticated AI Agent Workflows with Google Cloud's Agent Garden
Tweet@svpinoView Source →

🎙 Podcast Version

2-host dialogue — ALEX & SAM discuss this course.

Mastering Sophisticated AI Agent Workflows with Google Cloud's Agent Garden

Overview

This course provides a comprehensive exploration of advanced AI agent architectures using the Google Cloud Agent Garden and the Google ADK. It focuses on moving beyond simple "demo" bots to build authentic, production-ready applications that utilize multi-agent patterns and adaptive learning. By analyzing a real-world invoice processing agent, students will learn how to implement governance, validation, and human-in-the-loop feedback systems to create agents that evolve over time.

Background & Context

In the current landscape of AI development, many developers struggle to move from a basic prompt-based chatbot to a sophisticated agent capable of handling complex business logic. The "Agent Garden" from Google Cloud was created to solve this problem by providing a repository of 30 open-source, end-to-end agent examples. These examples serve as blueprints for developers to understand how to implement sophisticated workflows that are robust enough for enterprise use.

These agents are built using the Google ADK and are designed to be deployed directly to Google Cloud, leveraging the full suite of Google Cloud AI tooling. The primary goal of these examples is to demonstrate "patterns"—repeatable architectural designs—that developers can adopt and adapt for their own specific business needs, ensuring that agents are not just generative, but deterministic and governed.

Core Concepts

The Constitution (Governance Layer)

The "Constitution" is the foundational set of rules that guides the agent's behavior and decision-making process. Rather than relying solely on a system prompt, the constitution acts as a formal rule book (often stored as a Markdown file) that defines the boundaries of what the agent can and cannot do. This ensures that the agent's actions are aligned with company policy and legal requirements.

In the invoice processing example, the constitution contains specific rules regarding what makes an invoice valid. Some of these rules are deterministic (binary, yes/no logic that does not require an LLM), while others are executed by an LLM to handle nuance and reasoning. This hybrid approach ensures high precision for simple checks and flexibility for complex interpretations.

The Acting Agent (Execution Layer)

The Acting Agent is the primary worker responsible for the "heavy lifting" of the workflow. Its role is to receive the input—such as a PDF invoice—and execute a multi-step process: classifying the document, extracting the relevant data, validating that data against the constitution, and reasoning through the findings to reach a conclusion.

The Acting Agent does not operate in a vacuum; it is the first stage of a pipeline. Its output is not treated as the final answer but as a proposal that must be verified. This separation of concerns prevents the "hallucinations" common in single-agent systems by ensuring the agent's work is subject to a secondary review process.

The Critic Agent (Validation Pattern)

The Critic Agent implements a critical design pattern: the "Validator" or "Critic" pattern. In this architecture, the system does not trust the Acting Agent's output implicitly. The Critic Agent's sole purpose is to review the work of the Acting Agent and verify that it followed the rules laid out in the Constitution.

This pattern is widely applicable across various domains. For example, in software engineering, one agent might implement a piece of code (the Acting Agent), while a second agent (the Critic Agent) validates that the code is correct, secure, and follows style guidelines. This "double-check" mechanism significantly increases the reliability of the system's output.

Adaptive Learning Framework (ALF)

The Adaptive Learning Framework (ALF) is a sophisticated mechanism that allows an agent to learn from its mistakes through human feedback. Instead of requiring a developer to manually rewrite the system prompt or retrain a model, the ALF allows the agent to update its own rule book based on real-world corrections.

The ALF enables the system to operate in two distinct modes: Inference Mode (where it processes tasks based on existing rules) and Learning Mode (where it accepts feedback to create new rules). When a human expert identifies a mistake, the ALF analyzes how a new rule would have changed the outcome of previous cases, ensuring the new rule is "safe" before it is officially incorporated into the rule book.

How It Works / Step-by-Step

The Invoice Processing Workflow

The invoice processing agent follows a structured pipeline to ensure accuracy and compliance:

  1. Input Reception: The agent receives a PDF invoice (or a case number referring to a stored PDF).
  2. Acting Phase: The Acting Agent classifies the invoice, extracts the data, and reasons through the data based on the Constitution.
  3. Critic Phase: The Critic Agent reviews the Acting Agent's reasoning and validates it against the Constitution.
  4. Outcome: The invoice is either "Accepted" (fully compliant) or "Rejected" (non-compliant), with a specific reference to the rule that caused the rejection (e.g., "Rejected because of Section 4").

The Learning and Adaptation Process

When a human expert determines that the agent's decision was incorrect, the following "Learning Mode" workflow is triggered:

  1. Switch to Learning Mode: The user explicitly tells the system to enter learning mode.
  2. Feedback Input: The human expert provides a correction (e.g., "Accept invoices without an order if the amount is under $1,500").
  3. Rule Proposal: The Rule Learning Agent proposes a new rule in a structured format (JSON) and explains the logic.
  4. Impact Analysis: The system scans existing cases to see how the new rule would affect them. It reports which cases would now be "matches" and which would not, proving whether the rule is "safe" (i.e., it doesn't accidentally approve thousands of previously rejected, invalid invoices).
  5. Human Approval: The human expert chooses to Approve, Reject, Revise, or Discard the proposed rule.
  6. Promotion: Once approved, the rule is added to the rule book. Periodically, frequent patterns are promoted and integrated directly into the Acting Agent's core logic.

Real-World Examples & Use Cases

Case Study: Invoice Validation

In the provided example, the agent processed two distinct cases:

  • Case 2: The agent analyzed the invoice and found it fully compliant with all rules. The result was "Accepted."
  • Case 5: The agent rejected the invoice because it lacked a required authorization order for the work performed (per Section 4 of the rule book).
  • The Adaptation: The user entered Learning Mode and created a new rule: "Accept any invoice without an order as long as the amount is under $1,500." The system analyzed Case 5, found it matched the new rule, and proposed the update.

Extended Use Case: Automated Code Review

Applying these patterns to a coding assistant:

  • Acting Agent: Writes a Python function to handle a specific API request.
  • Critic Agent: Checks the code for security vulnerabilities (e.g., SQL injection) and ensures it follows the company's internal style guide.
  • ALF: If a senior developer corrects the code, the agent learns a new rule (e.g., "Always use this specific library for database connections") and applies that rule to all future code generation.

Extended Use Case: Legal Document Review

Applying these patterns to contract analysis:

  • Acting Agent: Scans a contract for "Change of Control" clauses.
  • Critic Agent: Verifies that the Acting Agent didn't miss any subtle phrasing that implies a change of control.
  • ALF: If a lawyer identifies a new type of clause that should be flagged, the system learns that pattern and updates the "Constitution" for all future contract reviews.

Key Insights & Takeaways

  • Don't Trust the First Agent: Always implement a Critic Agent to validate the output of the Acting Agent to prevent hallucinations and errors.
  • Separate Rules from Logic: Use a "Constitution" (Markdown/JSON) to store rules separately from the agent's core logic, making it easier to audit and update.
  • Implement Dual-Mode Operation: Use "Inference Mode" for production and "Learning Mode" for continuous improvement via human-in-the-loop feedback.
  • Perform Impact Analysis: Before adopting a new rule, the system must scan historical data to ensure the new rule doesn't create unintended side effects.
  • Hybrid Rule Execution: Combine deterministic rules (hard-coded logic) with LLM-based rules (reasoning) to balance precision and flexibility.
  • One-Click Deployment: Utilizing platforms like Google Cloud AI allows for rapid deployment of these complex architectures, moving from a GitHub repo to a running instance quickly.

Common Pitfalls / What to Watch Out For

  • Over-reliance on the Acting Agent: Beginners often stop at the Acting Agent, which leads to high error rates. The absence of a Critic Agent is a major architectural flaw.
  • Unchecked Rule Updates: Adding rules without an "Impact Analysis" (like the one provided by ALF) can lead to "rule drift," where new rules contradict old ones or open security holes.
  • Vague Constitutions: If the Constitution is written in ambiguous language, both the Acting and Critic agents will struggle to reach a consistent conclusion. Rules should be as deterministic as possible.

Review Questions

  1. What is the primary difference between the Acting Agent and the Critic Agent, and why is this separation necessary for production-grade AI?
  2. Explain the process of "Impact Analysis" within the Adaptive Learning Framework (ALF). Why is this step critical before approving a new rule?
  3. Imagine you are building an agent to screen resumes for a job. How would you design the "Constitution," the "Acting Agent," and the "Critic Agent" for this specific scenario?

Further Learning

  • Google ADK: Explore the Google Agent Development Kit to understand the underlying framework used to build these agents.
  • Multi-Agent Orchestration: Study frameworks like AutoGen or CrewAI to see how different agent roles (Manager, Worker, Critic) can be coordinated.
  • Human-in-the-Loop (HITL) Design: Research UI/UX patterns for how humans can most effectively "teach" AI agents without needing to write code.
← Previous
Next →