arrow_back

Deploy ADK agents to Agent Engine

Sign in Join
Get access to 700+ labs and courses

Deploy ADK agents to Agent Engine

Lab 1 hour 30 minutes universal_currency_alt 5 Credits show_chart Advanced
info This lab may incorporate AI tools to support your learning.
Get access to 700+ labs and courses

GENAI107

Overview

In this lab, you will learn to deploy ADK agents to Agent Engine for a scalable, fully managed environment for your agentic workflows.

This allows you to focus on the agents' logic while infrastructure is allocated and scaled for you.

Objective

In this lab you will learn:

  • Benefits of deploying agents, especially multi-agent systems, to Agent Engine
  • How to wrap an agent to deploy it to Agent Engine
  • How to test an agent locally before deploying
  • How to query an agent deployed to Agent Engine
  • How to list and delete agents

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 will be made available to you.

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

What you need

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
  • Time to complete the lab.

Note: If you already have your own personal Google Cloud account or project, do not use it for this lab.

Note: If you are using a Pixelbook, open an Incognito window to run this lab.

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.

Agent Engine

Vertex AI Agent Engine (formerly known as LangChain on Vertex AI or Vertex AI Reasoning Engine) is a fully managed Google Cloud service enabling developers to deploy, manage, and scale AI agents in production.

You can learn more about its benefits in the Vertex AI Agent Engine documentation.

Task 1. Install ADK and set up your environment

Note: Using an Incognito browser window is recommended for most Qwiklabs to avoid confusion between your Qwiklabs student account and other accounts logged into Google Cloud. If you are using Chrome, the easiest way to accomplish this is to close any Incognito windows, then right click on the Open Google Cloud console button at the top of this lab and select Open link in Incognito window.

Enable Vertex AI recommended APIs

  1. In this lab environment, the Vertex AI API has been enabled for you. If you were to follow these steps in your own project, you could enable it by navigating to Vertex AI and following the prompt to enable it.

Prepare a Cloud Shell Editor tab

  1. With your Google Cloud console window selected, open Cloud Shell by pressing the G key and then the S key on your keyboard. Alternatively, you can click the Activate Cloud Shell button () 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 .

  5. In the Cloud Shell Terminal, enter the following to open the Cloud Shell Editor to your home directory:

    cloudshell workspace ~
  1. 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.
  2. Throughout the rest of this lab, you can work in this window as your IDE with the Cloud Shell Editor and Cloud Shell Terminal.

Download and install ADK and code samples for this lab

  1. Update your PATH environment variable and install ADK by running the following commands in the Cloud Shell Terminal. Note: You will specify the version to ensure that the version of ADK that you install corresponds to the version used in this lab:

    export PATH=$PATH:"/home/${USER}/.local/bin" python3 -m pip install google-adk==1.6.1 --upgrade --force-reinstall
  2. Paste the following commands into the Cloud Shell Terminal to copy a file from a Cloud Storage bucket, and unzip it, creating a project directory with code for this lab:

    gcloud storage cp gs://{{{project_0.project_id| YOUR_GCP_PROJECT_ID}}}-bucket/adk_to_agent_engine.zip . unzip adk_to_agent_engine.zip
  3. Install additional lab requirements with:

    pip3 install -r adk_to_agent_engine/requirements.txt --force-reinstall --no-deps

