Install ADK and set up your environment

Sprawdź postępy

/ 25

Explore the ADK agent

Sprawdź postępy

/ 25

Deploy the Agent as an A2A Server

Sprawdź postępy

/ 25

Enable another ADK agent to call the agent remotely

Sprawdź postępy

/ 25

Ten moduł może zawierać narzędzia AI, które ułatwią Ci naukę.
Note: To ensure a consistent and high-performance experience, this lab may provide cached responses for some model requests.

GENAI120

Google Cloud self-paced labs

Overview

The Agent2Agent (A2A) protocol addresses a critical challenge in the AI landscape: enabling generative AI agents, built on diverse frameworks by different companies running on separate servers, to communicate and collaborate effectively – as agents, not just as tools. A2A aims to provide a common language for agents, fostering a more interconnected, powerful, and innovative AI ecosystem.

A2A is built around a few core concepts that make it powerful and flexible:

  • Standardized Communication: JSON-RPC 2.0 over HTTP(S).
  • Agent Discovery: Agent Cards detail an agent's capabilities and connection info, so agents can discover each other and learn about each other's capabilities
  • Rich Data Exchange: Handles text, files, and structured JSON data.
  • Flexible Interaction: Supports synchronous request/response, streaming (SSE), and asynchronous push notifications.
  • Enterprise-Readiness: Designed with security, authentication, and observability in mind.

Objectives

In this lab, you learn how to perform the following tasks:

  • Set up your environment and install the Agent Development Kit (ADK).
  • Deploy an ADK agent as an A2A Server.
  • Prepare a JSON Agent Card to describe an A2A agent's capabilities.
  • Enable another ADK agent to read the Agent Card of your deployed A2A agent and use it as a sub-agent.

Setup and requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.

This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito (recommended) or private browser window to run this lab. This prevents conflicts between your personal account and the student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab—remember, once you start, you cannot pause a lab.
Note: Use only the student account for this lab. If you use a different Google Cloud account, you may incur charges to that account.

How to start your lab and sign in to the Google Cloud console

  1. Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:

    • The Open Google Cloud console button
    • Time remaining
    • The temporary credentials that you must use for this lab
    • Other information, if needed, to step through this lab
  2. Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).

    The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Arrange the tabs in separate windows, side-by-side.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username below and paste it into the Sign in dialog.

    {{{user_0.username | "Username"}}}

    You can also find the Username in the Lab Details pane.

  4. Click Next.

  5. Copy the Password below and paste it into the Welcome dialog.

    {{{user_0.password | "Password"}}}

    You can also find the Password in the Lab Details pane.

  6. Click Next.

    Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  7. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Google Cloud console opens in this tab.

Note: To access Google Cloud products and services, click the Navigation menu or type the service or product name in the Search field. Navigation menu icon and Search field

Task 1. Install ADK and set up your environment

In this lab environment, the Agent Platform API and Cloud Run API have been enabled for you. If you were to follow these steps in your own project, you would enable them by navigating to Agent Platform and following the prompt to enable it.

Prepare a Cloud Shell Editor tab

  1. With your Google Cloud console window selected, press G,S to open Cloud Shell. Alternatively, you can click the Activate Cloud Shell button (Activate Cloud Shell) in the upper right of the Cloud console.
  2. Click Continue.
  3. When prompted to authorize Cloud Shell, click Authorize.
  4. In the upper-right corner of the Cloud Shell terminal panel, click the Open in new window button (Open in new window button).
  5. Click the Open Editor pencil icon (Edit pencil icon) at the top of the pane to view files.
  6. At the top of the left-hand navigation menu, click the Explorer icon (Explorer icon) to open your file explorer.
  7. Click the Open Folder button.
  8. In the Open Folder dialog that opens, click OK to select your student account's home folder.
  9. Close any additional tutorial or Gemini panels that appear on the right side of the screen to save more of your window for your code editor.
  10. Throughout the rest of this lab, you work in this window as your IDE with the Cloud Shell Editor and Cloud Shell terminal.

