Patterns
AI & Agent Platform
Cloud Infrastructure Google Cloud Platform DevOps & SRE Architecture

AI & Agent Platform

Comprehensive guide to AI agents, RAG architecture, and agent development on Google Cloud Platform

AI & Agent Platform

Google Cloud Platform provides enterprise-grade infrastructure and developer frameworks for building, deploying, evaluating, and managing autonomous AI agents and intelligent systems. This guide provides a deep-dive technical overview of Google Cloud’s AI agent ecosystem, correcting legacy syntax misconceptions, providing production-grade Python SDK workflows, official gcloud CLI operations, and enterprise architecture patterns. This guide covers everything from custom agent logic to declarative managed capabilities.


Google Cloud AI Agent Ecosystem Overview

Google Cloud structures AI agent development into two primary paradigms based on custom logic requirements versus declarative managed capabilities:

  1. Vertex AI Reasoning Engine (Custom Agent Logic): A fully managed, serverless Python runtime environment for custom agent reasoning loops (Perceive-Plan-Act-Observe), custom tools, state management, and orchestration via LangChain, LlamaIndex, or Google’s Agent Development Kit (ADK).
  2. Vertex AI Agent Builder & Discovery Engine (Declarative & Search): Enterprise-managed RAG, search, and conversational engines built on Google Search technology, managed via gcloud discoveryengine and gcloud dialogflow APIs.
  3. Google Agents CLI (google-agents-cli): Developer tool for local agent scaffolding, evaluation datasets, local testing, and multi-target deployment (Vertex AI Agent Runtime, Cloud Run, GKE).

Important CLI Correction: There is no gcloud ai agents command in Google Cloud SDK. AI agent lifecycle management on GCP is executed using gcloud discoveryengine for declarative chat/search engines, gcloud ai / vertexai Python SDK for Vertex AI Reasoning Engine, or agents-cli for developer workflows.

Prerequisites

Before working with AI agent platform on GCP, ensure you have:

  • A GCP project with appropriate permissions
  • Vertex AI API enabled
  • Basic understanding of AI/ML concepts
  • Python development environment setup
  • Familiarity with containerization concepts

1. Vertex AI Reasoning Engine

Vertex AI Reasoning Engine provides a managed runtime for hosting Python-based AI agents. It abstracts container management, serverless scaling, API generation, and token tracing.

Architecture & Capabilities

  • Serverless Execution: Deploys agent classes as managed REST/gRPC endpoints.
  • Tool Orchestration: Seamlessly binds Python functions, OpenAPI specs, and BigQuery/Spanner queries to Gemini models via Gemini Function Calling.
  • State & Memory Management: Persists execution context and multi-turn conversational history natively across calls.
  • Glass-Box Tracing: Integrates with Cloud Logging and OpenTelemetry to inspect step-by-step model thoughts, tool parameters, and raw model outputs.

Production Python SDK Implementation

The following example demonstrates building a multi-tool custom agent locally and deploying it to the Vertex AI Reasoning Engine managed runtime.

import os
import vertexai
from vertexai.preview import reasoning_engines
from vertexai.generative_models import GenerativeModel, Tool

# 1. Initialize Vertex AI Context
PROJECT_ID = "your-gcp-project-id"
LOCATION = "us-central1"
STAGING_BUCKET = "gs://your-agent-staging-bucket"

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

# 2. Define Custom Agent Tools
def lookup_customer_account(customer_id: str) -> dict:
    """Fetches customer account status and tier given a customer ID."""
    # In production, query Cloud Bigtable, Spanner, or external CRM API
    return {
        "customer_id": customer_id,
        "status": "Active",
        "tier": "Enterprise Premium",
        "open_tickets": 0
    }

def adjust_inventory_quota(sku: str, amount_delta: int) -> dict:
    """Adjusts warehouse inventory quota for a given SKU."""
    # Production logic connecting to inventory database
    return {
        "sku": sku,
        "status": "Updated",
        "new_capacity": 450 + amount_delta
    }