Task 2. Import a class to wrap your agent and test it locally

  1. In the Cloud Shell Editor's file explorer, navigate to the adk_to_agent_engine/transcript_summarization_agent directory.

  2. Use the Cloud Shell Editor menus, click View > Toggle Hidden Files. (You may have to scroll in this menu to find this menu option.)

  3. Click the file .env within the transcript_summarization_agent directory.

  4. Update it to the following values:

    GOOGLE_GENAI_USE_VERTEXAI=TRUE GOOGLE_CLOUD_PROJECT={{{project_0.project_id| YOUR_GCP_PROJECT_ID}}} GOOGLE_CLOUD_LOCATION={{{project_0.default_region| GCP_LOCATION}}} MODEL=gemini-2.0-flash-exp APP_NAME="Transcript Summarizer"
  5. Click Save.

  6. Click View > Toggle Hidden Files to hide the hidden files again.

  7. Click on the agent.py file to review the instructions of this simple summarization agent.

    root_agent = Agent( name="transcript_summarization_agent", description="Summarizes chat transcripts.", model=os.getenv("MODEL", "gemini-2.0-flash-exp"), instruction="Summarize the provided chat transcript.", )
  8. An agent deployed to Agent Engine needs to be able to act as a web app that can create and retrieve user sessions from its session service. To see this locally, right-click on the transcript_summarization_agent directory and select New File....

  9. Name the file test_agent_app_locally.py.

  10. In this file, paste the following code:

    import logging import google.cloud.logging import asyncio from vertexai.preview import reasoning_engines from agent import root_agent logging.basicConfig(level=logging.INFO) cloud_logging_client = google.cloud.logging.Client() cloud_logging_client.setup_logging() async def main(): agent_app = reasoning_engines.AdkApp( agent=root_agent, enable_tracing=True, ) session = await agent_app.create_session(user_id="u_123") for event in agent_app.stream_query( user_id="u_123", session_id=session.id, message=""" Virtual Agent: Hi, I am a vehicle sales agent. How can I help you? User: I'd like to buy a car. Virtual Agent: Can I interest you in a boat? User: No, a car. Virtual Agent: This boat will be $10,000. User: Goodbye. """, ): logging.info("[local test] " + event["content"]["parts"][0]["text"]) cloud_logging_client.flush_handlers() if __name__ == "__main__": asyncio.run(main())
  11. Review the code above. Notice that your root_agent is imported from your agent.py file. This script then uses the class reasoning_engines.AdkApp to wrap your agent in order for it to act as a web app which can handle the creation and management of user sessions.

  12. Read the transcript that is passed as input so that you can determine if the agent did a good job summarizing it. (The Agent Development Kit can help you be more systematic in evaluating your ADK agents, but that is a topic for another lab.)

  13. Save the file.

  14. This file will execute the stream_query() method of the reasoning_engines.AdkApp class locally. To run it, paste and run this command in the Cloud Shell Terminal:

    cd ~/adk_to_agent_engine/transcript_summarization_agent python3 test_agent_app_locally.py

    Example output (yours may be a little different):

    The user contacted a virtual agent to buy a car, but the agent repeatedly tried to sell the user a boat instead. The user ended the conversation.

Click Check my progress to verify the objective. Test Agent locally.

