Deploying to Agent Platform with ADK

2 min read

In my previous post, we created an agent with ADK and ran it locally. The next step to deploy it to Agent Platform runtime.

Create this script in the root project folder (the one containing trading_agent from the previous example), and set PROJECT_ID with your project name, and set STAGING_BUCKET to either an existing bucket, or any value that isn’t taken (try something like yourname-agent-test) and one will be created.

This is a simple python script to call the deployment API with your desired configuration. It’s not actually part of your agent python code, which is why I recommend keeping it in the parent directory. I used Gemini CLI to generate it for me, with a prompt like “deploy my agent to Agent Platform”. The key to get the coding agent to work is to be in the right directory, and source the env so it has everything it needs.

import os
import vertexai
from dotenv import load_dotenv
from trading_agent.agent import app

load_dotenv('trading_agent/.env')

PROJECT_ID = "your-project"
STAGING_BUCKET = "gs://your-bucket"
LOCATION = "us-west1"

vertexai.init(project=PROJECT_ID, location=LOCATION, staging_bucket=STAGING_BUCKET)

print("Deploying ADK Trading Agent...")
client = vertexai.Client(project=PROJECT_ID, location=LOCATION)
remote_agent = client.agent_engines.create(
    agent=app,
    config={
        "staging_bucket": STAGING_BUCKET,
        "display_name": "Trading Agent",
        "description": "An ADK agent that analyzes financial news and makes paper trades on Alpaca.",
        "requirements": "trading_agent/requirements.txt",
        "extra_packages": ["trading_agent/agent.py"],
        "env_vars": {
            "APCA_API_KEY_ID": os.getenv("APCA_API_KEY_ID", ""),
            "APCA_API_SECRET_KEY": os.getenv("APCA_API_SECRET_KEY", ""),
            "GOOGLE_GENAI_USE_VERTEXAI": "TRUE",
        },
    },
)

print()
print("Deployment complete!")
print(f"Resource name: {remote_agent.api_resource.name}")
Code language: Python (python)

One important thing to note is that when you want to call Gemini APIs from your project, set GOOGLE_GENAI_USE_VERTEXAI to TRUE, and do NOT pass in GOOGLE_API_KEY. The GOOGLE_API_KEY is long-lived bearer token designed for development use. In production, Google Cloud can use the agent’s identity (service account) to call Gemini, and the auth is handled automatically. For Alpaca, since this is just a paper trading account, I’m configuring the secrets a env vars. For a more robust setup, you would use secrets manager to avoid having the secrets in the configuration.

To deploy, from the project folder, source our environment and run the deploy python.

source trading-env/bin/activate
python deploy.py