Deconstructing Repository-Level Coding Agents: Technical Architecture and Principles

    This article breaks down the technical architecture behind repository-level coding agents, moving beyond the misconception that they are simply smarter LLMs. It explores four core layers of the agent runtime system: the main execution loop, permission boundaries, context division using sub-agents, and automated verification loops. Understanding these mechanisms provides a clear framework for evaluating or building enterprise-grade AI programming systems.

    1. Dispelling a Misconception: It’s Not Just About Better Coding Models

    Many assume that AI coding agents can handle entire repositories simply because the underlying models have become more capable at writing code. From an architectural perspective, however, the real shift isn’t the model’s inherent ability, but the maturity of the engineering encapsulation around it. The model still completes tasks by generating text and calling tools. What transitions “AI programming” from snippet-level to repository-level is a runtime system built around the model. This system dictates what the model can see, what it can modify, when it must pause for human input, and how its results are verified.

    This runtime can be deconstructed into four layers: the main loop, permission boundaries, context division, and the verification loop.

    2. The Main Loop: From Completion to “Context -> Plan -> Tool -> Write”

    Consider IDE-embedded AI assistants. Their interaction paradigm focuses on code completion, chat, and localized modifications. The model’s output typically lands near the cursor, with context limited to the current file.

    In contrast, a terminal-based repository-level agent is driven by a continuously running loop:

    1. while (task_not_complete) {
    2. observe_context // Read codebase, logs, test outputs
    3. make_plan // List todos, break down steps
    4. call_tools // Read/write files, execute commands, run tests
    5. observe_results // Verify if expectations are met
    6. revise_plan // Adjust next step based on feedback
    7. }

    This loop fundamentally differs from chat-based generation in three ways:

    1. Task Granularity: Chat-based generation aims to produce a code snippet from a single prompt. An agent targets completing an engineering task spanning multiple files, requiring proactive exploration of the codebase structure.
    2. Feedback Loop: Agents can execute commands and run tests, using real execution results as input for the next decision cycle, rather than relying on manual copy-pasting.
    3. State Management: Agents maintain a todo list, ticking off items as they progress, which prevents losing track of the objective during long tasks.

    This is why a repository-level agent feels less like an IDE plugin and more like an engineering assistant living in your terminal, capable of continuous work.

    3. Permission Boundaries: Systemizing “What Can Be Done”

    The real risk with AI programming isn’t that it “can’t write code,” but that it writes carelessly, exceeds its authority, or modifies code without understanding boundaries. Therefore, mature agent designs do not grant default access. Instead, they explicitly model permission modes as a system capability. Typical designs offer a spectrum of modes, from strict to loose:

    • Read-only Planning Mode: Only allows reading code and researching; no write operations are executed.
    • Controlled Editing Mode: Allows file modifications, but high-risk actions like executing commands require human confirmation.
    • Auto-Accept Mode: Automatically executes within a defined scope; asks for permission outside those bounds.
    • Full Access Mode: No interception; only suitable for isolated environments (e.g., CI containers, disposable VMs).

    The “Read-only Planning Mode” best reflects the underlying design philosophy. In this mode, the agent first reads the code, understands dependencies, gathers evidence, and produces a modification plan. Execution only begins after human confirmation. This approach inherently reduces the probability of “fixing A but breaking B”—gathering evidence before acting stands in stark contrast to the reckless “generate first, look later” approach.

    From a security engineering perspective, this layer implements the Principle of Least Privilege: before each loop iteration begins, the system decides what the agent can see, what it can change, and which actions require human approval. Permission modes represent a fundamentally different product philosophy compared to chat-based code generation.

    Practical tip: Use different permission levels in environments with varying levels of trust. For example, use controlled editing for local development, and reserve full access for isolated containers. Never use a guardrail-free mode in production-accessible environments.

    4. Context Division: Combating Context Pollution with Sub-Agents

    The most common point of failure for LLMs handling engineering tasks is cramming everything—finding clues, understanding the repository, writing implementations, running verifications, and explaining reasons—into a single context window. As the conversation grows longer, early conclusions are diluted, irrelevant details pile up, and instructions interfere with one another. This is context pollution.

    The solution is a sub-agent mechanism, which essentially provides context isolation. A large, messy task is divided among smaller agents with independent contexts, tool constraints, and permissions. A typical division of labor looks like this:

    • Exploration Sub-Agent: Read-only access. Responsible for retrieving and mapping the repository structure. It returns only conclusions (not raw file contents) to the main session.
    • Planning Sub-Agent: Responsible for researching approaches and breaking down steps, outputting a structured plan.
    • Main Session: Retains only key decisions and final deliverables, keeping the context clean.

    A single exploration might read dozens of files, but the main session ultimately receives only a few hundred words of summary. This is where pollution is cut off. The core idea can be summarized as: Rather than doing everything in one dirty context, split the work across multiple clean contexts, each handling one thing, then aggregate the conclusions.

    5. Verification Loops: Letting Machines Determine “Correctness”

    The final piece of the puzzle is verification. An agent without a verification loop only “looks like it finished”; an agent with a verification loop can be “proven to have finished correctly.” Universal best practices include:

    1. Tests as the Anchor: Have the agent automatically run unit tests and build commands after modifications, using exit codes and output as hard signals.
    2. Static Checks as a Fallback: Integrate standard toolchains like type checkers and linters to catch issues that tests might miss.
    3. Failure as Input: Feed error messages directly back into the model, forming an automatic convergence loop of “modify -> test -> fix.”
    4. Human Checkpoints: Set explicit human confirmations for irreversible operations (deletions, deployments, data changes).

    6. Conclusion

    The technical principles behind terminal-based coding agents are not mysterious. They don’t rely on the model suddenly becoming smarter, but rather wrap the model in a software engineering runtime. The main loop ensures continuous task progression; permission boundaries secure the safety baseline; context division combats pollution; and verification loops guarantee trustworthy results. Once you understand these four layers, you have a clear reference framework—whether for evaluating such tools or building your own agent systems.