Skip to main content

Lab 35: Container-Based Deployment of support-ops-agent to Agent Runtime

Goalโ€‹

In this hands-on Part 7 lab, you will prepare, validate, and deploy our canonical stateful Python support-ops-agent (gemini-3.8-flash) to Google Cloud's Agent Runtime using google-agents-cli โ€” completing the "one production container across Cloud Run, GKE, and Agent Runtime" deployment arc and generating deployment_metadata.json for zero-flag Gemini Enterprise publishing in Module 36.

To ensure every learner can complete this lab whether running against a live Google Cloud project (Track A) or in a local/offline training environment (Track B), Steps 1 & 2 validate the complete Agent Runtime container bundle locally before Step 3's cloud rollout!

Environment setup:

  • 1-Click Launch (Browser): Open in GitHub CodespacesOpen in Google Cloud Shell
  • Local machine: If you're continuing the course in sequence, cd into the adk-training project you created in Module 2 and skip the block below -- your environment and dependencies already carry forward. If you're starting fresh at this module, create that project first:
    uv init adk-training --python 3.10 && cd adk-training
    uv add "google-adk>=2.1.0" python-dotenv
  • DevContainer / Codespaces (Alternative): If you opened this repository in a DevContainer or GitHub Codespaces, Python 3.11, uv, gcloud, and all core ADK dependencies are pre-installed in your container environment.

Prerequisitesโ€‹

  • Python 3.10+, uv, and google-agents-cli (v1.10+) installed (uv tool install google-agents-cli).
  • For Track A (Live Google Cloud Rollout): A Google Cloud Project with billing enabled, gcloud auth application-default login, and the Agent Runtime APIs enabled:
    export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
    export DEPLOY_REGION="us-central1"
    gcloud config set project "$GOOGLE_CLOUD_PROJECT"

    gcloud services enable \
    aiplatform.googleapis.com \
    cloudbuild.googleapis.com \
    artifactregistry.googleapis.com \
    secretmanager.googleapis.com \
    cloudresourcemanager.googleapis.com \
    --project="$GOOGLE_CLOUD_PROJECT"

Step 1: Reuse (or Fast-Bootstrap) & Enhance support-ops-agent for Agent Runtimeโ€‹

  1. Navigate into support-ops-agent/ (or fast-bootstrap it in 10 seconds if starting fresh โ€” never mkdir before agents-cli create):

    cd /path/to/your/adk-training

    # Only if support-ops-agent/ does not exist yet:
    agents-cli create support-ops-agent \
    --agent adk \
    --prototype \
    --agent-guidance-filename GEMINI.md \
    --skip-checks -y

    curl -fsSL https://mauripsale.github.io/doc-adk-training/samples/part6/agent.py \
    -o support-ops-agent/app/agent.py

    cd support-ops-agent
  2. Enhance support-ops-agent in place for agent_runtime with Agent Identity & Agent Gateway readiness:

    Critical Rule โ€” Managed Sessions on Agent Runtime: Do not pass --session-type! At cloud runtime, Agent Runtime injects GOOGLE_CLOUD_AGENT_ENGINE_ID and app/app_utils/services.py automatically upgrades shared://session to VertexAiSessionService.

    # TODO: Run `agents-cli scaffold enhance .` with:
    # --deployment-target agent_runtime
    # --agent-runtime-identity-default agent_identity
    # --agent-gateway
    # --cicd-runner github_actions
    # --region us-central1
    # --skip-checks -y
    # Then sync dependencies with `agents-cli install`.

Step 2: Implement the Agent Runtime Container & Metadata Verifier (scripts/verify_agent_runtime_bundle.py)โ€‹

Before launching a 5โ€“10 minute remote container build on Agent Runtime, production CI pipelines verify four invariants:

  1. agents-cli-manifest.yaml targets agent_runtime, uses agent_directory: "app", and does not set a conflicting cloud_sql session override.
  2. app/fast_api_app.py gates otel_to_cloud on GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY and mounts both attach_a2a_routes and attach_reasoning_engine_routes.
  3. app/app_utils/services.py keeps SESSION_SERVICE_URI = "shared://session" at module import time while services.get_session_service() dynamically upgrades from InMemorySessionService locally to VertexAiSessionService when GOOGLE_CLOUD_AGENT_ENGINE_ID is injected in the runtime environment.
  4. deployment_metadata.json matches the exact schema expected by Module 36's agents-cli publish gemini.