Download and install the ADK and code samples for this lab

  • Download code for this lab and install the Agent Development Kit (ADK) and other requirements by running the following code in the Cloud Shell terminal:

    gcloud storage cp -r gs://{{{project_0.project_id| YOUR_GCP_PROJECT_ID}}}-bucket/* . export PATH=$PATH:"/home/${USER}/.local/bin" python3 -m pip install --upgrade google-adk[a2a]==1.31.0 google-genai

    Click Check my progress to verify the objective. Install ADK and set up your environment.

Task 2. Explore the ADK agent you plan to make available remotely

For the purposes of this lab, imagine you work for a stadium maintenance company, Cymbal Stadiums. As part of a recent project, you developed an image generation agent that can create illustrations according to your brand guidelines. Now, several different teams in your organization want to use it too.

If you were to copy the code for use as a sub-agent by many agents, it would be very difficult to maintain and improve all of these copies.

Instead, you can deploy the agent once as an agent wrapped with an A2A server, and the other teams' agents can incorporate it by querying it remotely.

  1. In the Cloud Shell Editor's file explorer pane, navigate to the adk_and_a2a/illustration_agent directory. This directory contains the ADK agent you plan to make available remotely. Click the directory to toggle it open.

  2. Open the agent.py file in this directory and scroll to the section labeled # Tools.

  3. Notice the generate_image() function, which is used as a tool by this agent. It receives a prompt and performs a two-step process. First, it uses the Google Gen AI SDK to call generate_content(), which returns the raw image data directly in the response. Second, the function uses the Cloud Storage library to upload these image bytes to a Google Cloud Storage bucket. Finally, the tool returns a URL for the newly created image file.

  4. Notice that the instruction provided to the root_agent provides specific instructions to the agent to use image-generation prompts that respect the company's brand guidelines. For example, it specifies:

    • a specific illustration style: (Corporate Memphis)
    • a color palette (purples and greens on sunset gradients)
    • examples of stadium/sports and maintenance imagery because it is a stadium maintenance company
  5. To see it in action, you first need to write a .env file to set environment variables needed by ADK agents. Run the following in the Cloud Shell terminal to write this file in this directory.

    cd ~/adk_and_a2a cat << EOF > illustration_agent/.env GOOGLE_GENAI_USE_VERTEXAI=TRUE GOOGLE_CLOUD_PROJECT={{{project_0.project_id| YOUR_GCP_PROJECT_ID}}} GOOGLE_CLOUD_LOCATION=global MODEL={{{project_0.startup_script.gemini_flash_model_id | gemini_flash_model_id}}} IMAGE_MODEL={{{project_0.startup_script.gemini_flash_image_model_id | gemini_flash_image_model_id}}} EOF
  6. Run the following to copy the .env to another agent directory you are using in this lab:

    cp illustration_agent/.env slide_content_agent/.env
  7. To enable the agent to create a signed URL for its images, you must impersonate a dedicated service account. Run the following command to configure application default credentials with impersonation:

    gcloud auth application-default login \ --impersonate-service-account=illustration-agent-sa@{{{project_0.project_id|YOUR_GCP_PROJECT_ID}}}.iam.gserviceaccount.com
  8. You will be asked in Cloud Shell Terminal to confirm that you would like to authenticate with a personal account. Type Y (to indicate 'Yes') and press Enter.

  9. Click the link provided and select your Qwiklabs student account to authenticate.

  10. Once authenticated, you will be presented an authorization code. Use the Copy button to copy that code and return to the Cloud Shell Terminal.

  11. Paste the copied code into the Cloud Shell Terminal and press Enter.

  12. Now from the Cloud Shell terminal, launch the Agent Development Kit Dev UI with the following command:

    adk web --allow_origins "regex:https://.*\.cloudshell\.dev"

    Output

    INFO: Started server process [2434] INFO: Waiting for application startup. +-------------------------------------------------------+ | ADK Web Server started | | | | For local testing, access at http://localhost:8000. | +-------------------------------------------------------+ INFO: Application startup complete. INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
  13. To view the web interface in a new tab, click the http://127.0.0.1:8000 link at the bottom of the terminal output.

  14. A new browser tab opens with the ADK Dev UI.

  15. In the ADK Dev UI tab, from the Select an app drop-down on the left, select the illustration_agent.

  16. Prompt the agent with some text that could be used in a recruitment slide deck:

    By supporting each other, we get big things done!
  17. After a minute or two, the agent responds with the prompt it generated and a preview of the image.

    Example Output

    Response and generated image.

  18. Notice that the prompt you provided to the agent didn't mention sports, stadiums, or maintenance work, but the agent took your text and the brand guidelines and combined them into a single prompt for the image generation model.

    When you are finished exploring the base agent, close the browser tab.

  19. Return to the Cloud Shell terminal and press CTRL+C to stop the server.

    Click Check my progress to verify the objective. Explore the ADK agent.

