# Building Next-Gen Agentic Architectures: From Local RAG to Sandboxed Execution and BigQuery MCP

> Source: <https://dev.to/mpnishanth/building-next-gen-agentic-architectures-from-local-rag-to-sandboxed-execution-and-bigquery-mcp-3ekh>
> Published: 2026-08-28 22:20:31+00:00

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.
