← cecilia lee

The Day the Agent Lied to Us Confidently

A field story about wiring a code knowledge graph into our AI coding agent — and three mistakes that taught the graph to know its own blind spots.

august 2026 · field notes

It started with a message that read, innocently enough: "hey why did the agent say this function doesn't exist? I'm looking at it right now."

We'd had an AI coding agent running against a sprawling microservices codebase — six services, tens of thousands of files — for a few weeks by then. It was good at the small stuff: find this file, fix this test, rename this variable. But the moment someone asked it something an actual architect would ask — "how does this request flow from end to end?" — it fell apart in a very specific, very embarrassing way. It didn't say "I don't know." It confidently grepped its way to a plausible-looking answer, presented it with full conviction, and moved on. Nobody caught the mistake until a human who actually knew the system read the output and went "...no."

That was the real problem. Not "the agent is slow" — slow we could live with. "The agent is wrong in a way that sounds right" was the one that kept us up. This is the story of the fix, and three mistakes along the way that taught us more than the fix itself did.

The idea: read the codebase once, not every session

The underlying waste was obvious once we measured it: every time a developer asked "how does X work," the agent re-discovered the answer from scratch — reading a dozen-plus files, following imports and calls, burning real tokens and real minutes. The same flow got re-discovered by every developer, every session. One heavy user alone burned through nearly 2 million tokens across 15 sessions, mostly re-doing the same codebase archaeology.

The fix: read the codebase once into a structural graph — classes, methods, calls, dependencies, as nodes and edges — and let the agent query the graph instead of re-reading the files every time. We used Graphify, an open-source tool built exactly for this — it parses a codebase with real AST parsers and turns it into a queryable graph, deterministically, with zero LLM tokens spent on extraction.

The architecture

Five layers, each with one job. Data flows up on a schedule; questions flow down on demand.

One question worth answering directly: why a shared, centrally-refreshed graph at all, rather than just having each developer build their own copy locally? Three reasons. A full build takes real time — roughly ten minutes for one mid-sized service — and that cost should be paid once per actual code change, not once per developer who wants a fresh graph. Consistency matters more than it sounds: with one canonical graph per service, "how stale am I" has a clean answer (compare my checkout to one known commit); with everyone building their own, two people could be looking at two different snapshots with no shared way to tell whose is fresher — which quietly undermines the entire staleness-checking idea below. And onboarding gets much simpler: a new developer pulls a few megabytes of already-built graph instead of waiting through a first build before the tool is useful at all.

The results, once all six services were mapped — roughly 141,000 nodes and 487,000 edges in total — were a genuine step change: answering an architecture question dropped from about 150,000 tokens and five minutes to around 10,000 tokens and thirty seconds. In head-to-head benchmarks against the old grep-and-read approach, the graph-based answers won 14 out of 15 times, at roughly a twentieth of the token cost.

That's the headline number. Getting there took three mistakes, each one teaching the same lesson from a different angle.

Mistake one: giving it a map instead of a flashlight

Our first version wired the graph up to the agent directly — ask a question, the graph answers. It worked, technically. But it was overkill for most questions. The large majority of what people actually asked was "orient me" — not "trace this exact edge case." We were making the agent do expensive graph traversal to answer questions a cheap, pre-generated summary could've answered just as well.

So we layered it: a cheap, automatically-refreshed report — key hub files, clusters, a call-flow summary — answers the orientation questions for free, with no live computation. Only if that doesn't resolve it does the agent do a real graph query. And only if the graph itself comes up empty does it fall back to reading raw source.

Lesson one: the expensive tool should be the last resort, not the first instinct. Most questions don't deserve your most powerful weapon.

Mistake two: the graph that couldn't take a hint

Then someone asked "what calls the payment handler?" and got back nothing. Not an error — worse, a quiet empty result that looked exactly like a legitimate "nothing calls this."

Except something obviously did. We just hadn't named it "handler." The codebase called it Executor. The graph matched on near-exact substrings — no synonyms, no stemming — so "handler" and "executor" were, as far as the tool was concerned, two unrelated words in two unrelated universes.

