Building Next-Gen Agentic Architectures: From Local RAG to Sandboxed Execution and BigQuery MCP A developer detailed three progressive architectural patterns for building production-ready AI agents on Google Cloud, using the Agent Development Kit (ADK) and modern LLM frameworks. The patterns cover local RAG with Firestore vector search, sandboxed code execution on Cloud Run with human-in-the-loop oversight, and BigQuery integration via the Model Context Protocol (MCP). The approach aims to ground AI with real-time context, ensure safe execution, and standardize access to enterprise datasets. 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. ┌─────────────────────────────────────────────────────────────┐ │ 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 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-005 and 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. php 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 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 . 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', 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.