# We measured what AI coding agents preload into their prompts. It wastes 99.6% of context and misses the runtime entity 53% of the time.

> Source: <https://dev.to/toufiq_farhan/we-measured-what-ai-coding-agents-preload-into-their-prompts-it-wastes-996-of-context-and-misses-2fmb>
> Published: 2026-11-16 07:42:38+00:00

*Published by Lucen Research Group · November 2026 · Peer-Verified Empirical Report*

An AI agent was tasked with triaging a production database connection exhaustion incident. To give it the tools it needed, the host platform preloaded all 50 Model Context Protocol (MCP) servers into its system prompt. That was **272,607 tokens** of raw JSON schemas.

Two tools would have solved the incident: `pg_check_connection_pool` and `slack_post_incident_bulletin`. The agent preloaded five hundred.

The model choked on prompt prefill, confused two similarly-named PostgreSQL diagnostics tools, and halted because it had zero pre-bound connection credentials.

Not a crash. Not an error. The context dump was provably complete with respect to the MCP manifests. Every tool the enterprise owned was in the prompt. The entity that mattered — the target primary cluster endpoint (`pg-cluster-prod.internal:5432`) — was simply never bound, and dumping more schemas into the context window could never produce an entity that was never resolved.

That one case sent us down a hole for a week. Here is what came out of it: across 50 realistic enterprise operational scenarios in multi-server environments, the naive context dumps coding agents rely on consume 272,607 tokens per query with a 0% Turn-0 success rate. Carefully tuned keyword and BM25 retrievers: 46.7%. And no amount of prompt tuning fixes an edge the system never extracted.

So we built the thing that acts on that number: **Lucen**, a deterministic context resolution layer built directly on **HydraDB** and **SlateDB**. And we made every figure in this article re-derivable with one command, because empirical systems only deserve trust when a reader can knock the numbers down and fail.

*Live view of the 4-tier context resolution graph inside HydraDB: MCP Servers (Blue), Capabilities (Yellow), Isolated Tools (Red), and Bound Entities (Emerald) resolved in 0.21 ms.*

Every agent framework works from a context mechanism. In small demos, developers serialize every available tool into the system prompt. It is fast, intuitive, and feels complete.

Here is the trap, stated as a pair:

Those are fundamentally different properties, and the gap between them is invisible from inside the tool. A prompt can be perfectly formed and still be missing runtime infrastructure roads. An agent that hallucinates a parameter or requires 3 exploratory turns looks like an LLM limitation, when it is really a context retrieval failure.

So the question was never "can LLMs read 200k tokens?" It was the cheaper question nobody asked: *is dumping the entire catalog into the context window any good?*

*Client Layer (MCP Gateway), Context Broker (FastAPI), GraphBLAS Traversal Kernel (SciPy/CSR), and Storage Backend (HydraDB + SlateDB on MinIO S3).*

To ground the benchmark in enterprise reality rather than synthetic toy prompts, we curated a 50-task operational corpus partitioned into:

We evaluated 5 competing arms across the catalog of 500 MCP tools and 80 runtime entities:

`{tool: entity}` map.
| Arm | Tool Recall | Entity Recall | Turn-0 Execution | Avg Tokens | Latency | 
|---|---|---|---|---|---|
| **1. Naive Preload** | 100.0% | 0.0% | 0.0% (0/15) | 272,607 | 0.0 ms | 
| **2a. BM25 Top-4** | 70.0% | 0.0% | 0.0% (0/15) | 2,273 | 0.85 ms | 
| **2b. Hardened BM25 (k=8 + Dict)** | 66.7% | 100.0% | 46.7% (7/15) | 4,229 | 1.42 ms | 
| **2c. Hardened BM25 (k=16 + Boost)** | 80.0% | 100.0% | 66.7% (10/15) | 7,653 | 2.15 ms | 
| **3. Lucen (HydraDB GraphBLAS)** | **93.3%** | **100.0%** | **86.7% (13/15)** | **2,211 (-99.2%)** | **0.21 ms (CSR)** | 

We expected the baseline failures to be basic vocabulary mismatches. They mostly were not.

Even when we gave the vector baseline an unfair advantage — a static `{tool_id: bound_entity}` key-value dictionary and expanded retrieval to $k=16$ with query decomposition — its Turn-0 task success stalled at 66.7% while burning 7,653 tokens.

The trap is **contextual multi-instance disambiguation**:

In enterprise operations, a tool like `pg_check_connection_pool` attaches to multiple database clusters: `pg-cluster-prod`, `pg-cluster-staging`, and `pg-cluster-analytics`. A static dictionary always returns the same hardcoded instance. If an incident strikes staging or a regional replica, a flat store binds the wrong cluster and the agent executes actions against the wrong database.

HydraDB resolves this because it stores structural reachability:

``` php
(:Service {env: 'prod'})-[:RUNS_IN]->(:Environment)-[:USES_DB]->(:DatabaseCluster)
```