Create scripts/verify_agent_runtime_bundle.py inside support-ops-agent/ and complete # TODO 1 through # TODO 3:

"""
Verifies the container-based Agent Runtime bundle for `support-ops-agent`
and validates dynamic `GOOGLE_CLOUD_AGENT_ENGINE_ID` session-URI promotion.
"""

import importlib
import json
import os
from pathlib import Path
import sys
import yaml

PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))


def verify_scaffold_files(root: Path) -> list[str]:
errors: list[str] = []
manifest = yaml.safe_load((root / "agents-cli-manifest.yaml").read_text(encoding="utf-8"))
create_params = manifest.get("create_params") or {}
fastapi_src = (root / "app" / "fast_api_app.py").read_text(encoding="utf-8")
dockerfile_src = (root / "Dockerfile").read_text(encoding="utf-8")

# TODO 1: Validate `manifest` (`create_params`) and `dockerfile_src`:
# - `create_params.get("deployment_target")` MUST equal `"agent_runtime"`
# - `manifest.get("agent_directory")` MUST equal `"app"`
# - `create_params.get("session_type")` MUST NOT equal `"cloud_sql"`
# - `"AGENT_GATEWAY_ROOT_CERTIFICATES"` MUST appear in `dockerfile_src`

# TODO 2: Validate `app/fast_api_app.py` dual-protocol & telemetry wiring:
# - Confirm `"GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY"` is in `fastapi_src`
# - Confirm `"attach_a2a_routes"` AND `"attach_reasoning_engine_routes"` are in `fastapi_src`

return errors


def verify_dynamic_session_upgrade() -> list[str]:
"""Simulates Agent Runtime injecting GOOGLE_CLOUD_AGENT_ENGINE_ID at startup."""
errors: list[str] = []
saved = {
k: os.environ.get(k)
for k in (
"GOOGLE_CLOUD_AGENT_ENGINE_ID",
"GOOGLE_CLOUD_PROJECT",
"GOOGLE_CLOUD_AGENT_ENGINE_LOCATION",
"SESSION_SERVICE_URI",
)
}
try:
for k in saved:
os.environ.pop(k, None)
import app.app_utils.services as services

services.get_session_service.cache_clear()
local_svc = services.get_session_service()

# TODO 3: Simulate Agent Runtime environment injection:
# - Set `os.environ["GOOGLE_CLOUD_AGENT_ENGINE_ID"] = "9876543210"`
# - Set `os.environ["GOOGLE_CLOUD_PROJECT"] = "demo-project"`
# - Set `os.environ["GOOGLE_CLOUD_AGENT_ENGINE_LOCATION"] = "us-central1"`
# - Clear the cache (`services.get_session_service.cache_clear()`) and call `cloud_svc = services.get_session_service()`.
# Verify that:
# - `type(local_svc).__name__ == "InMemorySessionService"`
# - `type(cloud_svc).__name__ == "VertexAiSessionService"`
# Append descriptive error strings to `errors` if either check fails.

finally:
for k, v in saved.items():
if v is None:
os.environ.pop(k, None)
else:
os.environ[k] = v
return errors


def ensure_sample_metadata_if_offline(root: Path) -> None:
"""Writes a valid sample deployment_metadata.json only if Track B (offline) has none yet."""
meta_path = root / "deployment_metadata.json"
if not meta_path.exists():
sample = {
"remote_agent_runtime_id": "projects/demo-project/locations/us-central1/reasoningEngines/9876543210",
"deployment_target": "agent_runtime",
"is_a2a": True,
"agent_directory": "app",
"deployment_timestamp": "2026-12-01T12:00:00+00:00",
}
meta_path.write_text(json.dumps(sample, indent=2) + "\n", encoding="utf-8")
print("โ„น๏ธ Wrote offline preview `deployment_metadata.json` for Module 36 handoff.")


