Agent Architecture Weekly

Feeding a Live Dependency Graph Into an AI Coding Agent as Working Memory

Giving AI coding agents a live dependency graph as queryable working memory.

Sponsored by Graphide

Agent Architecture Weekly Editors
· 8 min read
Cover illustration for “Feeding a Live Dependency Graph Into an AI Coding Agent as Working Memory”
Agent Workflow Patterns · October 31, 2026 · 8 min read · 1,866 words

An interactive codebase graph for AI agent steering is a typed, directional map of repository relationships that updates with the code and answers queries during a task. Giving an agent access to it through the Model Context Protocol adds working memory beyond file reads and conversation history. Its usefulness depends on what it captures, how promptly it updates, and whether the agent can query it before each consequential edit.

Why agents lose the plot on multi-file tasks

A coding agent without persistent codebase context starts a session without knowing what was refactored last week, why a module was deliberately decoupled, or which convention governs a boundary. These omissions are not simply gaps in code comprehension. They remove the context needed to distinguish an available dependency from an acceptable one. A model can understand the contents of a file while lacking the architectural reasons that constrain changes to it. The failure begins in the memory infrastructure.

Without an external context layer, the agent reconstructs that missing picture through repeated tool calls and ad hoc file reads. That exploration is incomplete because code understanding is relational. A function’s role depends on what it calls, what calls it, and which boundaries those relationships cross. Reading matching files does not establish those relationships systematically, so the agent must infer a structure from whichever fragments it encounters.

That leaves architectural choices exposed to prompt variation. The same task, expressed through three different prompts, can produce different component structures, dependency graphs, and failure modes because each exploration supplies a different slice of context. This is a design gap. Better reasoning alone does not give the agent the missing history or dependency map.

What a live dependency graph actually is, and what makes it "live"

A code graph models services, files, functions, and dependencies as typed entities connected by typed, directional relationships. Its edges show which connections are calls, imports, dependencies, or schema references, keeping each kind distinct. Direction distinguishes a function’s callers from its callees. Those distinctions make precise repository questions answerable. A static diagram may illustrate architecture, but it cannot serve as working memory unless the agent can query a current representation.

Codegraph illustrates a local-first construction approach. It uses tree-sitter to parse code in different languages and keeps symbols, call edges, import relationships, and dependency structure in a persistent local SQLite database. SPADE/RIG, published in January 2026, takes a deterministic, build-and-test-centered approach. Its Repository Intelligence Graph represents components, aggregators, runners, tests, external packages, and package managers.

Cognee’s six-stage cognify pipeline commits edges incrementally, processing only new or updated files on re-runs. Without that maintenance, queries can return relationships that no longer describe the repository. The graph can also extend beyond syntax. Bito AI Architect ingests business context from Jira and Linear, tribal knowledge from Slack, and design documents from Confluence and Google Docs, making non-code knowledge available with structural context.

Why vector search alone is insufficient and graph traversal is the missing half

Vector search retrieves text chunks with similar meaning, which makes it useful for locating a relevant entry point. It does not establish a dependency chain. Knowing that process_payment calls validate_card, which depends on CardProvider, requires represented relationships rather than similarity between those names or their surrounding code. Even a highly relevant retrieved passage may omit a caller whose text looks unrelated to the task.

The distinction becomes decisive during change planning. Finding code that resembles a request is a discovery problem, while identifying what will break after an interface change is a dependency problem. Single-document similarity search cannot work through a call chain across three modules to find every caller that a change would affect. Graph traversal can follow those edges and return the represented dependencies, provided the graph captures them accurately. Coverage still limits the answer.

Vector search finds relevant entry points, and traversal follows dependency chains to gather related context. A larger context window does not remove the need for this division of work. Large contexts are expensive and slow, and “lost in the middle” degradation can reduce attention to relevant information buried in their center. Targeted retrieval gives the agent a connected subset of the repository instead of asking it to reconstruct relationships from a larger pile of text.

How MCP gives an AI coding agent a real-time codebase map it can query mid-task

Anthropic’s Model Context Protocol gives agents a standard way to connect to external tools and memory servers. A dependency graph exposed through an MCP server becomes something the agent can consult during execution, rather than an artifact supplied once at the beginning. For example, the agent can request the modules that depend on an interface before changing it. The response supplies structured relationships instead of leaving the agent to grep for a string and infer which matches represent dependencies.

Code-aware ingestion determines what enters the graph, graph reasoning determines which relationships can be followed, and persistent storage keeps the result outside the conversation. MCP connects those capabilities to the agent’s workflow. Without that connection or a query interface that does the same job, even a well-built graph is an offline resource. Conversely, standardized access to chat history alone does not provide dependency reasoning.

Because the stored graph exists independently of the conversation, session resets, IDE restarts, and tool switches need not erase it. Cognee supports a pattern in which multiple developers query a shared knowledge graph through a single API-mode instance. But persistence and delivery do different jobs, so MCP support alone does not ensure that storage lasts or that the index is up to date.

What the graph needs to contain beyond function signatures

