Module 3: Your First Agent: The "Echo" Agent

Theoryโ
The Core of an ADK Agentโ
At its heart, an ADK Agent is a blueprint that tells a Large Language Model (LLM) how to behave. This blueprint consists of a few key pieces of information:
name: A unique identifier for your agent.model: The specific LLM that will act as the agent's "brain" (e.g.,gemini-3.8-flash).instruction: The most critical part. This is the detailed prompt that defines the agent's persona, goals, and constraints. Crafting a clear and effective instruction is the key to building a successful agent.description: A short, human-readable summary of the agent's purpose.
Two Ways to Define an Agentโ
The ADK provides two primary methods for creating this blueprint, catering to different needs and complexity levels.
1. Configuration-Based (YAML)โ
The simplest way to define an agent is with a YAML configuration file (e.g., root_agent.yaml). This "configuration-over-code" approach is excellent for rapid prototyping and for agents that don't require complex logic.
Advantages:
- Simple & Fast: Define an agent in just a few lines.
- Clear: The agent's purpose and instructions are easy to read and understand.
- Accessible: Non-programmers can easily create and modify agents.
A typical YAML configuration looks like this:
name: greeter_agent
model: gemini-3.8-flash
description: A polite greeting agent.
instruction: You are a friendly greeter. Welcome the user warmly and introduce yourself.
2. Programmatic (Python)โ
For more advanced scenarios, you can define your agent directly in a Python script (e.g., agent.py) using the Agent class. This is the modern standard in ADK 2.0.
Advantages:
- Flexibility: Allows for dynamic configuration and logic.
- Advanced Features: Required for implementing features like tools, workflows, and plugins.
- Integration: Easily integrates with other Python code and systems.
The same agent defined in Python would look like this:
from google.adk import Agent
root_agent = Agent(
name="greeter_agent",
model="gemini-3.8-flash",
description="A polite greeting agent.",
instruction="You are a friendly greeter. Welcome the user warmly and introduce yourself."
)
Important: When defining an agent in Python, the ADK requires that the main agent variable be named exactly root_agent.
The ADK 2.0 Runtime: App and Runnerโ
In ADK 2.0, defining the agent is only the first step. To actually run it, the framework uses two key concepts:
- App: A container that wraps your
root_agent. It defines the boundaries of your AI application, including its name and any global plugins (like for observability). - Runner: The engine that executes the
App. It handles the session state, manages the connection to the LLM, and provides helper methods likerun_debug().
When you use the CLI command uv run adk web, the ADK automatically creates an App and an InMemoryRunner for you behind the scenes!
Figure 3.1: The 3-layer ADK architecture hierarchy โ comparing Declarative YAML vs. Programmatic Python blueprint definitions, encapsulated in the App container and executed by the InMemoryRunner.
In the ADK 2.0 architecture, what is the specific role of the `Runner` (such as `InMemoryRunner`)?
Scaffolding Your Project with uv run adk createโ
The ADK command-line tool helps you quickly set up the necessary file structure for a new agent.
Running uv run adk create <agent_name> initiates an interactive wizard that lets you choose your preferred method (Config-based or Programmatic) and authentication backend. It then creates a directory containing:
root_agent.yaml(for config-based) oragent.py(for programmatic)..env: A file for storing environment variables, such as your API keys and project settings.
Understanding the adk create Wizard Backend Optionsโ
During creation, the wizard will ask: "Which backend do you want to use?" Here is how each option corresponds to your environment:
- Google AI (Google AI Studio API Key):
- Authentication: Uses a
GOOGLE_API_KEYobtained from Google AI Studio. - Best For: Quick personal prototyping or developers without a Google Cloud project.
- Authentication: Uses a
- Vertex AI (Agent Platform / Enterprise ADC):
- Authentication: Connects to Google Cloud Vertex AI using Application Default Credentials (
gcloud auth application-default login) or Service Accounts. SetsGOOGLE_GENAI_USE_VERTEXAI="1",GOOGLE_CLOUD_PROJECT, andGOOGLE_CLOUD_LOCATION="global". - Best For: Enterprise projects, team training environments, and production deployments on Google Cloud.
- Authentication: Connects to Google Cloud Vertex AI using Application Default Credentials (
- Login with Google (Interactive OAuth):
- Authentication: Launches a browser window to authenticate with your Google account credentials, acquiring temporary user tokens managed directly by the CLI.
- Best For: Fast developer setup without manually copying API keys or creating GCP service accounts.
In the upcoming lab, you will use these concepts to create, configure, and run your first agent.
Key Takeawaysโ
- An ADK agent is defined by its
name,model,instruction, anddescription. - The
instructionis the most critical part, defining the agent's persona, goals, and rules. - Agents can be defined simply with YAML (
root_agent.yaml) or programmatically with Python (agent.py). - The
uv run adk createcommand scaffolds the necessary project structure for a new agent.