This one stung because it was invisible. A wrong answer you can catch. A silent empty answer that reads as "there's nothing here" actively teaches the wrong lesson. The fix became a hard rule, not a suggestion: before ever querying the graph, go get the actual vocabulary the graph knows — the real words used in the codebase's own symbol names — and translate the question into those words first. We built this as its own tool the agent must call before every query: it hands back the top few hundred real tokens from the codebase, plus the handful of real relationship types that exist between nodes, so the agent is never guessing a word — or guessing whether a relationship is called call or calls — it's choosing from what's actually there.

Lesson two: when a system matches on names, "no results" and "wrong words" look identical from the outside. You have to check the vocabulary before you trust the silence.

Mistake three: the ghost of the main branch

Just when the tool started to feel trustworthy, it broke trust again — more subtly. An engineer asked the agent about a method they'd renamed two days earlier, on their own feature branch. The agent answered using the old name, with total confidence, and was completely wrong — because the graph was a snapshot of the main branch, rebuilt on a schedule, and this branch's changes hadn't merged yet.

This forced us to be honest about what a knowledge graph actually is: not a live view of reality, but a photograph. Photographs get stale the moment reality moves on. The scary part wasn't that it was stale — every cache is, sometimes. The scary part was that the agent had no idea it might be stale, so it never hedged.

We built in a mandatory check before trusting any graph answer about a specific file: what branch are you on, is this file modified locally, how far behind the main branch is your checkout. Depending on the answer, the agent either trusts the graph outright, trusts it for everything except the file it just edited, or — on a divergent branch — treats the graph as "here's what's on main, but don't believe it about anything you've personally touched."

Lesson three: any tool built on a snapshot needs an explicit, checkable answer to "how stale am I right now" — not a disclaimer buried in documentation nobody reads under deadline.

Knowing where it doesn't apply at all

The three mistakes above were all about making the graph honest within its own domain. But the more basic boundary is simpler: the graph indexes code structure — who calls whom, who extends whom, what clusters with what. It does not index string contents, runtime state, or time.

In benchmark testing, this boundary showed up concretely: the one question type where the graph lost to plain grep was "where is this SQL string literal defined?" — exactly the left-hand column. The graph doesn't index strings; grep does. Rule of thumb: if the answer lives in code structure, use the graph. If it lives in string content, state, time, or config, use grep.

Where this goes next

Right now the graph is served as a compressed file, loaded whole into memory by the query server. That's genuinely fine at the current size — but it's a deliberate, evidence-gated choice, not a permanent one. The next step under consideration is a proper graph database (something like Neo4j or Amazon Neptune) in place of the flat file: native traversal instead of in-memory search, indexed edges instead of a full load on every startup, and partial reads instead of pulling the whole graph just to answer one question. We're treating this the way any infrastructure migration should be treated — prove the cost reduction and confirm there's no performance regression on a small pilot first, then migrate, rather than adopting new infrastructure on the strength of a good argument alone.

The more interesting direction, once that foundation is in place, is hybrid search — combining the graph's structural precision with semantic retrieval. Right now the system answers "what calls X?" beautifully and "what's semantically similar to this problem?" not at all — those are two different retrieval problems, and this project only solves the first one. A vector index alongside the graph would let a query do both: traverse exact structural relationships where the question is precise, and fall back to semantic similarity where the question is fuzzier or the right vocabulary isn't obvious — which, notably, would also soften mistake two from a different angle, since a semantic match doesn't require guessing the codebase's exact word for something. It's the same combination I reached for in a different project — keyword-exact and semantic-fuzzy answer different kinds of questions, and a system that can only do one is leaving queries on the table.

What ties it together

All three mistakes are, underneath, the same mistake wearing different clothes: a system that can answer with authority, but had no built-in way to signal when it shouldn't. An overpowered tool answering an easy question doesn't know it's being wasteful. A substring match on the wrong word doesn't know it found nothing because it was asking wrong. A stale snapshot doesn't know it's stale unless you make it check.

None of the fixes were dramatic rewrites. They were small, almost embarrassing corrections — layer the expensive tool behind cheaper ones, check your vocabulary before trusting silence, check your freshness before trusting an answer. But they only became obvious after watching the agent confidently say something wrong to someone who knew better.

The throughline, if there is one: build any system that answers questions with authority, and you inherit an obligation to also tell it — and its users — exactly when not to trust itself. The graph didn't need to be perfect. It needed to know its own blind spots and say so.

Details genericized where they'd reveal internal systems or tooling names; the architecture, numbers, and lessons are accurate. If you're building something similar, I'd like to compare notes — github.com/lsscecilia.