Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 22

Setting Up Your Google ADK Environment

Recommended resources

Hello! Welcome to the next phase of our journey into agent development.

In the previous module, you gained hands-on experience building robust agents with LangGraph, culminating in implementing sophisticated error handling and retry mechanisms. We're now shifting our focus to a different, yet equally influential, part of the ecosystem: Google's Agent Development Kit (ADK). While LangGraph excels at creating explicit, stateful graphs, ADK offers a code-first approach tightly integrated with the Google Cloud ecosystem.

Today's lesson is purely foundational and practical. Our goal is to set up the Google Agent Development Kit (ADK) environment. By the end of this session, you will have a fully configured local development environment, ready for building your first Google ADK agent. We will cover everything from configuring your cloud project to installing the necessary tools and verifying that your setup is working correctly.

The ADK Environment: Two Paths

There are two primary ways to configure your environment for Google ADK:

  1. Google AI Path: A simpler setup using a Gemini API key directly from Google AI Studio. It's great for quick prototypes.
  2. Vertex AI Path: A more robust, production-oriented setup that integrates with a Google Cloud project. This path uses cloud-native authentication and is better for building scalable, manageable applications.

Given your interest in industry practices, we will focus on the Vertex AI path. It represents a more realistic setup for deploying agents in a professional context.


Step 1: Configure Your Google Cloud Project

Unlike our work with LangGraph where an API key was often sufficient, the ADK's Vertex AI integration relies on a configured Google Cloud Project. This project acts as a central hub for managing APIs, resources, and billing.

The Google Codelab, "Building AI Agents with ADK: The Foundation," provides a clear, step-by-step guide for this process. We will follow its instructions closely.

Building AI Agents with ADK: The Foundation

This Google Codelab is our primary guide for setting up the cloud environment. It walks through creating a project and enabling the necessary APIs.

Please follow the instructions in Step 3: Configure Google Cloud Services. This involves: Creating a new Google Cloud project. Launching the Cloud Shell (or using your local terminal with gcloud CLI installed). Setting your project ID using gcloud config set project YOUR_PROJECT_ID. Enabling the Vertex AI API with gcloud services enable aiplatform.googleapis.com. Completing these steps ensures your environment is authenticated and authorized to use Vertex AI.

Key takeaway: With the Vertex AI path, you typically don't need to manage API keys in .env files for authentication. By using the gcloud CLI and logging in (gcloud auth application-default login), your environment is automatically authenticated, which is a more secure and standard practice in cloud development.


Step 2: Set Up the Local Python Environment

Now that your cloud environment is ready, let's prepare your local machine. As a software engineer, this process of creating a virtual environment and installing packages will be very familiar.

  1. Create a Project Directory: Make a new folder for your ADK projects.

    mkdir google-adk-agents
    cd google-adk-agents
    
  2. Create and Activate a Virtual Environment:

    # For Mac/Linux
    python3 -m venv .venv
    source .venv/bin/activate
    
    # For Windows
    python -m venv .venv
    .venv\Scripts\activate
    
  3. Install Google ADK: Use pip to install the core ADK library.

    pip install google-adk
    

    You can verify the installation with pip show google-adk.

For reference, these commands are also covered in the official ADK documentation page, "Installing ADK".


Step 3: Scaffold an Agent Project with the ADK CLI

One of the most convenient features of ADK is its command-line interface (CLI), which can generate a starter project with the correct file structure. This is a significant difference from frameworks like LangChain/LangGraph, where you typically create the structure manually.

ADK expects a specific structure for it to discover and run your agents:

  • A directory named after your agent (e.g., my_first_agent/).
  • An __init__.py file to mark the directory as a Python package.
  • An agent.py file containing your agent's logic.
  • A .env file for configuration variables.

The adk create command handles all of this for you.

Building AI Agents with ADK: The Foundation

Let's use the ADK's built-in command to create our first agent's file structure. The codelab demonstrates this process perfectly.

Please follow the instructions in Step 4 and Step 5, then review Step 6. Step 5: Create an agent: Run adk create personal_assistant in your terminal. This will launch an interactive prompt. For the model, choose gemini-1.5-flash or a similar available option. For the backend, choose Vertex AI. Confirm your Google Cloud Project ID and region (us-central1 is a good default). Step 6: Explore agent codes: After the command finishes, examine the three files it created: agent.py, __init__.py, and .env. The codelab provides an excellent explanation of each file's role and content. Pay close attention to the variables set in the .env file for the Vertex AI backend.

The agent.py file will contain a predefined root_agent. This specific variable name is mandatory; it's how the ADK runtime identifies the main agent to execute in the package.

Test your understanding!

Based on the required project structure, what do you predict would happen if you renamed the root_agent variable in agent.py to my_agent and then tried to run adk run personal_assistant?

Show answer

The command would fail with an error, likely stating something like AttributeError: module 'personal_assistant.agent' has no attribute 'root_agent'. The ADK runtime specifically looks for a variable named root_agent within the agent.py module to serve as the entry point. This strict convention is part of what makes the ADK framework discoverable and opinionated.


Step 4: Verify Your Setup

The final step is to confirm that everything is connected and working. The ADK provides two ways to run your agent, both of which are useful for testing your environment.

This video from DataCamp provides a clear walkthrough of running the agent via both the CLI and the web interface.

Google ADK for Beginners: Developing AI Agents with Google

This video will show you exactly how to run your newly created agent and what to expect. Watching this will help you verify your own setup.

Please watch the segment from 00:12:14 to 00:18:39. The presenter demonstrates: Running the agent in the terminal using adk run <agent_folder_name>. Interacting with the agent directly in the command line. Launching the development web UI with adk web. Interacting with the agent in the much richer web interface and inspecting the events and request data.

Now, try it yourself:

  1. Run in Terminal:

    adk run personal_assistant
    

    You should see a [user]: prompt. Type "Hello" and press Enter. The agent should respond. Type exit to quit.

  2. Run with Web UI:

    adk web
    

    This will start a local web server. Open your browser to http://localhost:8000. You will see a clean, chat-like interface where you can select your personal_assistant agent and interact with it. This web UI is an excellent tool for debugging that we will use in future lessons.

If both of these methods work, your environment is successfully set up!

If you encounter a billing or API error, refer to the Troubleshooting section in Step 7 of the "Building AI Agents with ADK: The Foundation" codelab (LINK) for solutions.


Conclusion

Congratulations! You have successfully configured a complete, production-oriented development environment for the Google Agent Development Kit. While it involves a few more initial steps than just using an API key, this Vertex AI-integrated setup provides a robust and scalable foundation for building serious agentic applications.

Key Takeaways:

  • Vertex AI vs. Google AI: You learned the difference between the simple API key path and the more robust Google Cloud Project (Vertex AI) path for ADK setup.
  • The adk CLI is Key: The adk create command is a powerful tool for scaffolding projects with the correct, required structure.
  • Convention over Configuration: ADK relies on conventions like the personal_assistant/ folder structure and the root_agent variable name to automatically discover and run agents.
  • Verification is Twofold: You can run and test agents either directly in the terminal with adk run or through the much richer debugging interface provided by adk web.

Now that your environment is ready, you're all set to start building. In the next lesson, we will dive into the agent.py file to construct a basic agent using Google ADK's core primitives, moving from this setup phase to active development.