Build and deploy an AI agent to Cloud Run using the Agent Development Kit (ADK)

TheAgent Development Kit (ADK)framework simplifies the creation, evaluation, and deployment of AI agents.ADK provides a modular, code-first approach to building agents that can reason,plan, and utilize tools.

This tutorial shows you how to build and deploy an AIagent to Cloud Run using ADK forPython. This agent retrieves the weather report for a city you specify.

For more information about hosting your ADK agent using the Google Cloud CLI, seeDeploy to Cloud Runin ADK documentation.

Objectives

Costs

In this document, you use the following billable components of Google Cloud:

To generate a cost estimate based on your projected usage, use thepricing calculator.

New Google Cloud users might be eligible for afree trial.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  5. Verify that billing is enabled for your Google Cloud project.

  6. Enable the Cloud Run Admin API, Vertex AI API, and Cloud Build APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.

    Enable the APIs

  7. Set up your Cloud Run development environmentin your Google Cloud project.
  8. Install ADK by following the instructions in theAgent Development Kit documentation.
  9. If you are under a domain restriction organization policyrestricting unauthenticated invocations for your project, you will need to access your deployed service as described underTesting private services.

Required roles

To get the permissions that you need to deploy an AI agent to Cloud Run, ask your administrator to grant you the following IAM roles:

For more information about granting roles, seeManage access to projects, folders, and organizations.

You might also be able to get the required permissions throughcustom roles or otherpredefined roles.

Write the sample application

To write an application in Python:

  1. Create a new parent directory namedparent_folder and change directory into it:

    mkdirparent_foldercdparent_folder
  2. In theparent_folder directory, create a new subdirectory namedmulti_tool_agentand change directory into it:

    mkdirmulti_tool_agentcdmulti_tool_agent
  3. Create an__init__.py file to import the agent:

    from.importagent
  4. Create anagent.py file to define the agent for answering questionsabout the time and weather in a specified city:

    importdatetimefromzoneinfoimportZoneInfofromgoogle.adk.agentsimportAgentdefget_weather(city:str)->dict:"""Retrieves the current weather report for a specified city.    Args:        city (str): The name of the city for which to retrieve the weather report.    Returns:        dict: status and result or error msg.    """ifcity.lower()=="new york":return{"status":"success","report":("The weather in New York is sunny with a temperature of 25 degrees"" Celsius (77 degrees Fahrenheit)."),}else:return{"status":"error","error_message":f"Weather information for '{city}' is not available.",}defget_current_time(city:str)->dict:"""Returns the current time in a specified city.    Args:        city (str): The name of the city for which to retrieve the current time.    Returns:        dict: status and result or error msg.    """ifcity.lower()=="new york":tz_identifier="America/New_York"else:return{"status":"error","error_message":(f"Sorry, I don't have timezone information for{city}."),}tz=ZoneInfo(tz_identifier)now=datetime.datetime.now(tz)report=(f'The current time in{city} is{now.strftime("%Y-%m-%d %H:%M:%S %Z%z")}')return{"status":"success","report":report}root_agent=Agent(name="weather_time_agent",model="gemini-2.0-flash",description=("Agent to answer questions about the time and weather in a city."),instruction=("You are a helpful agent who can answer user questions about the time and weather in a city."),tools=[get_weather,get_current_time],)
  5. Create a.env file and add the following variables:

    GOOGLE_GENAI_USE_VERTEXAI=TRUEGOOGLE_CLOUD_PROJECT=PROJECT_IDGOOGLE_CLOUD_LOCATION=REGION

    Replace the following:

    • PROJECT_ID: the Google Cloud project ID.
    • REGION: the region you plan to deploy your service in.
  6. Navigate to the parent folder directoryparent_folder, and create arequirements.txt fileto add thegoogle-adk dependency:

    google-adk

    Your source project includes the following structure:

    parent_folder/├── requirements.txt└── multi_tool_agent/    ├── __init__.py    ├── agent.py    └── .env

Your app is finished and ready to be deployed.

Deploy to Cloud Run from source

Deploy from source automatically builds a container image from source codeand deploys it.

  1. In your source code directory (parent_folder), deploy to Cloud Run using thefollowing command:

    gcloudrundeploy--source.
    1. When you are prompted for the service name, press Enter to accept thedefault name, for exampleweather-agent.

    2. If you are prompted to enable additional APIs on the project,for example, the Artifact Registry API, respond by pressingy.

    3. When you are prompted for region: select theregionof your choice, for exampleeurope-west1.

    4. If you are prompted to create a repository in the specified region, respond by pressingy.

    5. If you are prompted toallow public access:respondy. You might not see this prompt if there is a domainrestriction organization policy that prevents it; for more details see theBefore you begin section.

    Then wait a few moments until the deployment is complete. On success, thecommand line displays the service URL. Navigate to/list-apps from your service URL. For example,https://weather-agent-123456789101.us-central1.run.app/list-apps.

Run your agent

To query the ADK agent, run the following curl commands:

  1. To get the list of apps, run the following command:

    curl -X GETSERVICE_URL/list-apps

    ReplaceSERVICE_URL with the URL of your deployed service.

  2. To start a session, run the following command:

    curl -X POSTSERVICE_URL/apps/multi_tool_agent/users/u_123/sessions/s_123 -H "Content-Type: application/json" -d '{"key1": "value1", "key2": 42}'
  3. To query the agent, run the following command:

    curl -X POSTSERVICE_URL/run \-H "Content-Type: application/json" \-d "{\"appName\": \"multi_tool_agent\",\"userId\": \"u_123\",\"sessionId\": \"s_123\",\"newMessage\": { \"role\": \"user\", \"parts\": [{ \"text\": \"What's the weather in New York today?\" }]}}"

The agent returns the weather information in the results of your query.

For more information and examples about the supported curl commands, seeUse the API Server in ADK documentation.

Success: You deployed an AI agent using the Agent Development Kit to Cloud Run.

Clean up

To avoid additional charges to your Google Cloud account, delete all the resourcesyou deployed with this tutorial.

Delete the project

If you created a new project for this tutorial, delete the project.If you used an existing project and need to keep it without the changes you addedin this tutorial,delete resources that you created for the tutorial.

The easiest way to eliminate billing is to delete the project that you created for the tutorial.

To delete the project:

    Caution: Deleting a project has the following effects:
    • Everything in the project is deleted. If you used an existing project for the tasks in this document, when you delete it, you also delete any other work you've done in the project.
    • Custom project IDs are lost. When you created this project, you might have created a custom project ID that you want to use in the future. To preserve the URLs that use the project ID, such as anappspot.com URL, delete selected resources inside the project instead of deleting the whole project.

    If you plan to explore multiple architectures, tutorials, or quickstarts, reusing projects can help you avoid exceeding project quota limits.

  1. In the Google Cloud console, go to theManage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then clickDelete.
  3. In the dialog, type the project ID, and then clickShut down to delete the project.

Delete tutorial resources

  1. Delete the Cloud Run service you deployed in this tutorial.Cloud Run services don't incur costs until they receive requests.

    To delete your Cloud Run service, run the following command:

    gcloudrunservicesdeleteSERVICE-NAME

    ReplaceSERVICE-NAME with the name of your service.

    You can also delete Cloud Run services from theGoogle Cloud console.

  2. Remove thegcloud default region configuration you added during tutorialsetup:

    gcloudconfigunsetrun/region
  3. Remove the project configuration:

     gcloud config unset project

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-18 UTC.