Est.

Monorepo vs Polyrepo Architecture With AI Agents

AI agents work best in monorepos where they can see the full dependency graph.

· 9 min read
Cover illustration for “Monorepo vs Polyrepo Architecture With AI Agents”
Agent Workflows · October 16, 2026 · 9 min read · 1,985 words

The monorepo-versus-polyrepo decision has quietly become an AI agent capability question. An agent that can see one service at a time, blind to what depends on it, cannot do the same work as an agent that reads the full dependency graph. The structure a team chooses now sets a hard ceiling on what its agents can deliver, and most teams have not made that choice deliberately.

Why the monorepo vs. polyrepo decision changed when agents arrived

The monorepo-versus-polyrepo debate is being reopened by a force it was never designed to answer: autonomous AI coding agents whose effectiveness is directly bounded by what a repository lets them see, write, and remember. The traditional framing, team autonomy versus shared tooling, fast isolated CI versus atomic cross-project commits, never considered an agent as a first-class actor in the system. Those tradeoffs were negotiated by humans who could walk across the office, read a wiki page, or ask a teammate how a service behaves. Agents do none of those things. They operate on whatever is in their context window, which means repo boundaries function as hard walls rather than the organizational lines on a chart they were for people.

The cap is not there because the agents are weak. It is there because the architecture withholds the inputs an agent needs to reason across system boundaries. A team that adopted a polyrepo strategy years ago for legitimate organizational reasons may now find that those same boundaries prevent the agent from completing the cross-service refactor where the highest leverage work lives.

What an agent actually needs from a repository to do its job

Diagram: What Agents Need — and What Each Structure Provides. Visualizes: Visualize three agent requirements (cross-project read access, atomic cross-project write ability, persistent context across sessions) against three structure options…

Agent effectiveness in a codebase depends on three properties that repository structure either provides or denies: cross-project read access, atomic cross-project write ability, and persistent context across sessions. These three requirements are the checklist every architecture decision should be evaluated against, because they determine what an agent can accomplish before a human ever steps in. The read requirement is the most immediate. An agent building a frontend form that cannot see the backend it calls will miss edge cases. An agent updating a shared UI library that cannot see which applications consume it cannot catch downstream breakage. The write requirement compounds the problem. Every human handoff reduces agent autonomy, and the coordination work is exactly what agents were supposed to remove. The memory requirement is the least visible but perhaps the most corrosive. Every repository boundary wipes the agent's context. Nx's monorepo analysis calls this the "Memento Problem." The solution that a monorepo provides is not error-free output. It is coherent mistakes that are easier to spot and fix, rather than the incoherent context loss that produces errors no one can trace.

What a monorepo gives agents and what it costs to sustain

A monorepo satisfies all three agent requirements by construction. A breaking API change and every caller live in one repo, which means one commit, one review, and one revert path. There is no choreography of PRs across six repositories, no compatibility matrix, no deployment ordering. Nx's analysis demonstrates the difference with a side-by-side: a developer using an agent in an Nx workspace completed a cross-project change four times faster, with far fewer interruptions, than in a polyrepo. The memory benefit follows directly: the agent works in one continuous context, and its mistakes are coherent rather than fragmented.

There is a second-order effect that matters more than the direct productivity gain. In polyrepo environments, cross-project work is so painful that teams stop attempting it. A monorepo removes that friction, which means agents can propose the migrations and refactors that were previously written off as too expensive. That unlocked work represents the larger portion of the value. But these properties are not free. Past a certain scale a team cannot build everything on every change, so it needs change detection, remote caching, and a team that owns the build machinery. The build system becomes infrastructure in its own right, and when that infrastructure lags, CI cycle times absorb the difference. A monorepo is a bet that the team will keep funding build-infrastructure evolution. That bet can pay off, but only if the infrastructure keeps pace with repository scale.

What a polyrepo gives agents and what it silently takes away

A polyrepo's strongest properties are real and organizational. Each repository has its own CI pipeline, its own release cadence, and an ownership boundary that maps cleanly onto a team. Different stacks can coexist without a single build tool needing to understand all of them. Deprecating a service means archiving a repo. That operational steadiness is exactly what monorepos must earn through tooling investment.

The agent cost is hidden inside those same boundaries. An agent updating a UI component library cannot see which applications consume it. An agent building a frontend form cannot see the backend it calls. The deeper cost is the work that never gets attempted. Even when tooling tries to bridge the gap, the cross-repo change remains non-atomic. Nx describes its Polygraph cross-repo agent harness honestly: each write must land independently, so the overall change still involves friction and cannot be atomic.

The queryability gap — why "what depends on this" is the real variable underneath the debate

The monorepo-versus-polyrepo debate is ultimately a proxy argument. The real variable is whether "what depends on this" is queryable at any moment, and physical co-location in one repository is only one way to provide that. Riftmap's analysis names the distinction directly: a build graph answers "what depends on this" automatically, by construction, inside a monorepo. In a polyrepo, nobody can answer that question without going looking, and the agent cannot go looking. What turns co-location into a genuine agent benefit is the layer on top: affected-only build and test, a dependency graph, enforced API boundaries, and ownership rules. Without these, a large monorepo gives an agent files but not structure.