# 3. Define Custom Agent Class
class EnterpriseOperationsAgent:
    def __init__(self, model_name: str = "gemini-1.5-pro"):
        self.model_name = model_name

    def set_up(self):
        """Initialization method executed on container startup inside Reasoning Engine."""
        self.tools = [
            Tool.from_google_search_retrieval(),
            lookup_customer_account,
            adjust_inventory_quota
        ]
        self.model = GenerativeModel(
            model_name=self.model_name,
            tools=self.tools
        )

    def query(self, prompt: str) -> str:
        """Entrypoint method called when invoking remote_agent.query()."""
        chat = self.model.start_chat()
        response = chat.send_message(prompt)
        return response.text

# 4. Deploy Agent to Vertex AI Reasoning Engine Runtime
remote_agent = reasoning_engines.ReasoningEngine.create(
    EnterpriseOperationsAgent(model_name="gemini-1.5-pro"),
    requirements=[
        "google-cloud-aiplatform[reasoningengine,langchain]",
        "pydantic>=2.7.4",
        "requests>=2.31.0",
        "cloudpickle==3.0.0"
    ],
    display_name="enterprise-ops-agent",
    description="Managed agent handling operations and inventory lookups."
)

print(f"Agent successfully deployed! Resource Name: {remote_agent.resource_name}")

Querying the Deployed Remote Agent

Once deployed, the agent can be queried asynchronously or synchronously from any application using the Vertex AI SDK or REST API:

from vertexai.preview import reasoning_engines

# Connect to existing Reasoning Engine deployment
deployed_agent = reasoning_engines.ReasoningEngine(
    "projects/123456789/locations/us-central1/reasoningEngines/987654321"
)

# Execute agent prompt
response = deployed_agent.query(
    prompt="Check customer status for account CUST-8821 and adjust SKU-9941 stock up by 50 units."
)

print(response)

2. Declarative Agent Builder & Enterprise RAG via gcloud CLI

For search, document chat, and declarative knowledge systems, Google Cloud provides Vertex AI Agent Builder and Discovery Engine APIs.

Infrastructure Provisioning via gcloud

# Step 1: Enable required GCP services
gcloud services enable   discoveryengine.googleapis.com   aiplatform.googleapis.com   storage.googleapis.com

# Step 2: Create Cloud Storage bucket for document ingestion
gcloud storage buckets create gs://enterprise-kb-docs-prod   --location=us-central1   --uniform-bucket-level-access

# Step 3: Create Discovery Engine Data Store for unstructured RAG
gcloud discovery-engine data-stores create   --data-store-id="corporate-policy-ds"   --display-name="Corporate Policy Datastore"   --industry-vertical="GENERIC"   --solution-types="SOLUTION_TYPE_CHAT"   --location="global"

# Step 4: Create Conversational Search/Chat Engine
gcloud discovery-engine engines create   --engine-id="policy-chat-agent"   --display-name="Policy Advisor Agent"   --solution-type="SOLUTION_TYPE_CHAT"   --data-store-ids="corporate-policy-ds"   --location="global"

Grounding Gemini Models with Vertex AI Search Tools

In Python, connect Gemini models directly to the created Data Store using native SDK tools:

import vertexai
from vertexai.generative_models import GenerativeModel, Tool

vertexai.init(project="your-gcp-project-id", location="us-central1")

# Create Grounding Tool pointing to Vertex AI Search Data Store
grounding_tool = Tool.from_retrieval(
    grounding_connector=Tool.from_vertex_ai_search(
        project="your-gcp-project-id",
        location="global",
        data_store_id="corporate-policy-ds"
    )
)

# Instantiate Gemini 1.5 Pro with Grounding Tool
model = GenerativeModel("gemini-1.5-pro")

response = model.generate_content(
    "What is the company policy regarding remote work stipends and quarterly travel?",
    tools=[grounding_tool]
)

print("Response:", response.text)
# Inspect Grounding Metadata to verify citations and source facts
print("Grounding Metadata:", response.candidates[0].grounding_metadata)

3. Google Agents CLI (google-agents-cli) Workflow

For developers leveraging the Agent Development Kit (ADK), google-agents-cli streamlines local development, evaluation metrics, and container deployment.

# Setup Google Agents CLI environment
pip install google-agents-cli
agents-cli setup

# Create new agent project scaffold
agents-cli create --name="compliance-checker" --template="adk-python"

# Run local evaluation benchmark against ground-truth datasets
agents-cli eval --dataset="eval_dataset.json" --metrics="faithfulness,answer_relevance"