Task 3. Deploy your agent app to Agent Engine

  1. To create a script to deploy your app to Agent Engine, right-click on the transcript_summarization_agent directory and select New File....

  2. Name the file deploy_to_agent_engine.py.

  3. In this file, paste the following code:

    import os import vertexai from vertexai import agent_engines from dotenv import load_dotenv from agent import root_agent load_dotenv() vertexai.init( project=os.getenv("GOOGLE_CLOUD_PROJECT"), location=os.getenv("GOOGLE_CLOUD_LOCATION"), staging_bucket="gs://" + os.getenv("GOOGLE_CLOUD_PROJECT")+"-bucket", ) remote_app = agent_engines.create( display_name=os.getenv("APP_NAME", "Agent App"), agent_engine=root_agent, requirements=[ "google-cloud-aiplatform[adk,agent_engines]" ] )
  4. Review this script as well. Once again, your root_agent is imported, but this time it is deployed to Agent Engine with the agent_engines.create() method. Behind the scenes, your agent will again be wrapped to handle user sessions.

  5. In the Cloud Shell Terminal, run this file from the transcript_summarization_agent directory with:

    python3 deploy_to_agent_engine.py

    Deployment should take about 10-15 minutes. You can follow the status from the log file that will be linked from the command's output. During that time, the following steps are occurring:

    1. A bundle of artifacts is generated locally, comprising:
      • *.pkl: a pickle file corresponding to local_agent.
      • requirements.txt: a text file containing the package requirements.
      • dependencies.tar.gz: a tar file containing any extra packages.
    2. The bundle is uploaded to Cloud Storage (using a defined directory if specified) for staging the artifacts.
    3. The Cloud Storage URIs for the respective artifacts are specified in the PackageSpec.
    4. The Vertex AI Agent Engine service receives the request and builds containers and spins up HTTP servers on the backend.

    Feel free to prepare the file in the next task for use and review its code while your agent is deploying. If you are following the logs in Logs Explorer, once you notice the log INFO: Application startup complete., your agent should be ready to query. You will also see the following output complete in your Cloud Shell Terminal.

    Example Output:

    Deploying google.adk.agents.Agent as an application. Identified the following requirements: {'cloudpickle': '3.1.1', 'google-cloud-aiplatform': '1.88.0'} The following requirements are missing: {'cloudpickle'} The following requirements are appended: {'cloudpickle==3.1.1'} The final list of requirements: ['google-cloud-aiplatform[adk,agent_engines]', 'cloudpickle==3.1.1'] Creating bucket qwiklabs-gcp-01-0c86710d5fae-bucket in location='us-central1' Wrote to gs://qwiklabs-gcp-01-0c86710d5fae-bucket/agent_engine/agent_engine.pkl Writing to gs://qwiklabs-gcp-01-0c86710d5fae-bucket/agent_engine/requirements.txt Creating in-memory tarfile of extra_packages Writing to gs://qwiklabs-gcp-01-0c86710d5fae-bucket/agent_engine/dependencies.tar.gz Creating AgentEngine Create AgentEngine backing LRO: projects/1058982205918/locations/us-central1/reasoningEngines/4511630460299771904/operations/1923299927245455360 View progress and logs at https://console.cloud.google.com/logs/query?project=qwiklabs-gcp-01-0c86710d5fae AgentEngine created. Resource name: projects/1058982205918/locations/us-central1/reasoningEngines/4511630460299771904 To use this AgentEngine in another session: agent_engine = vertexai.agent_engines.get('projects/1058982205918/locations/us-central1/reasoningEngines/4511630460299771904')
  6. Agent Engine is now available to Preview in the Google Cloud Console. When your agent has completed its deployment, return to your Cloud Console tab and search Agent Engine in the search bar at the top. Select your location for this lab () and you will see your deployed agent. You can click on its name to explore metrics and sessions that will populate as your agent is used.

Click Check my progress to verify the objective. Deploy your agent.

Task 4. Get and query an agent deployed to Agent Engine

  1. For your agent to be able to use models and manage sessions through Vertex AI, you'll need to grant the Agent Engine service agent permissions. Navigate to IAM in the console.
  2. Click the checkbox to Include Google-provided role grants.
  3. Find the AI Platform Reasoning Engine Service Agent (service-PROJECT_NUMBER@gcp-sa-aiplatform-re.iam.gserviceaccount.com) and click the pencil icon in its row.
  4. Click Add another role.
  5. Select Vertex AI User.
  6. Click Save.
  7. Back in the Cloud Shell Editor, create a new Python file by right-clicking on the transcript_summarization_agent directory and selecting New File....
  8. Name the file query_app_on_agent_engine.py.
  9. In this file, paste the following code:
import os from dotenv import load_dotenv import logging import google.cloud.logging from google.cloud.logging.handlers import CloudLoggingHandler import vertexai from vertexai import agent_engines # Load environment variables and initialize Vertex AI load_dotenv() project_id = os.environ["GOOGLE_CLOUD_PROJECT"] location = os.environ["GOOGLE_CLOUD_LOCATION"] app_name = os.environ.get("APP_NAME", "Transcript Summarizer") bucket_name = f"gs://{project_id}-bucket" # Initialize Google Cloud Logging with the correct project ID cloud_logging_client = google.cloud.logging.Client(project=project_id) handler = CloudLoggingHandler(cloud_logging_client, name="transcript-summarizer") logging.getLogger().setLevel(logging.INFO) logging.getLogger().addHandler(handler) # Initialize Vertex AI with the correct project and location vertexai.init( project=project_id, location=location, staging_bucket=bucket_name, ) # Filter agent engines by the app name in .env ae_apps = agent_engines.list(filter=f'display_name="{app_name}"') remote_app = next(ae_apps) logging.info(f"Using remote app: {remote_app.display_name}") # Get a session for the remote app remote_session = remote_app.create_session(user_id="u_456") transcript_to_summarize = """ Virtual Agent: Hi, I am a vehicle sales agent. How can I help you? User: I'd like to buy a boat. Virtual Agent: A big boat, or a small boat? User: How much boat will $50,000 get me? Virtual Agent: That will get you a very nice boat. User: Let's do it! """ # Run the agent with this hard-coded input events = remote_app.stream_query( user_id="u_456", session_id=remote_session["id"], message=transcript_to_summarize, ) # Print responses for event in events: for part in event["content"]["parts"]: if "text" in part: response_text = part["text"] print("[remote response]", response_text) logging.info("[remote response] " + response_text) cloud_logging_client.flush_handlers()
  1. Save the file.

  2. Review the commented code to pay attention to what it is doing.

  3. Review the transcript passed to the agent, so that you can evaluate if it's generating an adequate summary.

  4. In the Cloud Shell Terminal, run the file from the transcript_summarization_agent directory with:

    python3 query_app_on_agent_engine.py

    Example output (yours may be a little different):

    The user wants to buy a boat and has a budget of $50,000. The virtual agent confirmed that this budget is sufficient for a "very nice boat" and the user is ready to proceed with the purchase.

