Table Of Contents
- System Architecture Overview
- 1. Grounded Context: Serverless Local & Vector RAG with ADK
- 2. Dynamic Execution: Sandboxed Python Analytics & Human-in-the-Loop
- 3. Scalable Intelligence: Gemma 4 Deployment & BigQuery MCP Integration
- Key Architectural Takeaways
Modern enterprise AI has moved far beyond basic chat completions. To deliver tangible business value, artificial intelligence systems require grounded real-time context, safe execution environments, and standardized access to massive enterprise datasets.
In this article, I break down three progressive architectural patterns for building production-ready AI agents using Google Cloud, the Agent Development Kit (ADK), and modern LLM frameworks.
System Architecture Overview
┌─────────────────────────────────────────────────────────────┐
│ User Interface │
│ (Streamlit Chat / WebSocket UI / ADK Web Console) │
└──────────────────────────────┬──────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ ADK Agent Runtime │
│ (LlmAgent, Runner, Session Management) │
└───────┬──────────────────────┬──────────────────────┬───────┘
│ │ │
▼ ▼ ▼
[ RAG Grounding ] [ Cloud Run Sandbox ] [ BigQuery MCP ]
• Local JSON Tool • Shell / Python Tool • Direct VPC Egress
• Firestore Vector DB • POS Data Analytics • Schema Exploration
• text-embedding-005 • Google Sheets API • Read-Only Analytics
Enter fullscreen mode Exit fullscreen mode
1. Grounded Context: Serverless Local & Vector RAG with ADK
Dynamic retrieval prevents hallucinations and protects domain-specific constraints. Building an interactive conversational agent requires decoupling static knowledge from live operational data:
Token-Efficient Tools: Rather than cluttering system prompts with large catalogs, the agent uses structured tools to query local datasets on demand, minimizing prompt token consumption and latency.
Scalable Vector Search: Migrating data to Cloud Firestore Native Mode allows the agent to generate vector embeddings using
text-embedding-005and execute cosine similarity searches (find_nearest) directly inside tool functions.Serverless Deployment: Deploying the agent wrapped in a Streamlit interface directly to Cloud Run using Google Cloud Buildpacks creates a scalable microservice protected by dedicated least-privilege service accounts.
# Firestore Vector Search Tool Example
def get_menu(query: str) -> str:
db = firestore.Client(database="coffee-menu")
client = genai.Client()
response = client.models.embed_content(
model="text-embedding-005",
contents=query,
)
query_vector = response.embeddings[0].values
results = db.collection("menu").find_nearest(
vector_field="embedding",
query_vector=Vector(query_vector),
distance_measure=DistanceMeasure.COSINE,
limit=3,
).stream()
return json.dumps([doc.to_dict() for doc in results])
Enter fullscreen mode Exit fullscreen mode
2. Dynamic Execution: Sandboxed Python Analytics & Human-in-the-Loop
Complex business operations require more than text generation—they need secure code execution and verifiable human oversight.
Cloud Run Sandboxes: Executing code via an isolated sandbox environment (
/usr/local/gcp/bin/sandbox) enables the agent to write and run ad-hoc Python scripts dynamically to solve analytical queries without exposing host infrastructure.Bottleneck Diagnostics: The agent ingests historical Point-of-Sale (POS) data, correlates order spikes with event schedules, diagnoses bottlenecks (distinguishing between front-counter cashier queues and barista fulfillment delays), and drafts actionable operational recommendations.
Human-in-the-Loop (HITL) Safety: The agent presents diagnostic conclusions and requests explicit user confirmation before executing updates to production sheets via the Google Sheets API.
3. Scalable Intelligence: Gemma 4 Deployment & BigQuery MCP Integration
Standard database connectors create architectural complexity when connecting agents to enterprise data warehouses. The Model Context Protocol (MCP) provides an open standard for tool integration:
Self-Hosted Open Weights on Cloud Run GPUs: Deploying Gemma 4 31B-it using vLLM on Cloud Run with NVIDIA RTX 6000 Pro GPUs. Cold-start times are minimized using Direct VPC Egress and Cloud Storage model streaming.
BigQuery MCP Server: Connecting the ADK agent to the managed BigQuery MCP toolset (
get_dataset_info,list_table_ids,execute_sql_readonly) gives the agent a native, secure bridge to cloud datasets.Autonomous Analytical Querying: The model parses schemas, formulates multi-table analytical SQL queries, validates syntax using dry runs, and derives operational decisions across millions of records.
# BigQuery MCP Toolset Configuration in ADK
bigquery_toolset = MCPToolset(
connection_params=StreamableHTTPConnectionParams(
url="[https://bigquery.googleapis.com/mcp](https://bigquery.googleapis.com/mcp)",
headers={
"Authorization": f"Bearer {application_default_credentials.token}",
"x-goog-user-project": project_id,
},
tool_filter=[
'get_dataset_info',
'list_table_ids',
'get_table_info',
'execute_sql_readonly',
]
)
)
Enter fullscreen mode Exit fullscreen mode
Key Architectural Takeaways
Decouple Data from Prompts: Dynamic tool retrieval and vector search prevent token bloat and enable live catalog updates.
Isolate Code Execution: Run agent-generated analytics inside sandboxed runtimes to maintain security boundaries.
Standardize Integrations with MCP: MCP servers eliminate custom connector glue code and simplify enterprise data connectivity.