This guide details the technical implementation of Agent Development Kit (ADK) agents on Google Cloud Run, structured for a multi-environment enterprise lifecycle.
Source code is available at: Github Repo Dev-Signal with Google ADK and Python code
e-Commerce
Qualification of Deals, Offers, and Products — evaluating customer or account profiles to determine eligibility for specific offerings. Examples include:
- Healthcare: Determining which high-tier medical plans a customer qualifies for based on their demographic profile, existing coverage, and regulatory requirements.
- Automotive/Machinery: Qualifying a B2B account for specialized financing or fleet discounts based on purchase history and creditworthiness when buying cars or heavy machinery.
Traditional rule-based systems often fail when the qualification criteria are highly dynamic or involve unstructured data. An agentic solution is required when:
- Contextual complexity: The decision depends on reasoning across disparate data points (for example a customer’s recent support interactions, current market trends, and complex policy documents).
- Dynamic decisioning: Business rules change frequently (seasonal offers, shifting inventory levels), making hard-coded logic difficult to maintain.
- Multi-step reasoning: The process requires thought — first qualifying the profile, then calculating the discount, and finally verifying order feasibility — before committing to a transaction.
- Scalability of logic: You need to scale the intelligence of the system across multiple product lines (healthcare vs. machinery) without rebuilding the core engine.
The approach leverages a multi-agent architecture built on the Google ADK framework and hosted on Google Cloud Run.
- Reasoning layer: A specialized Qualification Agent uses Gemini models via Vertex AI to reason through customer profiles.
- Execution layer: A dedicated Order Agent handles transactional tool-calling to ERP or CRM systems.
- Delivery layer: Serverless, server-side infrastructure using Cloud Run that supports high availability and regional failover.
Before triggering a CI/CD pipeline, the agent must adhere to ADK’s entry-point requirements so the container builds correctly.
- Project structure (Python): The directory must contain
agent.py, an__init__.py(containingfrom . import agent), and arequirements.txt. - Naming convention: The main agent instance must be named
root_agent. - Local testing: Use
adk run --with_uito test the reasoning chain. Validate that offer qualification correctly identifies discount eligibility before the order-creation tool is invoked. - Mocking: Use environment variables to toggle between local mock APIs and integration-level order APIs.
Automation ensures that every deployment to Dev, QA, Staging, and Prod is identical and traceable.
- Workload Identity Federation (WIF): In GitHub Actions or GitLab CI, use WIF for keyless authentication to GCP. Avoid long-lived JSON service account keys.
- Build once, deploy many: Build the container image during the
developmerge. Tag it with the Git SHA and push to Artifact Registry. Use this specific image digest across all subsequent environments (QA, Staging, Prod). - Evaluation gate: Integrate an automated testing step using ADK’s evaluation framework to measure reasoning accuracy for offer qualification before promoting the build to Staging.
The deployment command must be parameterized for each environment within your pipeline.
adk deploy cloud_run \
--project=$GCP_PROJECT_ID \
--region=$GCP_REGION \
--service_name="commerce-agent-${ENV}" \
--session_service_uri="${DB_CONNECTION_STRING}" \
--port=8080 \
--with_ui # Enabled ONLY for DEV and QA environments
State persistence: Cloud Run instances are stateless. For commerce workflows, you must use --session_service_uri to point to a persistent store (for example postgresql:// via Cloud SQL). This prevents memory loss when the agent scales down or an instance restarts mid-transaction.
Port mapping: Cloud Run listens on port 8080. The adk deploy tool handles the internal mapping from the ADK default (8000), but manually verifying the PORT environment variable in your agent code is best practice.
The principle of least privilege is vital for an agent that can trigger financial transactions (order creation).
- Agent identity: Create a unique service account for each environment (for example
agent-prod@...). - Vertex AI User (
roles/aiplatform.user): Grants the agent permission to use Gemini models for offer reasoning. - Secret Accessor (
roles/secretmanager.secretAccessor): Grants access to specific secrets (API keys for ERP/order systems) stored in Secret Manager. - Resource binding: Apply these roles at the resource level (specific secrets/models) rather than the project level where possible.
For mission-critical eCommerce, a single regional deployment is a point of failure.
- Regional redundancy: Deploy the agent to an active region (for example
us-central1) and a passive region (for exampleus-east1). - Global load balancing: Use a Global External HTTP(S) Load Balancer with a single frontend IP.
- Health checks: Configure the load balancer to probe the
/healthendpoint of the ADK API. If the active region fails, traffic is automatically rerouted to the passive region. - Database sync: Ensure the underlying Cloud SQL (session store) uses cross-region replication to keep the passive agent warm with current session data.
AI agents have unique performance profiles that differ from standard web apps.
- Startup CPU Boost: Enable this in Cloud Run to reduce cold-start latency. AI libraries (like Pydantic and the Vertex SDK) are heavy and benefit from extra CPU during initialization.
- Min instances: For Production and Pre-Prod, set
min-instancesto at least 1. This ensures order-creation logic stays responsive. - Environment variables: Explicitly set
GOOGLE_CLOUD_PROJECT,GOOGLE_CLOUD_LOCATION, andGOOGLE_GENAI_USE_ENTERPRISE=Truein the Cloud Run service configuration so the Vertex AI SDK resolves correctly in a serverless environment.
- Structure:
agent.pycontainsroot_agent;__init__.pyis present. - CI/CD: WIF configured; build-once / deploy-many digest used.
- State: Persistent
session_service_uripoints to Cloud SQL. - IAM: Dedicated service account with
aiplatform.userrole. - Failover: Global Load Balancer configured for active/passive routing.
- Performance: Startup CPU Boost and min-instances enabled in Prod.