How Repository-Level AI Coding Agents Work: Architecture, Runtime, and Verification Loops

    This article breaks down the technical architecture of repository-level AI coding agents, arguing that their engineering reliability comes from the runtime that wraps the model rather than from the model alone. It explains four core layers: the main loop that reads context, plans, calls tools, and writes changes; explicit permission boundaries that make safety a system capability; context isolation through sub-agents with separate roles and tool access; and verification loops that make passing tests the delivery gate. It also outlines a practical adoption path and common anti-patterns to avoid.

    Key takeaway first: capability comes from the runtime, not the model alone

    When people discuss how AI coding tools work, the most common misconception is to attribute all of the results to the model simply being “better at writing code.” A more accurate view is that the model supplies reasoning and generation, while what actually determines engineering usability is the runtime wrapped around it. This runtime schedules context, constrains actions, invokes tools, collects evidence, and drives verification. In form, it looks less like a completion engine and more like a software engineering system.

    Looking at the industry adoption curve, these tools entered mainstream development workflows within a year of release. That suggests they benefited from workflow advantages rather than short-lived novelty. So what deserves attention is not prompt tricks but system structure. The rest of this article groups that structure into four layers: the main loop, permission boundaries, context separation, and the verification loop.

    The main loop: from completing snippets to a continuous read-plan-call-write cycle

    Traditional AI completion behaves like a front-line copilot. Its interaction unit is a snippet of code near the cursor, and its goal is to return candidates with low latency. A repository-level agent works differently. Its smallest task unit is a verifiable engineering goal, such as fixing a class of defects, adding a missing capability, or migrating an interface.

    Its main loop typically has four stages:

    1. Read context: locate relevant directories, build configuration, test entry points, and existing conventions.
    2. Form a plan: break the goal into ordered steps and note how each step will be verified.
    3. Call tools: read and write files, run commands, execute tests, and search symbols and references.
    4. Write back results: fold tool output back into the context, revise the plan, and start the next round.

    Illustrative pseudocode:

    1. while not goal_satisfied:
    2. ctx = collect_context(goal, workspace)
    3. plan = propose_plan(goal, ctx)
    4. for step in plan:
    5. result = run_tool(step, permission=current_mode)
    6. ctx = merge(ctx, result)
    7. if result.signals_failure:
    8. plan = revise(plan, result)
    9. if verify(goal, ctx): break

    The key point is that the loop terminates not when generation is “done,” but when verification passes or the task is explicitly blocked. This explains why these tools feel unlike a plugin in the terminal: they carry state and the ability to act across rounds.

    Permission boundaries: making safety a system capability, not a verbal promise

    In engineering settings, the real risk is not that the model cannot write code, but that it writes beyond its authority, writes incorrectly, or writes before the boundaries are clear. Mature implementations turn permissions into an explicit configuration layer. Common modes include a default mode, an auto-accept-edits mode, a read-only planning mode, a non-interactive mode, a restricted question-answering mode, and a fully permissive mode.

    Three design points matter:

    • Least privilege by default: state up front what the agent may see and change in the current round, and which actions require a stop for confirmation.
    • Action classification: group read operations, write operations, external command execution, and network access by risk level, and force human confirmation for high-risk actions.
    • Auditable boundaries: record the arguments and results of every tool call so it is easy to trace the source of “changing A broke B.”

    The read-only planning mode best reflects the design philosophy. Once it is enabled, the agent may only search and read. It produces a plan and an impact analysis without writing anything to disk. This turns “gather evidence first, then act” into a hard constraint and substantially lowers the chance of regressions.

    Context separation: isolating contamination with sub-agents

    The most common failure mode of large models on engineering tasks is piling “finding clues, reading the repository, writing the implementation, running verification, and explaining causes” into a single context window. As rounds accumulate, the window fills with repeated file fragments, failure logs, and intermediate guesses. The signal-to-noise ratio drops quickly, and the model starts forgetting constraints, repeating work, or even contradicting itself.

    The essence of the sub-agent mechanism is context isolation: assign separate contexts, separate tool sets, and separate permissions to different responsibilities, and return only conclusions to the main session. A typical division looks like this:

    Role Responsibility Tool constraints What it returns
    Explorer Search symbols, references, and configuration Read-only Key file list and location findings
    Planner Design the approach and assess impact Read-only Step plan and risk points
    Executor Modify files and run commands Read/write plus controlled execution Change summary and verification output
    Main session Make decisions and trade-offs Aggregated permissions Final plan and status

    The engineering benefits show up in three places: the main context stays lean, so long tasks drift less; parallel exploration shortens the time needed to locate things; and permissions can be narrowed per role, reducing the surface for mistakes. In practice, returned information also needs to be structured, for example returning only paths, symbol names, failing assertions, and conclusions rather than entire logs.

    The verification loop: making “it runs” the delivery gate

    Generation is only an intermediate state. A reliable implementation closes the loop on verification. From weakest to strongest, the common layers are: syntax and static checks pass, unit tests pass, relevant integration cases pass, key end-to-end paths pass, and performance and security baselines do not regress.

    A practical loop design:

    1. change -> static checks -> affected test selection -> targeted tests -> full regression (optional)
    2. -> on failure, minimize the reproduction and feed it back into context -> replan

    “Affected test selection” determines cost: pick relevant tests based on changed files and the dependency graph, run a small set first for fast feedback, then decide whether to widen the scope. Failure information should be compressed into actionable clues, such as assertions, key stack frames, and reproduction commands, to avoid contaminating the main context.

    Adoption advice and common anti-patterns

    A four-step path works well: first, accumulate understanding of the repository in read-only planning mode; then, validate permissions and the verification loop with a very small task; next, introduce role-based sub-agents to share the retrieval load; finally, connect general cloud capabilities such as static checks, test and log monitoring, and alerting into the loop to form a sustainable quality baseline.

    Common anti-patterns include: delivering too large a task in one shot, skipping verification before merging, stuffing all logs back into the main context, leaving permissions fully permissive for a long time, and lacking change auditing. The way to avoid them is to tighten task granularity, the verification gate, and the scope of authorization at the same time.

    In summary, the principle of a repository-level AI coding agent can be compressed into one sentence: a continuously running main loop, operating within explicit permission boundaries, drives an engineering loop that ends in verification through role-based collaboration with isolated contexts. The model sets the ceiling, the runtime sets the floor, and the latter is the main source of engineering stability.