Task 3. Deploy the agent as an A2A Server

In this task, you take the steps to deploy this agent as a remote A2A agent. An A2A Agent identifies itself and its capabilities by serving an Agent Card.

  1. Run the following to create an agent.json file:

    cat << EOF > illustration_agent/agent.json { "name": "illustration_agent", "description": "An agent designed to generate branded illustrations for Cymbal Stadiums.", "defaultInputModes": ["text/plain"], "defaultOutputModes": ["application/json"], "skills": [ { "id": "illustrate_text", "name": "Illustrate Text", "description": "Generate an illustration to illustrate the meaning of provided text.", "tags": ["illustration", "image generation"] } ], "url": "https://illustration-agent-{{{project_0.startup_script.project_number|Project Number}}}.{{{project_0.default_region| GCP_LOCATION}}}.run.app/a2a/illustration_agent", "capabilities": {}, "version": "1.0.0" } EOF
  2. Review the JSON in the agent.json file. Notice that it gives the agent a name and description and identifies some skills. It also indicates a url where the agent itself can be called.

    The agent's url is constructed to be its Cloud Run service URL once you have deployed it following the instructions in this lab.

    While similar in name to skills, the parameter capabilities here is reserved to indicate abilities like streaming.

  3. Run the following to create a requirements.txt file in the illustration_agent directory:

    cat << EOF > illustration_agent/requirements.txt google-adk[a2a]==1.31.0 EOF
  4. In the following command, you use adk deploy cloud_run with the --a2a flag to deploy your agent to Cloud Run as an A2A server:

    adk deploy cloud_run \ --project {{{project_0.project_id| YOUR_GCP_PROJECT_ID}}} \ --region {{{project_0.default_region| GCP_LOCATION}}} \ --service_name illustration-agent \ --a2a \ illustration_agent \ -- \ --service-account=illustration-agent-sa@{{{project_0.project_id| YOUR_GCP_PROJECT_ID}}}.iam.gserviceaccount.com \ --set-env-vars="GOOGLE_CLOUD_LOCATION=global"
  5. When prompted to allow unauthenticated responses, type Y, and then press ENTER.

    While the agent deploys, review the following arguments passed to the command:

    • The --project and --region define the project and region in which your Cloud Run service will be deployed.
    • The --service_name defines the name for the Cloud Run service.
    • The --a2a flag indicates it should be hosted as an A2A agent. This means that your agent will be wrapped by a class that bridges ADK and A2A agents, the A2aAgentExecutor. This class translates A2A Protocol's language of tasks and messages to an ADK Runner in its language of events.
    • The -- separator is used to pass flags directly to the underlying gcloud run deploy command. Any flags listed after -- are ignored by the ADK tool and handled directly by the Google Cloud CLI. Here it is used to assign the dedicated service account and set the GOOGLE_CLOUD_LOCATION environment variable on the initial deployment.
    Note: Deployment should take about 5-10 minutes. If you encounter a PERMISSION_DENIED error, try running the above command again.

    Expected output:

    You should see steps relating to building a Dockerfile and deploying the container, then deploying the service, followed by:

    Service [illustration-agent] revision [illustration-agent-00001-xpp] has been deployed and is serving 100 percent of traffic. Service URL: https://illustration-agent-{{{project_0.startup_script.project_number|Project Number}}}.{{{project_0.default_region| GCP_LOCATION}}}.run.app

    Click Check my progress to verify the objective. Deploy the Agent as an A2A Server.

Task 4. Enable another ADK agent to call this agent remotely