# Deploy agent to target runtime (Vertex AI Agent Runtime or Cloud Run)
agents-cli deploy --target="agent-runtime" --project="your-gcp-project-id" --region="us-central1"

4. Production RAG Architecture Patterns

Below is the enterprise production architecture pattern for low-latency RAG systems on Google Cloud Platform:

[ Data Ingestion Sources ]
  β”œβ”€β”€ PDF / Docs ─────> [ Cloud Storage (gs://) ]
  β”œβ”€β”€ DB Tables ──────> [ BigQuery / Spanner ]
                             β”‚
                             β–Ό
              [ Vertex AI Search / Vector Search ]
             (Embedding Generation + Dense Indexing)
                             β”‚
                             β–Ό
[ User Interface ] ──> [ Reasoning Engine Runtime ]
                             β”‚
             β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
             β–Ό                               β–Ό
     [ Semantic Search ]            [ Tool Calls / APIs ]
             β”‚                               β”‚
             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β–Ό
                   [ Gemini 1.5 Pro / Flash ]
                             β”‚
                             β–Ό
                   [ Grounded Output ]
Component / FeatureVertex AI Search (Data Stores)Vertex AI Vector Search (Matching Engine)
Primary Use CaseOut-of-the-box RAG, document search, web scrapingCustom embedding models, billion-scale ANN vector indexing
Indexing PipelineFully managed (auto chunking, embedding, parsing)Developer managed (Vertex Embeddings API, custom pipelines)
Query Latency~200ms - 500msSub-10ms high-throughput
gcloud Managementgcloud discovery-enginegcloud ai index-endpoints
Grounding IntegrationDirect Gemini Tool integrationCustom Python retrieval pipeline

5. Multi-Agent Systems & Advanced Design Patterns

Hierarchical Multi-Agent Pattern

In complex enterprise workflows, split tasks across a Orchestration Supervisor Agent and specialized Domain Worker Agents.

class SupervisorAgent:
    def __init__(self):
        self.finance_agent = FinanceSubAgent()
        self.legal_agent = LegalSubAgent()

    def route_and_execute(self, user_request: str) -> str:
        # Step 1: Supervisor plans and decomposes task
        if "contract" in user_request.lower():
            legal_analysis = self.legal_agent.analyze(user_request)
            return self.finance_agent.assess_financial_impact(legal_analysis)
        else:
            return self.finance_agent.execute(user_request)

Safety, Guardrails & Security Best Practices

  1. IAM & Least Privilege:
    • Assign dedicated GCP Service Accounts to Reasoning Engines.
    • Grant granular IAM permissions: roles/aiplatform.user, roles/discoveryengine.viewer, roles/bigquery.dataViewer.
  2. Vertex AI Safety Settings:
    • Configure threshold guardrails for Hate Speech, Harassment, Dangerous Content, and Explicit Content directly within GenerativeModel(safety_settings=...).
  3. Network Isolation:
    • Wrap Vertex AI endpoints inside VPC Service Controls (VPC-SC) perimeters to prevent data exfiltration.
    • Use Private Service Connect (PSC) for secure connections to on-prem databases or Cloud SQL instances.

Observability & Performance Monitoring

  • Cloud Logging: All Reasoning Engine stdout/stderr outputs automatically aggregate in GCP Cloud Logging (resource.type="aiplatform.googleapis.com/ReasoningEngine").
  • Token Budget & Latency Tracing: Embed OpenTelemetry hooks to monitor prompt token counts, tool execution latency, and model response times.

Common Issues and Troubleshooting

Agent Deployment Failures

  • Verify Vertex AI API is enabled
  • Check service account permissions
  • Ensure container registry access
  • Review resource quotas

Tool Execution Errors

  • Validate tool function signatures
  • Check API authentication
  • Monitor token usage limits
  • Review rate limiting policies

Performance Issues

  • Monitor latency metrics
  • Optimize model selection
  • Review token budget
  • Check network connectivity

Cleanup Commands

# Delete Reasoning Engine deployment
gcloud ai reasoning-engines delete my-agent \
  --region=us-central1

# Delete Discovery Engine resources
gcloud discovery-engine data-stores delete my-data-store \
  --location=global

# Delete agent resources
gcloud discovery-engine engines delete my-engine \
  --location=global

Jump to other sections

Additional Resources