Lab 3 Challenge: Build and Run the "Echo" Agent
Goalโ
Your task is to create, configure, and run a simple "Echo" agent using the ADK.
The Challenge: Unlike a standard chatbot, this agent must act like a parrot. It should never answer questions or provide information; it must only repeat the user's input exactly as it was received.
Expected Behaviorโ
| User Input | Agent Response (Correct) | Agent Response (Wrong) |
|---|---|---|
| "Hello!" | "Hello!" | "Hi there, how can I help you?" |
| "What is the capital of France?" | "What is the capital of France?" | "The capital of France is Paris." |
| "12345" | "12345" | "You entered the numbers 1 through 5." |
Lab Tasksโ
Environment setup:
- Local machine: If you're continuing the course in sequence,
cdinto theadk-trainingproject you created in Module 2 and skip the block below -- your environment and dependencies already carry forward. If you're starting fresh at this module, create that project first:uv init adk-training --python 3.10 && cd adk-training
uv add "google-adk>=2.1.0" python-dotenv- DevContainer / Codespaces (Alternative): If you opened this repository in a DevContainer or GitHub Codespaces, Python,
uv, and the core ADK dependencies are already pre-installed in your container environment.
- Use the
uv run adk createcommand to scaffold a new agent namedecho_agent. By default, this will create a Python-based project structure:uv run adk create echo_agentNote: This is an interactive wizard โ it will prompt you for choices like the model, backend, GCP project, and region. Answer the prompts as they appear.
- Follow the Python Approach below to define the agent's behavior.
- Instruction Strategy: Craft an instruction that forces the agent to only echo and explicitly forbids it from answering questions or being helpful.
- Configure the
.envfile with your Google API key or Google Cloud project details. - Run the agent using the
uv run adk webcommand (remember to run this from the parent directory of your agent). - Interact with the agent in the Dev UI to verify it passes the "Expected Behavior" tests.
Python Approach (Primary)โ
Modify your agent.py file to look like the following, filling in the TODO sections.
from google.adk import Agent
# TODO: Define the root_agent for your application.
# You will need to provide a name, a model, and the instruction for the agent.
root_agent = Agent(
name=..., # TODO: Give your agent a name (e.g., "echo_agent")
model=..., # TODO: Specify the model to use (e.g., "gemini-3.5-flash")
description=..., # TODO: Provide a short description of what the agent does.
instruction=..., # TODO: Provide the instruction for the echo agent.
)
Alternative Approach: Using YAML Configuration (Informational Only)โ
Note: For the remainder of this course, we will focus exclusively on the Python approach. While the ADK supports YAML configuration, it lacks the flexibility required for the advanced modules you will encounter later. You do not need to perform this step.
If you prefer a simpler, config-based agent, you can define your agent in a YAML file instead of Python. To do this, you would create a root_agent.yaml file instead of agent.py.
# The first line is an optional schema definition that provides
# auto-completion and validation in compatible code editors.
# yaml-language-server: $schema=https://raw.githubusercontent.com/google/adk-python/refs/heads/main/src/google/adk/agents/config_schemas/AgentConfig.json
name: ... # Give your agent a name (e.g., "echo_agent")
model: ... # Specify the model to use (e.g., "gemini-3.5-flash")
instruction: ... # Provide the instruction for the echo agent.
Note: If both
agent.pyandroot_agent.yamlexist in the same directory, the ADK will useagent.py-- the generated__init__.pyhard-imports it, regardless of a sibling YAML file. Avoid keeping both in the same directory.
Self-Reflection Questionsโ
- What are the advantages of defining an agent in a Python script versus a YAML file?
- Why is it important to keep API keys and other secrets in a
.envfile instead of directly in your agent's code? - Explore the "Trace" tab in the Dev UI after running your agent. What information does it provide, and how could this be useful for debugging a more complex agent?
๐ Reference Solution Vaultโ
Module 03 Reference Solution Vault
Active Comprehension Gate โข Zero Guessable URLs โข Guided Verification