Build and deploy an AI agent to Cloud Run using the Agent Development Kit (ADK) Stay organized with collections Save and categorize content based on your preferences.
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
- Write the sample application to define the weather-agent.
- Deploy the agent to Cloud Run from source.
- Run your agent to query weather information.
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.
Before you begin
- 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.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
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.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.createpermission.Learn how to grant roles.
Verify that billing is enabled for your Google Cloud project.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
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.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.createpermission.Learn how to grant roles.
Verify that billing is enabled for your Google Cloud project.
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.enablepermission.Learn how to grant roles.- Set up your Cloud Run development environmentin your Google Cloud project.
- Install ADK by following the instructions in theAgent Development Kit documentation.
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:
- Cloud Run Source Developer (
roles/run.sourceDeveloper) on the project - Vertex AI User (
roles/aiplatform.user) on the project - Service Account User (
roles/iam.serviceAccountUser) on the service identity - Logs Viewer (
roles/logging.viewer) on the project
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:
Create a new parent directory named
parent_folderand change directory into it:mkdirparent_foldercdparent_folderIn the
parent_folderdirectory, create a new subdirectory namedmulti_tool_agentand change directory into it:mkdirmulti_tool_agentcdmulti_tool_agentCreate an
__init__.pyfile to import the agent:from.importagentCreate an
agent.pyfile 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],)Create a
.envfile and add the following variables:GOOGLE_GENAI_USE_VERTEXAI=TRUEGOOGLE_CLOUD_PROJECT=PROJECT_IDGOOGLE_CLOUD_LOCATION=REGIONReplace the following:
- PROJECT_ID: the Google Cloud project ID.
- REGION: the region you plan to deploy your service in.
Navigate to the parent folder directory
parent_folder, and create arequirements.txtfileto add thegoogle-adkdependency:google-adkYour 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.
In your source code directory (
parent_folder), deploy to Cloud Run using thefollowing command:gcloudrundeploy--source.
When you are prompted for the service name, press Enter to accept thedefault name, for example
weather-agent.If you are prompted to enable additional APIs on the project,for example, the Artifact Registry API, respond by pressing
y.When you are prompted for region: select theregionof your choice, for example
europe-west1.If you are prompted to create a repository in the specified region, respond by pressing
y.If you are prompted toallow public access:respond
y. 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-appsfrom 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:
To get the list of apps, run the following command:
curl -X GETSERVICE_URL/list-appsReplaceSERVICE_URL with the URL of your deployed service.
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}'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:
Delete tutorial resources
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.
Remove the
gclouddefault region configuration you added during tutorialsetup:gcloudconfigunsetrun/regionRemove 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.