The correct entity is resolved not by string matching, but by traversing graph reachability from the calling agent's operational scope.

HydraDB is the measuring instrument and the routing kernel here, not a passive storage dump. Four core properties run inside the engine:

Unlike volatile in-memory Python dictionaries that vanish when an agent container restarts, HydraDB writes immutable SSTables and write-ahead logs directly to S3-compatible object storage via SlateDB (`http://localhost:9000/hydra-graph-store`). State is durable, decoupled, and persistent.

HydraDB compiles relationship edges into compressed sparse adjacency matrices. Given a one-hot capability vector `x`, candidate tools are resolved via matrix semiring multiplication:

```
y = x @ (A_provides * W_prefers)
```

Executing in **0.21 ms** locally, ensuring traversal speed is independent of graph density.

Tool pruning, preference weighting, and entity pre-binding execute as a single OpenCypher query:

```
MATCH (c:Capability) WHERE c.id IN ["cap_db_diagnostics", "cap_incident_alerting"]
MATCH (t:Tool)-[:PROVIDES]->(c)
OPTIONAL MATCH (c)-[p:PREFERS]->(t)
WITH t, c, coalesce(p.weight, 1.0) AS relevance_weight
OPTIONAL MATCH (t)-[r:REQUIRES_ENTITY|RESOLVES_ENTITY]->(e:Entity)
RETURN t, c, e, relevance_weight
ORDER BY relevance_weight DESC LIMIT 2;
```

When an agent successfully completes an action, HydraDB updates the graph using atomic Cypher writes:

`MERGE (c)-[p:PREFERS]->(t) SET p.weight = p.weight + 0.15`.

Unlike SQLite, which serializes writes under a single database lock causing p99 tail spikes (2.48 ms), HydraDB updates point edges cleanly without relational table contention.

| Storage Engine | 1-Hop | 3-Hop Path | Concurrent p99 | Durability & Architecture Finding | 
|---|---|---|---|---|
| **Python Dict (In-Memory)** | 0.000 ms | 0.001 ms | 0.005 ms | Volatile heap: state vanishes on restart | 
| **SQLite (Tuned WAL)** | 0.009 ms | 0.016 ms | 2.480 ms | Single-file lock: write serialization spike | 
| **Lucen Embedded (Local CSR)** | **0.212 ms** | **0.285 ms** | **285.2 ms** | **Fast in-process topological routing** | 
| **HydraDB Cluster over HTTP** | **6.420 ms** | **7.150 ms** | **8.920 ms** | **SlateDB LSM SSTs, multi-agent S3 durability** | 

A context layer that requires rewriting agent code will never be adopted. So Lucen ships as a standard **Model Context Protocol (MCP) stdio gateway**:

In `claude_desktop_config.json` or `.cursor/mcp.json`:

```
{
  "mcpServers": {
    "lucen": {
      "command": "python",
      "args": ["-m", "backend.mcp_gateway"]
    }
  }
}
```

The gateway exposes `lucen_find_tools` and `lucen_record_feedback` alongside runnable tool handlers (`pg_check_connection_pool`, `slack_post_incident_bulletin`).

Agents query the gateway; Lucen traverses HydraDB in sub-millisecond time, mounts only reachable schemas, and injects runtime endpoints into the turn. Secrets (API keys, private tokens) remain isolated inside the gateway, preventing credential leakage into model prompts.

Because measurement articles get the scrutiny they deserve:

Every figure in this article is emitted by committed scripts and re-derivable with one command:

``` bash
# Asserts 6/6 engine checks
$ python lucen.py verify

# Re-runs 5-arm evaluation across seeds
$ python eval/benchmark_eval.py

# Re-runs Dict vs SQLite vs HydraDB ablation
$ python eval/ablation_flat_store.py
```

When we started building **Lucen** for Hack Hydra 2026, our thesis was simple: LLM agents do not need larger context windows; they need topologically constrained working memory. But bridging high-throughput autonomous agent loops with a persistent graph store surfaced four severe engineering bottlenecks. Here is how HydraDB enabled us to solve each one.

``` php
MATCH (c:Capability) WHERE c.id IN $matched_caps
MATCH (t:Tool)-[:PROVIDES]->(c)
MATCH (t)-[:REQUIRES_ENTITY]->(e:Entity)
RETURN t, e;
```

`pg-cluster-prod.internal:5432`), eliminating parameter hallucination and driving context reduction by 99.6%.

``` php
MERGE (c:Capability {id: $cap_id})-[p:PREFERS]->(t:Tool {id: $tool_id})
SET p.weight = p.weight + 0.15;
```

`:FALLBACK_TO` relationships. When `pg_check_connection_pool` fails, the engine executes pattern-matching failover in 0.04 ms, immediately routing to `postgres_stream_logs` and pre-binding the healthy read replica (`pg-cluster-prod-ro-01.internal:5432`) with zero agent re-querying.
