Deploy an ADK agent to Agent Platform Runtime
Copy as MarkdownIn my previous post, we created an agent with ADK and ran it locally. The next step is to deploy it to Agent Platform runtime.
ADK deployments are typically deployed using a small Python script to configure the required properties.
Create the following 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.
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}")
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.
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, when using venv, source our environment (if not already done):
source trading-env/bin/activate
and run the deploy python:
python deploy.py
Interacting with the agent
With the agent deployed, we can interact with it in the Playground by creating a new session and chatting “trade”.

Command line sessions
To run a session via HTTP, you can use a script like this. Replace RESOURCE_NAME with the resource name you can copy from the Deployments tab, and update BASE_URL to point to your region. This runs a query, authenticated as the logged-in user.
#!/bin/bash
set -e
RESOURCE_NAME="projects/213543088169/locations/us-west1/reasoningEngines/4084914395606417408"
BASE_URL="https://us-west1-aiplatform.googleapis.com/v1/${RESOURCE_NAME}"
USER_ID="test-user"
MESSAGE="${1:-Run the trading cycle.}"
TOKEN=$(gcloud auth print-access-token)
echo "Creating session..."
SESSION_RESPONSE=$(curl -s -X POST \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
"${BASE_URL}:query" \
-d "{\"classMethod\":\"create_session\",\"input\":{\"user_id\":\"${USER_ID}\"}}")
SESSION_ID=$(echo "${SESSION_RESPONSE}" | jq -r '.output.id')
echo "Session created: ${SESSION_ID}"
echo "Sending query: ${MESSAGE}"
curl -s -X POST \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
"${BASE_URL}:streamQuery" \
-d "{\"classMethod\":\"stream_query\",\"input\":{\"user_id\":\"${USER_ID}\",\"session_id\":\"${SESSION_ID}\",\"message\":\"${MESSAGE}\"}}" \
| jq -rj 'select(.content.parts) | .content.parts[] | select(.text) | .text'
echo