How Repository-Level AI Coding Agents Work: A Technical Breakdown

    This article breaks down the technical architecture of repository-level AI coding agents, arguing that their competitiveness comes from the runtime surrounding the model rather than from single-point model capability. It explains four core layers: the main loop of read, plan, tool invocation, and write-back; permission boundaries implemented as a first-class runtime capability; context separation through sub-agents; and a verification loop that determines whether output is deliverable. It also covers common misconceptions and practical recommendations, offering developers and enterprises a clear architectural reference for building auditable and rollback-capable engineering workflows.

    1. The Bottom Line: Competitiveness Comes from the Runtime, Not Single-Point Model Capability

    When discussing repository-level AI coding tools, the most common misjudgment is attributing all effectiveness to “the model is simply better at writing code.” An explanation closer to engineering reality is that the model is only the decision-making core; what truly determines usability is the runtime wrapped around the model. This runtime is responsible for scheduling context, constraining actions, invoking tools, and collecting feedback, enabling a single session to keep advancing across multiple files and multiple steps.

    The two can be compared to an “engine” and a “complete vehicle.” Engine power sets the upper limit, but the transmission, brakes, chassis, and dashboard together determine whether the car can safely finish the entire journey. AI coding tools work the same way: without a runtime, model output is just a suggestion; with a runtime, suggestions can be verified, rolled back, and constrained.

    From an engineering evolution perspective, the fact that this class of tools has achieved relatively high adoption in a short time shows that it benefits from workflow gains: information that originally had to be carried by a human across multiple windows is consolidated into a single traceable execution chain.

    2. Layer One: The Main Loop Is a Closed Cycle of Read, Plan, Invoke, and Write-Back

    The interaction unit of traditional code completion is “a snippet of text near the current cursor,” with the goal of producing candidates with low latency. The interaction unit of a repository-level tool is “a task,” with the goal of advancing the task to a verifiable state. Its main loop typically consists of four stages:

    1. Read context: locate relevant files, dependencies, configuration, and test entry points;
    2. Form a plan: break the task into ordered steps and clarify the expected result of each step;
    3. Invoke tools: read and write files, search symbols, execute commands, and run tests;
    4. Write back results: bring tool output back into the context, revise the plan, or move to the next step.

    Illustrative pseudocode:

    1. while not done(task):
    2. ctx = collect_context(task) # Read
    3. plan = update_plan(ctx, task) # Plan
    4. result = call_tools(plan) # Invoke
    5. task = merge(task, result) # Write back
    6. if blocked(task): ask_human()

    The key design of this loop is the “write-back.” Many failures are not because the model cannot write code, but because tool output is not structurally merged into subsequent reasoning, leading to duplicated work or self-contradiction. Mature implementations trim and summarize output, keeping only the evidence relevant to the current step.

    3. Layer Two: Permission Boundaries Are a System Capability, Not a Prompt Constraint

    The real risk of AI coding is not “failing to write code,” but “writing without seeing the boundaries clearly, writing beyond authority, or writing something that cannot be rolled back.” Therefore, permissions must be implemented as a first-class runtime capability, not as a sentence saying “please operate carefully.”

    A common layered approach to permissions includes: default mode (each sensitive action requires confirmation), auto-accept edits mode (confirmation-free within a limited scope), plan mode (read-only research, no writes to disk), and a higher-risk skip-confirmation mode (used only in isolated environments). The most valuable here is plan mode: it enforces “gather evidence first, modify later,” significantly reducing the probability of “fixing A and breaking B.”

    In engineering, permission decisions can be abstracted as a pure function, making them easy to audit and test:

    1. def decide(action, mode, scope) -> Decision:
    2. if action.kind == "read":
    3. return ALLOW
    4. if action.kind == "write" and action.path in scope:
    5. return ALLOW if mode in ("accept_edits", "auto") else ASK
    6. if action.kind in ("network", "deploy", "delete"):
    7. return ASK if mode != "isolated" else ALLOW
    8. return DENY

    There are three supporting practices: first, least privilege, limiting the writable set by repository subdirectory or task scope; second, rollback capability, with all changes made as patches or version-control units; third, auditability, recording each tool invocation as a structured log for later review.

    4. Layer Three: Context Division of Labor, Using Sub-Agents to Isolate Contamination

    The place where engineering tasks most easily fall apart is stuffing “finding clues, reading the repository, writing the implementation, running verification, and explaining reasons” all into the same context window. As entries accumulate, the noise ratio rises, the model’s attention is diluted, and problems emerge such as forgetting constraints, duplicate implementation, and mistakenly citing old conclusions.

    The essence of the sub-agent mechanism is context isolation: assigning independent contexts, independent tool sets, and independent permissions to different responsibilities. For example, a read-only exploration agent handles retrieval and localization, a planning agent produces steps and acceptance criteria, and the main session retains only key decisions and final results. The content returned to the main session should be compressed conclusions, not raw logs.

    A practical split example:

    Role Permission Output
    Exploration agent Read-only List of relevant files and call chains
    Planning agent Read-only Steps, risks, acceptance criteria
    Implementation agent Writable within a limited directory Patches and change descriptions
    Verification agent Can execute tests Failing cases and localization clues

    This division of labor brings three benefits: cleaner context, more tightly scoped permissions, and the ability to retry failures locally without contaminating the whole.

    5. Layer Four: The Verification Loop Determines “Deliverable” Rather Than “Looks Right”

    Code generation without a verification loop is just text. Repository-level tools must incorporate tests, static checks, and type checks into the loop, using “reproducible failures” as input for the next step. The recommended approach is: first write or locate a minimal reproduction case, then make the minimal change, and finally regress the relevant test suite. Acceptance criteria should be clarified at the planning stage, for example, “the new case passes and existing tests are not broken.”

    When adopting this in a team, the verification loop can be connected to continuous integration: the local loop handles fast feedback, while the pipeline handles full regression; at the same time, log services and monitoring alerts can be used to observe the success rate and latency of tool invocations, identifying whether the issue is insufficient context, blocked permissions, or a missing environment.

    6. Common Misconceptions and Practical Recommendations

    • Misconception one: treating prompts as guardrails. Permissions and rollback must be guaranteed by the runtime.
    • Misconception two: pursuing a one-shot result. Tasks should be broken into small pieces and advanced in verifiable increments.
    • Misconception three: the larger the context, the better. Compression and isolation should be applied proactively, retaining decision-relevant information.
    • Practical recommendations: enable high-freedom modes first in an isolated branch or container platform, and use plan mode by default; set a whitelist for the writable scope; write acceptance criteria into the task description; produce structured summaries of tool output.

    7. Conclusion

    The technical principles of repository-level AI coding tools can be summarized as: driving task progress with the main loop, controlling risk with permission boundaries, isolating context with sub-agents, and ensuring deliverability with the verification loop. Model capability determines the upper limit, while runtime design determines the lower limit. Understanding these four layers can help developers use such tools more efficiently and provide enterprises with a clear architectural reference when building internal R&D assistants, for example, combining container platforms, log services, and monitoring alerts on Baidu AI Cloud to build an auditable, rollback-capable engineering closed loop.