def main() -> int:
errors = verify_scaffold_files(PROJECT_ROOT) + verify_dynamic_session_upgrade()
if errors:
print("โŒ Agent Runtime Bundle Verification FAILED:")
for e in errors:
print(f" - {e}")
return 1

ensure_sample_metadata_if_offline(PROJECT_ROOT)
print("โœ… Agent Runtime Bundle & Dynamic Session Promotion Verified!")
return 0


if __name__ == "__main__":
sys.exit(main())

Run your verifier:

uv run python scripts/verify_agent_runtime_bundle.py

Step 3: Deploy & Smoke-Test on Agent Runtime (Track A: Live GCP | Track B: --dry-run Preview)โ€‹

Track A โ€” Live Google Cloud Deployment (--no-wait + --status + Dual-Mode Invocation)โ€‹

  1. Start the non-blocking container rollout (separating --region us-central1 for the Agent Runtime control plane from GOOGLE_CLOUD_LOCATION=global for gemini-3.8-flash inference, with --agent-identity enabled):

    # Remove any offline sample deployment_metadata.json before real deploy
    rm -f deployment_metadata.json

    agents-cli deploy \
    --project "$GOOGLE_CLOUD_PROJECT" \
    --region "$DEPLOY_REGION" \
    --agent-identity \
    --env-vars "GOOGLE_GENAI_USE_ENTERPRISE=1,GOOGLE_CLOUD_LOCATION=global" \
    --no-confirm-project \
    --no-wait

    # Poll every ~60s until completion (writes real deployment_metadata.json when done!)
    agents-cli deploy --status

    # List active Agent Runtime instances in your project/region
    agents-cli deploy --list --project "$GOOGLE_CLOUD_PROJECT" --region "$DEPLOY_REGION"

    (Enterprise Perimeter Note: In regulated environments, you can also append --agent-gateway-egress projects/PROJECT/locations/REGION/agentGateways/GATEWAY, --network-attachment ..., or --key projects/KEY_PROJECT/locations/REGION/keyRings/RING/cryptoKeys/KEY on initial creation.)

  2. Invoke the live managed Agent Runtime over BOTH adk (:streamQuery) and a2a (/api passthrough):

    export AGENT_RUNTIME_ID=$(python3 -c 'import json; print(json.load(open("deployment_metadata.json"))["remote_agent_runtime_id"])')
    export AGENT_RUNTIME_URL="https://${DEPLOY_REGION}-aiplatform.googleapis.com/v1/${AGENT_RUNTIME_ID}"

    # TODO 4: Run `agents-cli run` against `--url "$AGENT_RUNTIME_URL"` in `--mode adk`:
    # Prompt: "Investigate ticket TCK-1042 and escalate if P1."

    # TODO 5: Run `agents-cli run` against `--url "$AGENT_RUNTIME_URL"` in `--mode a2a`:
    # Prompt: "Check ticket TCK-2088 and summarize its SLA response target."

Track B โ€” Offline / No-Billing Pre-Flight Verificationโ€‹

If you do not have a live billing-enabled GCP project today, preview the non-destructive rollout command via --dry-run, verify your local smoke test via agents-cli run, and confirm that deployment_metadata.json generated in Step 2 contains "deployment_target": "agent_runtime" and "agent_directory": "app" ready for Module 36:

agents-cli deploy --dry-run \
--deployment-target agent_runtime \
--project demo-support-ops \
--region us-central1 \
--agent-identity

Self-Reflection Questionsโ€‹

  • Why did agents-cli standardize on container-based Agent Runtime builds (Dockerfile + uvicorn app.fast_api_app:app) instead of legacy cloudpickle Python SDK scripts?
  • Why must you omit or clear custom session_type overrides when enhancing support-ops-agent for --deployment-target agent_runtime?
  • How do agents-cli deploy --no-wait and agents-cli deploy --status protect developer shells and CI jobs against 5โ€“10 minute container build timeouts, and what file does --status write upon completion?

๐Ÿ” Reference Solution Vaultโ€‹

๐Ÿงช

35: Deploying to Agent Runtime(Challenge Lab)

Part 7: Cloud Runtimes & Enterprise โ€ข Module 35