How Repository-Level AI Coding Agents Work: Runtime Architecture Explained

    This article breaks down the technical architecture behind repository-level AI coding agents, arguing that their capability leap comes from the runtime layer rather than the model alone. It explains four interlocking components: the agent main loop that replaces code completion, permission boundaries enforced as system capabilities, context separation through sub-agents, and verification loops that make results falsifiable. The article also includes practical guidance for adopting these tools safely within a team engineering workflow.

    1. Key Takeaway: The Capability Leap Comes from the Runtime, Not a Single Model

    When discussing repository-level AI coding tools, the most common misjudgment is attributing all quality improvements to “the model just got better at writing code.” A more accurate assessment is that model capability is only a necessary condition. What truly determines the experience and output quality is the runtime layer wrapped around the model. This layer schedules context, constrains actions, invokes tools, collects evidence, and drives iteration.

    Broken down, this runtime consists of four interlocking parts:

    • Main loop: upgraded from “completion” to a continuous cycle of “read context → make a plan → call tools → write back results”;
    • Permission boundaries: making “what the agent is allowed to do” a system capability rather than relying on prompt-level self-discipline;
    • Context separation: using sub-agents to isolate distinct responsibilities such as retrieval, implementation, and verification, reducing context pollution;
    • Verification loop: forming a closed loop with tests, static checks, and diff review so that results can be falsified.

    Note that this article does not evaluate or recommend any specific product. Instead, it explains the general engineering paradigm behind this class of tools. Any mention of usage-rate changes serves only as background context that “the engineering workflow dividend is real,” drawn from publicly available developer survey-type information. Readers should not treat it as precise data.

    2. Main Loop: From Code Completion to a Repository-Level Agent Loop

    Traditional intelligent completion works like a “front-seat copilot”: accept a suggestion when one appears near the cursor, keep typing manually when none does. The interaction unit is “one completion.” For repository-level tools, the smallest interaction unit is “a task,” and internally it is an uninterrupted loop.

    A typical loop can be abstracted as:

    1. while not task_done:
    2. ctx = collect_context(task, repo_index) # retrieve relevant files, symbols, and change history
    3. plan = update_plan(ctx, task) # maintain todos and dependency order
    4. action = choose_action(plan, policy) # read file/write file/run command/run test
    5. result = execute(action, sandbox=policy) # execute under permission boundaries
    6. memory = fold(result, ctx) # compress into conclusions, not raw text piles
    7. task_done = verify(memory, task) # use the verification loop to judge convergence

    There are three easily overlooked design points here.

    First, retrieval precedes generation. Most repository-level task failures are not because the model “can’t write code,” but because it “didn’t see the key constraints”: a seemingly simple change may affect interface contracts, configuration defaults, database migration scripts, or frontend compatibility logic. Building a repository index and symbol relationships before writing can significantly reduce “fix A, break B” outcomes.

    Second, the plan is an explicit intermediate artifact that humans can intervene in. The todo list is not decoration; it makes long tasks interruptible, resumable, and auditable. Humans can correct course at the planning stage at a far lower cost than reworking at the code stage.

    Third, the action space is enumerated. Tool calls are not free text but a finite set (read, write, retrieve, execute commands, run tests, and so on). The smaller the action space, the easier it is to enforce permission control, log auditing, and failure retries.

    This is also why many people feel on first contact that “it doesn’t behave like an editor plugin”: it is more like an engineering assistant placed inside the terminal, where the interaction unit is tasks and plans rather than a single completion.

    3. Permission Boundaries: Making Security a System Capability

    In terms of permission design, this class of tools typically offers multiple modes, ranging from read-only research, auto-accept edits, and plan mode, to step-by-step confirmation and fully open execution modes. Naming varies by vendor, but abstractly it is the same thing: first decide “what the agent gets to see this round, what it can modify, and which actions must stop and ask a human.”

    Why is this a foundational guardrail? Because the real risk in AI coding is not “failing to write code,” but three types of overreach:

    • Unauthorized writes: changes that exceed the task boundary and touch unrelated modules or protected configuration;
    • Irreversible actions: deleting data, force-pushing, overwriting history, or modifying production configuration;
    • Hidden side effects: installing dependencies, modifying environment variables, or triggering external calls that produce hard-to-roll-back impacts.

    Making permissions a system capability means constraints happen at the execution layer rather than relying on the model to “remember not to misbehave.” In engineering practice, this is usually combined with the following measures:

    • Path and command allowlists/blocklists to restrict writable directories and high-risk commands;
    • Sandboxes and least-privilege accounts to limit network, filesystem, and credential visibility;
    • Full action audit logs to make it easy to trace “who changed what and when”;
    • Mandatory human confirmation for high-risk actions, forming a human-machine collaboration gate.

    Plan mode especially embodies this philosophy: once in that mode, the tool first does code reading and solution research rather than rushing to write to disk. It essentially uses the order of “collect evidence first, then execute” to reduce the probability of erroneous changes and to make review happen at the lowest-cost stage.

    4. Context Separation: Using Sub-Agents Against Context Pollution

    Stuffing “finding clues, understanding the repository, writing the implementation, running verification, and explaining the reasoning” all into the same context window is the most common way things fall apart: logs, errors, file snippets, and repeated trial-and-error keep piling up, key information gets drowned out by noise, and the model starts forgetting constraints, duplicating work, or even contradicting itself. This is context pollution.

    The solution is not “make the window bigger,” but to separate responsibilities and compress context:

    • The retrieval sub-agent is only responsible for locating evidence, returning conclusions and file locations rather than entire blocks of source text;
    • The implementation sub-agent only receives summaries and interface contracts directly relevant to the change;
    • The verification sub-agent independently runs tests and static checks, returning a failure list and minimal reproduction;
    • The main agent is responsible for aggregation, decision-making, and explaining to humans, keeping its context lean.
    1. Main agent (decision/aggregation)
    2. ├─ Retrieval sub-agent: locate call chains, config items, change history → return conclusions
    3. ├─ Implementation sub-agent: produce patches per interface contracts → return diffs
    4. └─ Verification sub-agent: run tests/static checks → return failures and reproductions

    Supporting engineering measures also include: segmenting long tasks and persisting intermediate conclusions to disk, applying structured trimming to logs, slicing large files by symbol for retrieval, and injecting stable project conventions at session start (build method, directory responsibilities, coding standards). The goal is to turn “context” from a running log into a chain of evidence.

    5. Verification Loop: Making Results Falsifiable

    An agent without a verification loop is just a faster text generator. A reliable implementation must define “done” as “passed verification,” not “generation finished.” A working closed loop typically includes:

    1. Static checks and type checks to eliminate low-level errors first;
    2. Unit tests and integration tests covering the changed path and the regression path;
    3. Diff review, checking line by line whether changes overstep boundaries or introduce unnecessary refactoring;
    4. Failure feedback, feeding compressed failure information back into the loop to form a “hypothesize—verify—correct” iteration.

    Illustration:

    1. # Pseudocode: verification loop
    2. run_lint_and_typecheck() # fast feedback
    3. run_tests(changed_modules) # targeted verification
    4. if failed:
    5. feedback = summarize_failure(logs) # compress noise, keep only key stack and assertions
    6. feed_back_to_agent(feedback)
    7. else:
    8. request_human_review(diff) # high-risk changes still need human review

    The key metric here is not “how many lines were generated,” but first-pass rate, regression introduction rate, average convergence rounds, and the proportion of human rework. Only by wiring these metrics into logging services and monitoring alerts can you continuously improve prompts, retrieval strategies, and permission tiers.

    6. Implementation Advice: Turning the Tool into an Engineering System

    To adopt this capability within a team, it is recommended to proceed in the following order:

    • First build a repository index and project convention docs so retrieval has a reliable basis;
    • Default to read-only or plan mode, and only open up writes after review approval;
    • Isolate the execution environment with container platforms or sandboxes, and issue credentials with least privilege;
    • Integrate tests and static checks into continuous integration as the foundation of the verification loop;
    • Use logs and monitoring to measure convergence efficiency rather than relying only on subjective perception;
    • Keep human gates for high-risk actions to form clear responsibility boundaries.

    In summary: the competitiveness of repository-level AI coding tools comes from this runtime design of “main loop + permission boundaries + context separation + verification loop.” Understanding these four layers both explains why they differ from completion plugins and helps teams convert the engineering workflow dividend into delivery efficiency under safe and controllable conditions.