Step-by-Step Guide to Deploy ADK Agents to Agent Engine
Prerequisites
- Google Cloud account
- Python 3.9
- Basic understanding of Python programming
And provide the Vertex AI User role Service Account.
- Navigate to IAM in the console.
- Click the checkbox to Include Google-provided role grants.
- 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. - Click Add another role.
- Select Vertex AI User.
Create Project Structure
├Dir -->adk_to_agent_engine
── requirements.txt
└── transcript_summarization_agent
├── agent_engine_utils.py
├── agent.py
├── deploy_to_agent_engine.py
├── __init__.py
├── __pycache__
│ └── agent.cpython-312.pyc
├── query_app_on_agent_engine.py
└── test_agent_app_locally.py
2. .env File
GOOGLE_GENAI_USE_VERTEXAI=1
GOOGLE_CLOUD_PROJECT=your-project-id
GOOGLE_CLOUD_LOCATION=us-central1
MODEL=gemini-2.0-flash-exp
APP_NAME="Transcript Summarizer"
3. Requirements.txt
fire==0.7.0
google-cloud-aiplatform[adk,agent_engines]==1.88.0
4. Agent.py
import os
from dotenv import load_dotenv
from google.adk import Agent
load_dotenv()
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.",
)
5. Test_agent_app_locally.py
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())
6. Deploy_to_agent_engine.py
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]"
]
)
7. Query_app_on_agent_engine.py
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()
Execution Steps:
Install ADK and Set Up Environment
# Add ADK to your PATH
export PATH=$PATH:"/home/${USER}/.local/bin"
# Install the Google ADK package
python3 -m pip install google-adk==1.1.1
# Install required dependencies
python3 -m pip install -r requirements.txt
Test locally
python3 transcript_summarization_agent/test_agent_app_locally.py
Deploy to Agent Engine
python3 transcript_summarization_agent/deploy_to_agent_engine.py
Query the deployed agent
python3 transcript_summarization_agent/query_app_on_agent_engine.py
List and delete agents deployed to Agent Engine
8. Agent_engine_utils.py
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()
python3 agent_engine_utils.py list
python3 agent_engine_utils.py delete RESOURCE_ID_FROM_PREVIOUS_OUTPUT
About Me
As the world increasingly adopts cloud-based solutions, I bring over 16 years of industry expertise to help businesses transition seamlessly to the cloud. Currently serving as a Google Cloud Principal Architect, I specialize in building highly scalable, secure, and efficient solutions on the Google Cloud Platform (GCP). My areas of expertise include cloud infrastructure design, zero-trust security, Google Cloud networking, and infrastructure automation using Terraform.
I am proud to hold multiple cloud certifications that Google Cloud, HashiCorp Terraform, Microsoft Azure, and Amazon AWS, reflecting my commitment to continuous learning and multi-cloud proficiency.
Multi-Cloud Certified
- Google Cloud Certified — Cloud Digital Leader
- Google Cloud Certified — Associate Cloud Engineer
- Google Cloud Certified — Professional Cloud Architect
- Google Cloud Certified — Professional Data Engineer
- Google Cloud Certified — Professional Cloud Network Engineer
- Google Cloud Certified — Professional Cloud Developer Engineer
- Google Cloud Certified — Professional Cloud DevOps Engineer
- Google Cloud Certified — Professional Security Engineer
- Google Cloud Certified — Professional Database Engineer
- Google Cloud Certified — Professional Workspace Administrator
- Google Cloud Certified — Professional Machine Learning Engineer
- HashiCorp Certified — Terraform Associate
- Microsoft Azure AZ-900 Certified
- Amazon AWS Certified Practitioner
Empowering Others
Beyond my professional work, I am passionate about helping professionals and students build successful careers in the cloud. Through my content and mentorship, I aim to demystify complex cloud technologies, making them accessible and practical for all skill levels. My areas of guidance include Google Cloud, AWS, Microsoft Azure, and Terraform.
I regularly share insights, tutorials, and resources on various platforms. Whether you’re preparing for a certification exam, exploring cloud architecture, or tackling DevOps challenges, my goal is to provide clear, actionable content that supports your learning journey.
Connect With Me
Stay updated with the latest in cloud computing by following me on these platforms:
- YouTube: Grow with Google Cloud
- Topmate: Consult with Me
- Medium: My Blogs
- Telegram: Community Channel
- Twitter: Follow Me
- Instagram: Connect on Instagram
- LinkedIn: Professional Profile
- GitHub: My Projects
- Facebook: Follow on Facebook
- Linktree: All Resources
I’m here to help — together, we can achieve great heights in the cloud.
Let’s connect and grow! 😊
#aiagent #adk #gcp #agentengine