CONCEPT · AGENTS
Why code graphs help when working with agents
A code graph gives a coding agent a queryable map of the repository, so it needs fewer steps to answer structural questions and misses fewer indirect dependencies.
3 min read · updated 2026-10
What is it
A coding agent working in a repository constantly has to answer structural questions: where is this defined, who calls it, what breaks if I change it. A code graph is an index built to answer exactly those.
A parser reads each file and produces an AST (abstract syntax tree), a tree that says what each part of the code is, not just which characters it contains. From it, the tool extracts every symbol (function, class, method, route) as a node and every relationship between them (calls, imports, extends, implements...) as an edge. The result is stored locally, for example in a SQLite file, and exposed to the agent as a tool through MCP.
Tools like CodeGraph work this way. Two clarifications:
- The graph is not AI. It does not understand natural language. It searches by keywords against symbol names, signatures, and docstrings, then walks the edges.
- The graph is not the agent's brain. It is a lookup tool. The language model decides what to ask and interprets the answer.
Mental model
Think of a library catalog versus walking the shelves.
Without a catalog, finding every book that cites a given author means opening books one by one. With a catalog, you look up the author and get the list with locations.
An agent without an index walks the shelves: it searches for a name, reads a file, searches again, reads another file. An agent with a graph consults the catalog.
How it helps an agent
- Fewer steps. One query can return the relevant source code, the call paths between the symbols, and a blast radius: what depends on the code in question. In CodeGraph this is what
codegraph_explorereturns. Fewer steps means fewer round trips. - Fewer missed dependencies. Text search finds the places where a name appears; the graph follows real call edges, so indirect callers show up even when you did not think to search for them.
- Safer changes. Before editing, the agent can ask what depends on a function and check those places, instead of discovering the breakage afterward.
- A clear division of labor. The graph does deterministic retrieval. The model does the language work: it turns "how do reservations work?" into good keywords, calls the tool, and explains the result. That is why asking a question in natural language still works.
- Context under control. The agent receives the symbols that matter instead of reading whole files hoping to find them.
The graph tells the agent where to look. It does not replace reading the code that matters.
When to use it / when not to
A code graph pays off when:
- The repository is large, and grepping and reading becomes slow or noisy.
- Your questions cross many files ("how does this flow work end to end?").
- You want to know what a change affects before making it.
- You are onboarding to a repository you did not write.
It matters less, or can mislead, when:
- The project is tiny. Grep plus a couple of reads costs about the same, so you may not see any token savings. Measure the number of steps and tool calls, not just tokens.
- Your keywords are not in the code. Keyword search will not find "inicio de sesión" if the function is called
login. The agent usually bridges this by choosing English keywords. - The index is stale. The index is a copy of your code. If it falls behind, the agent trusts a map that no longer matches the territory. Keep it in sync.