An import graph cannot show every architectural constraint. The objection is substantive. A rule that a module must not know another module’s internals concerns responsibility and encapsulation. File paths and call edges can show a connection without proving that it stays within the intended boundary. Intent-aware editing needs a complete view of the structure, but it also needs more than that.

Complete codebase memory needs three distinct layers, which are code structure, edit history, and relational context. Structure records what the code is, history records what changed and in what order, and relational context records dependencies. The reasoning behind deliberate decoupling, a locked API contract, or a constrained data model often resides in PR descriptions, design documents, and past conversations. Bito’s ingestion of non-code context represents one production approach to closing that gap.

Edit heuristics add another kind of evidence. If auth.middleware.py is always modified with routes.py, that pattern reveals implicit coupling even when no import edge connects them. It is architectural knowledge, but it is not equivalent to a declared dependency. Deterministic constraints, including represented import edges, call relationships, and package boundaries, can be checked programmatically. Semantic constraints require complementary model-based judgment, with the graph grounding that judgment in the actual structure.

How the graph keeps the agent coherent as it moves across files in a single task

Before the first edit, an agent with graph-based working memory can query which modules are in scope, where dependency boundaries lie, and which callers an interface change will affect. That changes the basis of its plan. Instead of discovering architecture incidentally while opening files, it begins with represented relationships and the constraints attached to them. File reading still supplies implementation detail, but it no longer has to supply the entire architectural picture.

As edits accumulate, the graph can connect task history to outstanding work. With edit history represented and the index updated, the agent can query which files it has modified and which callers of a changed function remain untouched. The gap becomes explicit rather than inferred. This supports a precise scope test, namely whether the agent touched the files it should have touched and only those. The diff shows edits, while the graph supplies the dependency context needed to judge their reach.

Salesforce’s Prizm illustrates the downstream alternative of reconstructing that context during review. Salesforce redesigned review around intent reconstruction as PRs regularly expanded across many files and over a thousand lines of change. Prizm preserves structural boundaries in diffs, including files, functions, and modules. Graph-based working memory moves that structural awareness upstream into the editing process. Review can still examine the result, but the agent has access to dependency context while its choices remain in progress.

Running graph conformance checks in CI to enforce what the agent built

A graph consulted during a task remains advisory unless architectural rules also constrain the resulting code. A conformance layer compares the dependency graph of generated code against declared constraints, including a rule such as “no new database dependencies without review.” The comparison turns a planning boundary into an enforceable condition. It tests whether the output respects the rule.

Architecture tests integrated into CI can make deterministic violations block the build and prevent a merge. Enforcement no longer depends on a reviewer noticing. Hard constraints provide that binary gate for non-negotiable boundaries, while soft constraints surface concerns without stopping the build. Semantic questions still need the judgment layer described earlier.

The graph must also version with the code. A conformance check against stale relationships can produce false confidence because the checked structure differs from the proposed change. The update strategy that supports mid-task queries therefore also supports trustworthy enforcement. The graph that guides an edit and the graph that checks its output must both match the repository state they are used for. Otherwise, a deterministic check can be precise about the wrong structure.

Building or adopting graph-based agent memory: what the implementation choices actually determine

Construction determines what the memory system can see. AST-based parsing captures syntactic structure, and tree-sitter-based approaches such as Codegraph’s support polyglot repositories. If a parser misses dynamic imports or cross-service calls, traversal cannot fill in what it missed. RIG’s build-and-test-centered representation shows a different view of the architecture, while Bito’s non-code ingestion brings in the missing intent.

Storage determines where memory persists and who can share it. Codegraph’s local SQLite approach provides a persistent repository graph on the local system, while Cognee’s shared API-mode pattern supports multiple developers querying common memory. Neither storage choice, by itself, establishes freshness or useful query behavior. Those depend on the surrounding implementation. The appropriate comparison is therefore not just where the graph lives, but whether that deployment supports the intended working context.

Update strategy and query access deserve particular attention because a graph can be constructed correctly and still fail operationally. Full re-ingestion on every run can be accurate but slow for large repositories, while incremental processing makes it practical to keep the graph up to date. A graph without a standard query interface needs custom integration for each agent framework. MCP server support is the practical baseline for existing coding workflows. Otherwise, teams have to keep integration code working before the agent can use the memory mid-task.

For a team building or adopting this approach, the lesson is to evaluate coverage, storage, incremental updates, and query access as separate decisions. A map that supports visual inspection does not by itself establish that an agent can query it during a change. The decisive capability is a current, structured answer at the point of action, backed by conformance checks for the boundaries that must not be crossed.

Sources

  1. Building Effective AI Coding Agents for the Terminal: Scaffolding, Harness, Context Engineering, and Lessons Learned
  2. Agentic Context Management: Solving Agent Memory and Cost by Treating Them as Lifecycle and Architecture Problems
  3. Codified Context: Infrastructure for AI Agents in a Complex Codebase
  4. AgentFlow: Building Agent Dependency Graphs for Static Analysis of Agent Programs
  5. Architecture Without Architects: How AI Coding Agents Shape Software Architecture

More in Agent Workflow Patterns