Click Check my progress to verify the objective. Query an agent.

Task 5. List and delete agents deployed to Agent Engine

  1. To list, delete or otherwise manage your agents deployed to Agent Engine, create one more Python file by right-clicking on the transcript_summarization_agent directory and selecting New File....

  2. Name the file agent_engine_utils.py.

  3. In this file, paste the following code:

    import os import fire from dotenv import load_dotenv import vertexai from vertexai import agent_engines # Load environment variables and initialize Vertex AI load_dotenv() vertexai.init( project=os.getenv("GOOGLE_CLOUD_PROJECT"), location=os.getenv("GOOGLE_CLOUD_LOCATION"), staging_bucket="gs://" + os.getenv("GOOGLE_CLOUD_PROJECT") + "-bucket") # Utility functions for working with Agent Engine def list(): """List Agent Engine agents.""" for agent in agent_engines.list(): print(agent.display_name) print(agent.resource_name + "\n") def delete(resource_name): """Delete an Agent Engine agent by its resource_name.""" agent_engines.delete(resource_name, force=True) if __name__ == "__main__": fire.Fire()
The fire package included in this file allows you to run its various functions from the command line.
  1. Run the list() function to list Agent Engine agents with:

    python3 agent_engine_utils.py list

    Example Output:

    Transcript Summarizer projects/1029886909158/locations/us-central1/reasoningEngines/1456078850617245696
  2. When you are ready to delete your agent, run the script again, this time running the delete() function and passing it a resource_name by copying and pasting the resource_name included in the output you received above when you called the list function (include the entire resource_name, for example projects/1029886909158/locations/us-central1/reasoningEngines/1456078850617245696):

    python3 agent_engine_utils.py delete RESOURCE_ID_FROM_PREVIOUS_OUTPUT

    Example Output:

    Deleting AgentEngine resource: projects/1029886909158/locations/us-central1/reasoningEngines/1456078850617245696 Delete AgentEngine backing LRO: projects/1029886909158/locations/us-central1/operations/2884525977596067840 AgentEngine resource deleted: projects/1029886909158/locations/us-central1/reasoningEngines/1456078850617245696

Click Check my progress to verify the objective. List and delete agents.

Congratulations!

In this lab, you’ve learned:

  • Benefits of deploying agents, especially multi-agent systems, to Agent Engine
  • How to wrap an agent to deploy it to Agent Engine
  • How to test an agent locally before deploying
  • How to query an agent deployed to Agent Engine
  • How to list and delete agents

Next Steps

You can learn more about building agents with Agent Development Kit from other labs in this series:

  • Empower ADK agents with tools
  • Build multi-agent systems with ADK
  • Deploy ADK agents to Agent Engine

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 May 28, 2025

Lab Last Tested May 28, 2025

Copyright 2023 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.

Before you begin

  1. Labs create a Google Cloud project and resources for a fixed time
  2. Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
  3. On the top left of your screen, click Start lab to begin

This content is not currently available

We will notify you via email when it becomes available

Great!

We will contact you via email if it becomes available

One lab at a time

Confirm to end all existing labs and start this one

Use private browsing to run the lab

Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.