The same properties can be approximated across polyrepos if tooling constructs a synthetic dependency graph. Nx's Polygraph does exactly this. It connects all repositories into one dependency graph without moving code, and it records sessions so any agent can resume prior work. But writes remain non-atomic, so the approximation is real and partial. The practical implication for teams evaluating structure is to ask a different question first: can our agents query the dependency graph? A tool that maps a codebase into a live, navigable architecture graph makes this structural choice visible. Graphide maps a codebase into such a graph, which lets developers evaluate deliberately what an agent can and cannot see across repository boundaries and what the cost of those boundaries is in terms of agent context and coherence.

How experienced developers actually control agents regardless of repo structure

Experienced developers do not delegate fully to agents regardless of repository structure. They plan before implementing and validate all agent outputs, treating agents as a productivity boost rather than a replacement for judgment. A Cornell and UC San Diego study of 99 experienced developers found that professionals carefully control agents through planning and supervision. They are looking for a productivity boost while still valuing software quality attributes, and they find agents suitable for well-described, straightforward tasks but not for complex ones. They describe what should happen, inspect the resulting diff, run or review tests, correct assumptions, and repeat.

Repository structure amplifies or constrains what this loop can accomplish. In a polyrepo, a developer validating an agent's cross-service change must manually reconstruct the context the agent never had. In a monorepo with a queryable graph, the diff arrives coherent and the blast radius is visible. Agent-generated PRs are larger, arrive faster, and wait longer for human review, which makes the quality of the structural context agents work in visible in the review queue. The developer's cognitive load is not removed by agents. It is redirected, and the repository structure determines whether that load lands on understanding the change or on reconstructing lost context. The same study confirms that developer strategy shapes agent quality, while repository structure shapes agent capability. Both layers matter, and neither substitutes for the other.

Why CI enforcement of architectural constraints is not optional in either structure

An agent has no inherent understanding of your architecture. It is optimizing for "solve this task," not "maintain this system's structure." Architectural rules must be machine-enforced at the CI gate, not documented in a file the agent reads inconsistently. Rules that run as tools before the code merges, such as strict linters, type checkers, and runtime contract validators, are more reliable because they do not depend on the agent reading and applying them correctly. The gate is static analysis before merge: code that violates architectural constraints does not merge, regardless of whether an agent or a human wrote it. A compliance check that exits non-zero and blocks a merge is more valuable than any amount of post-hoc architecture review, because the review arrives after the structure has already been compromised.

In a monorepo, build-graph tooling answers the blast-radius question automatically. An affected-only test run shows what broke before the PR is reviewed. In a polyrepo that visibility requires additional tooling to reconstruct. The most useful review question for agent-generated code is no longer just "does this work?" Software is maintained far longer than it is generated, so the structural question matters beyond the immediate task. Without architectural guardrails in CI, a monorepo's structural advantage erodes as agents and humans drift the design independently. Tools that let teams define and enforce architectural constraints at merge time turn monorepo structure into a constraint that actually holds. Graphide's graph, combined with CI enforcement through its gr check command, is one way teams apply that discipline.

How to choose: the questions that actually determine which structure fits your agent workflows

The right repository structure for agent workflows is determined by how frequently a team needs cross-cutting atomic changes versus how much it needs isolation, independent versioning, or compliance-grade access control, and whether the dependency graph will be queryable either way. A monorepo is the right choice when the most valuable work is cross-cutting: API migrations, shared library upgrades, refactors that touch many services. This is exactly where agents deliver the largest gains and where polyrepo friction destroys them. It requires a team that can fund build-infrastructure evolution, including affected-only builds, remote caching, and a dependency graph that stays accurate as the repository grows. And it is the structure in which CI enforcement of architectural constraints can cover the whole system in one gate.

A polyrepo is the right choice when services are genuinely independent with stable, versioned API contracts, the kind of isolation where an agent rarely needs to cross a boundary to complete a task. It also fits when compliance, access-control, or regulatory requirements map cleanly onto repository-level permissions and cannot be relaxed. And it works when cross-cutting changes are rare enough that manual coordination is not a bottleneck, with the explicit acceptance that agent leverage on those changes will be limited. If migration is not possible but agent cross-repo capability is needed, a synthetic monorepo, tooling that constructs a unified dependency graph across repositories without moving code, recovers the read and memory properties agents need. The write property, atomic cross-repo commits, remains constrained. Nx's Polygraph is an agent-agnostic meta-harness that connects repositories into one dependency graph and records sessions for persistent agent memory, while acknowledging that cross-repo writes are not atomic. The synthetic approach buys significant agent improvement without organizational migration cost, but it does not fully substitute for a real monorepo when atomic writes matter.

The underlying principle is that structure, not physical co-location, is what agents actually need. What matters is whether the dependency graph is queryable and whether constraints are enforced. The graph is the critical variable. Teams that plan and direct agent work on the graph, and then enforce constraints at the CI gate, are applying the structural discipline necessary regardless of which repository model they run.

Sources

  1. Professional Software Developers Don't Vibe, They Control: AI Agent Use for Coding in 2025
  2. Runnable Directories: The Solution to the Monorepo vs. Multi-repo Debate
Filed underAgent Workflows

More in Agent Workflows