In this task, you provide a second ADK agent the ability to identify your illustration agent's capabilities and call it remotely. This second agent is tasked with creating contents for slides. It must write a headline and a couple of sentences of body text, then transfer to the illustration agent to generate an image to illustrate that text.

  1. In the Cloud Shell terminal, run the following command to copy the Agent Card JSON file to your adk_and_a2a directory and change its name to indicate that it represents the illustration_agent:

    cp illustration_agent/agent.json illustration-agent-card.json
  2. In the Cloud Shell Editor's file explorer pane, navigate to the adk_and_a2a/slide_content_agent directory, and open the agent.py file.

    Review this agent's instruction to see that it takes a user's suggestion for a slide, uses that to write a headline & body text, and then requests that your A2A agent provides an illustration for the slide.

  3. Paste the following code under the # Agents header (around line #16) to add the remote agent using the RemoteA2aAgent class from ADK:

    illustration_agent = RemoteA2aAgent( name="illustration_agent", description="Agent that generates illustrations.", agent_card=( "illustration-agent-card.json" ), )
  4. Add the illustration_agent as a sub-agent of the root_agent by adding the following parameter under # Add the sub_agents parameter below in the same file:

    sub_agents=[illustration_agent]
  5. Save the file.

  6. Launch the UI from the Cloud Shell terminal with the following command:

    cd ~/adk_and_a2a adk web --allow_origins "regex:https://.*\.cloudshell\.dev"
  7. Once again, click the http://127.0.0.1:8000 link in the terminal output to launch the ADK Dev UI.

  8. In the ADK Dev UI browser tab, from the Select an app drop-down on the left, select the slide_content_agent.

  9. Prompt the agent with an idea for a slide as follows:

    Create content for a slide about our excellent on-the-job training.

    You should see the following output:

    • A headline and body text written by the slide_content_agent itself.
    • A call to transfer_to_agent, indicating a transfer to the illustration_agent.
    • The response from the illustration_agent with the new image.

    Expected output:

    The agent generates text, then transfers to the illustration_agent to generate an image.

    Click Check my progress to verify the objective. Enable another ADK agent to call the agent remotely.

Congratulations!

In this lab, you demonstrated the power of cross-agent collaboration using the A2A Protocol! You deployed a local ADK agent onto Cloud Run as a discrete microservice and detailed its abilities via a standardized Agent Card. Then, you securely handed off tasks from a secondary independent agent. With these foundational skills, you are ready to start building scalable, multi-agent ecosystems across distributed teams.

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated April 21, 2026

Lab Last Tested April 21, 2026

Copyright 2026 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.

Zanim zaczniesz

  1. Moduły tworzą projekt Google Cloud i zasoby na określony czas.
  2. Moduły mają ograniczenie czasowe i nie mają funkcji wstrzymywania. Jeśli zakończysz moduł, musisz go zacząć od początku.
  3. Aby rozpocząć, w lewym górnym rogu ekranu kliknij Rozpocznij moduł.

Użyj przeglądania prywatnego

  1. Skopiuj podaną nazwę użytkownika i hasło do modułu.
  2. Kliknij Otwórz konsolę w trybie prywatnym.

Zaloguj się w konsoli

  1. Zaloguj się z użyciem danych logowania do modułu. Użycie innych danych logowania może spowodować błędy lub naliczanie opłat.
  2. Zaakceptuj warunki i pomiń stronę zasobów przywracania.
  3. Nie klikaj Zakończ moduł, chyba że właśnie został przez Ciebie zakończony lub chcesz go uruchomić ponownie, ponieważ spowoduje to usunięcie wyników i projektu.

Ta treść jest obecnie niedostępna

Kiedy dostępność się zmieni, wyślemy Ci e-maila z powiadomieniem

Świetnie

Kiedy dostępność się zmieni, skontaktujemy się z Tobą e-mailem

Jeden moduł, a potem drugi

Potwierdź, aby zakończyć wszystkie istniejące moduły i rozpocząć ten

Aby uruchomić moduł, użyj przeglądania prywatnego

Najlepszym sposobem na uruchomienie tego laboratorium jest użycie okna incognito lub przeglądania prywatnego. Dzięki temu unikniesz konfliktu między swoim kontem osobistym a kontem do nauki, co mogłoby spowodować naliczanie dodatkowych opłat na koncie osobistym.

Aby rozpocząć laboratorium, wykonaj to krótkie zadanie.