Lab 2: Environment Setup Challenge
Prerequisitesโ
Before you begin, ensure you have the following tools ready:
- Code Editor (IDE): You need a good environment to write your code. We recommend:
- VS Code (Local)
- Project IDX (Cloud-based)
- Google Cloud Shell Editor (Cloud-based)
- Environment Choice (Pick one - see README for full step-by-step guides):
- Option A โ GitHub Codespaces (1-Click in Browser): Open repo on GitHub โ Click
<> Codeโ Codespaces โ "Create codespace". Ready in under 1 minute without installing anything locally! - Option B โ VS Code Dev Containers (Local Docker): Open the repo in VS Code with Docker Desktop running and click "Reopen in Container".
- Option C โ Standard Local Setup (
uvon Host OS): Installuvvia terminal:- macOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh - Windows (PowerShell):
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
- macOS/Linux:
- Option A โ GitHub Codespaces (1-Click in Browser): Open repo on GitHub โ Click
Goalโ
Your task is to prepare your environment for enterprise agent development using modern tools. Try to complete the steps below using your existing knowledge. If you get stuck, the lab-solution.md file provides a detailed, step-by-step walkthrough.
Lab Tasksโ
Step 0: Ensure Python 3.10+ (Crucial)โ
Before you start, you must ensure you are using a modern version of Python. The ADK requires Python 3.10 or higher. Using older versions (like 3.9) will result in numerous warnings and potential crashes.
Fortunately, uv makes this easy. Even if your system doesn't have Python 3.10, you can tell uv to install and use it for your project. (If you are using Codespaces or DevContainer, Python 3.11 is already the active default).
Step 1: Create the Project Structure with uvโ
- Use
uvto initialize a new Python project namedadk-training. Use the--python 3.10flag to guarantee you meet the ADK's requirements:(Note: Run this in your terminal โ whether on your local host or inside the DevContainer/Codespaces terminal).uv init adk-training --python 3.10 - Navigate into the
adk-trainingdirectory. - Use
uv addto install the modern ADK and dotenv:Notice howuv add "google-adk>=2.1.0" python-dotenvuvautomatically creates a virtual environment (.venv) and locks the dependencies inuv.lock.
Step 2: Configure Authenticationโ
Create a file named .env in your adk-training directory. This file will securely store your authentication credentials. Choose one of the two options below.
Option A: Use a Google AI Studio API Key (Recommended for Beginners)
- Get your API key from Google AI Studio.
- Add the following line to your
.envfile:GOOGLE_API_KEY="YOUR_API_KEY"
Option B: Use Agent Platform (Advanced)
- Authenticate with the gcloud CLI:
gcloud auth application-default login - Add the following lines to your
.envfile, replacing the placeholder values with your Google Cloud project details:GOOGLE_GENAI_USE_VERTEXAI="1"
GOOGLE_CLOUD_PROJECT="your-gcp-project-id"
GOOGLE_CLOUD_LOCATION="us-central1"
Note on
adk createand.envvariables: Later modules useuv run adk create <name>to scaffold a project. That command is an interactive wizard โ it will prompt you for choices like the model, backend, GCP project, and region, so don't be surprised when it asks questions instead of just running silently. Also, the.envfile it auto-generates may showGOOGLE_GENAI_USE_ENTERPRISE=1instead of theGOOGLE_GENAI_USE_VERTEXAI=1used in this lab's examples. Both variables are real and fully supported โ they are functionally equivalent ways of telling the ADK to use Vertex AI/Agent Platform. If you seeGOOGLE_GENAI_USE_ENTERPRISE=1in a generated.envfile, that's fine; there's no need to "fix" it to match theGOOGLE_GENAI_USE_VERTEXAI=1shown elsewhere in the docs.
Step 3: Verification Scriptโ
Create a file named verify_setup.py and add the following content:
# verify_setup.py
import asyncio
import os
from dotenv import load_dotenv
from google.adk import Agent
from google.adk.apps import App
from google.adk.runners import InMemoryRunner
async def main():
load_dotenv()
print("๐ Testing ADK 2.0 Environment...")
try:
# 1. Define a simple Node (Agent)
agent = Agent(
name="verify_agent",
model="gemini-3.5-flash",
instruction="Respond with: 'ADK 2.0 is Ready!'"
)
# 2. Create the App
app = App(name="verify_app", root_agent=agent)
# 3. Initialize the Runner
runner = InMemoryRunner(app=app)
# 4. Execute using the new run_debug helper
print("๐ Connecting to LLM...")
events = await runner.run_debug("Hello!", user_id="test_user")
# Verify the response
ready = False
for event in events:
if event.is_final_response():
print(f"โ
Agent Response: {event.content.parts[0].text}")
ready = True
if ready:
print("\n๐ SETUP COMPLETE! You are running ADK 2.0.")
else:
print("\nโ Failed to get a final response from the agent.")
except ImportError as e:
print(f"โ Version Error: {e}")
print("Ensure you installed google-adk>=2.1.0")
except Exception as e:
print(f"โ An unexpected error occurred: {e}")
if __name__ == "__main__":
asyncio.run(main())
Step 4: Run the Verificationโ
Execute the script using uv run. This command ensures that your script runs within the virtual environment that uv created, without you needing to manually activate it!
uv run python verify_setup.py
๐ก Troubleshooting: Model Not Found (404)โ
If you see an error like Publisher Model ... gemini-3.5-flash was not found, it usually means the specific model is not yet available in your chosen Google Cloud region (e.g., us-central1).
The Fix:
- Open your
.envfile. - Change
GOOGLE_CLOUD_LOCATIONto a different supported region, such asus-east4,us-west1, oreurope-west9. - Run the verification script again.
- If switching regions doesn't resolve it, the model may simply not be enabled/allowlisted for your specific GCP project at all. Check the Vertex AI Model Garden in your project, or contact your project admin to confirm access.
Note: You might see a
UserWarningregarding an[EXPERIMENTAL]feature (likePLUGGABLE_AUTH). You can safely ignore this; it is just the ADK informing you of its internal development state and does not affect your lab.
Self-Reflection Questionsโ
- Why is
uvconsidered a major upgrade over traditional tools likepipandvenv? - What is the purpose of the
uv.lockfile generated in your project directory? - What are the security implications of storing API keys in a
.envfile versus hardcoding them in your script?
๐ Reference Solution Vaultโ
Module 02 Reference Solution Vault
Active Comprehension Gate โข Zero Guessable URLs โข Guided Verification