When you want to use services from Agent Platform with other runtimes (like GKE, and Cloud Run), you need to first create a resource identifier.
At the time of writing, the way to do this is actually to deploy a “dummy” or backend agent. This is an agent that basically does nothing, except provide us the identifiers that we can use for our actual agent deployments on other runtimes.
from google.adk.agents import Agent
# Minimal placeholder agent. Its only purpose is to be deployed to Agent
# Engine so that the deployment provides managed Sessions and a Memory Bank.
# The containerized trading agent connects to those services via
# SESSION_SERVICE_URI / MEMORY_SERVICE_URI (agentengine://<resource_id>).
root_agent = Agent(
name="session_backend",
model="gemini-2.0-flash",
instruction="You are a placeholder. You only exist to host managed Sessions and Memory. Whatever the user asks, just reply 'I am a placeholder'.",
)Code language: Python (python)
"""Deploy the minimal backend agent to Agent Engine.
This agent does nothing on its own — its purpose is to exist as an Agent
Engine resource that provides managed Sessions and a Memory Bank. The
containerized trading agent connects to those services via the printed
SESSION_SERVICE_URI / MEMORY_SERVICE_URI (agentengine://<resource_id>).
Run from the 04_Containerized directory:
python3 backend_deploy.py
"""
import json
import vertexai
from vertexai.agent_engines import AdkApp
from backend_agent.agent import root_agent
# Replace with your project ID, bucket name and preferred region.
PROJECT_ID = "your-project-id"
STAGING_BUCKET = "gs://your-bucket-name"
LOCATION = "us-west1"
if PROJECT_ID == "your-project-id":
raise ValueError("Set PROJECT_ID to your Google Cloud project ID in backend_deploy.py")
if STAGING_BUCKET == "gs://your-bucket-name":
raise ValueError("Set STAGING_BUCKET to your GCS bucket in backend_deploy.py")
vertexai.init(project=PROJECT_ID, location=LOCATION, staging_bucket=STAGING_BUCKET)
client = vertexai.Client(project=PROJECT_ID, location=LOCATION)
print("Deploying Sessions + Memory backend agent (this takes 5-10 minutes)...")
remote_agent = client.agent_engines.create(
agent=AdkApp(agent=root_agent),
config={
"staging_bucket": STAGING_BUCKET,
"display_name": "Trading Agent Sessions+Memory Backend",
"description": "Minimal agent providing managed Sessions and Memory services.",
"requirements": "backend_agent/requirements.txt",
"extra_packages": ["backend_agent"],
"env_vars": {
"GOOGLE_GENAI_USE_VERTEXAI": "TRUE",
},
},
)
resource_name = remote_agent.api_resource.name
print()
print("Deployment complete!")
print(f"Resource name: {resource_name}")
print()
print("Add these to your docker-env (or deploy env):")
print(f"SESSION_SERVICE_URI=agentengine://{resource_name}")
print(f"MEMORY_SERVICE_URI=agentengine://{resource_name}")Code language: Python (python)
Clone the repo to get this code.
git clone https://github.com/WilliamDenniss/agent-examples.git
cd 04_AgentPlatformBackendCode language: PHP (php)
Create and source the python environment
python3 -m venv agent-env
source agent-env/bin/activate
pip install -r backend_agent/requirements.txt
and deploy the placeholder agent
python deploy_backend.pyCode language: CSS (css)
Make a note of the resource URI (printed as SESSION_SERVICE_URI and MEMORY_SERVICE_URI), these will be needed later to utilize the backend.