How Repository-Level Coding Agents Work: A Technical Breakdown of the Runtime Design
This article breaks down the technical principles behind repository-level coding agents, arguing that their capability leap comes from the runtime that surrounds the model rather than from model upgrades alone. It explains the four core layers of such systems—the main loop, permission boundaries, context separation through subagents, and the verification loop—and shows how each layer turns raw model reasoning into controllable, observable software engineering. The article also offers practical adoption advice and highlights common misconceptions, making it useful for engineers and teams evaluating agent-based development tools.
1. The Bottom Line: The Capability Leap Comes from the Runtime, Not Just a Better Model
When people discuss AI coding tools, the most common misconception is to attribute all the improvement to the model simply “getting better at writing code.” An explanation closer to engineering reality is that the model has been placed inside a runtime that closely mirrors the software engineering workflow. This runtime is responsible for reading context, constraining the scope of actions, splitting the information load, and feeding results back into a verification stage. The model only handles reasoning and decision-making; the rest of the capability is provided by the system structure.
Looking at industry adoption, the penetration of these tools among developers keeps rising, which suggests they are riding the dividend of engineering workflows rather than being a short-lived gimmick. To understand the technical principles, you can break them into four layers: the main loop, permission boundaries, context separation, and the verification loop. In its practice around intelligent coding and R&D efficiency, Baidu AI Cloud likewise emphasizes packaging model capabilities into a controllable, observable engineering runtime rather than relying on a single prompt.
2. The Main Loop: From “Completing Code” to “Read Context → Plan → Call Tools → Write Back Results”
Traditional intelligent completion behaves more like a front-stage copilot in the IDE. Its focus is completion, conversation, and local edits, and its unit of interaction is “the area around the cursor in the current file.” The unit of interaction for a repository-level agent is the entire codebase and the task goal.
Its main loop usually contains four stages:
- Read context: retrieve the directory structure, dependencies, relevant files, and historical conventions;
- Make a plan: break the task into ordered to-dos and clarify the expected output of each step;
- Call tools: read and write files, execute commands, run tests, search logs, and so on;
- Write back results: bring tool output back into the context and decide whether to continue, roll back, or converge.
Illustrative pseudocode:
while not done:ctx = collect_context(goal, repo_state)plan = model.plan(ctx, todo_list)for step in plan.steps:result = tool.run(step) # constrained by the permission layerctx = merge(ctx, result)done = verify(ctx, acceptance)
The key difference is “continuity.” A completion tool finishes after a single question-and-answer exchange; an agent keeps running until verification passes or human intervention is triggered. This is also why many people feel on first use that it is “not like a plugin,” but rather like placing a working engineering assistant inside the terminal.
3. Permission Boundaries: Making Safety a System Capability, Not a Request in a Prompt
The real risk of AI coding is not “not knowing how to write,” but writing recklessly, writing beyond its authority, or writing without seeing the boundaries clearly. Mature solutions therefore make permission modes an independent layer of system capability. Common mode dimensions include: default mode, auto-accept edits, plan-only, auto-execute, no-ask, and fully open (usually only for isolated environments).
The most valuable design judgment here is: do not grant permissions by default. Instead, first decide “what the agent gets to see this round, what it is allowed to change, and which actions must stop and ask a human.” In engineering terms, this usually comes down to three types of boundaries:
- Read boundary: which directories, secret files, and configurations can be retrieved;
- Write boundary: the allowlist and denylist of paths that may be modified;
- Action boundary: deletions, force pushes, deployments, and billing-related operations must be explicitly confirmed.
Plan-only mode in particular shows the principle at work: after entering this mode, the system first does code reading and solution research without writing changes to disk. This essentially reduces the probability of “fixing A and breaking B”—letting the model gather evidence first, then make changes. Combined with sandbox containers, least-privilege accounts, audit logs, and monitoring alerts, the permission layer turns from a “product option” into governable engineering infrastructure.
4. Context Separation: Using Subagents to Solve Context Pollution
The place where large models most easily fall apart on engineering tasks is cramming “finding clues, understanding the repository, writing the implementation, running verification, and explaining the reasons” all into the same context window. It gets dirtier and dirtier as it accumulates, attention gets diluted, and early constraints get drowned out.
Context isolation is the general solution: different subagents have independent contexts, independent tool constraints, and independent permissions. For example, a retrieval subagent is only responsible for reading the repository and reporting conclusions, a planning subagent is responsible for the solution and a risk list, and the main session only retains key decisions and acceptance criteria.
A typical context flow:
Main session (goal + acceptance criteria)├─ Retrieval subagent → reports relevant files and a call-chain summary├─ Planning subagent → reports the change list and risk points└─ Execution subagent → reports the diff and test results
The key point is “return summaries, not raw logs.” Subagents output structured conclusions, the main session’s context size stays controllable, conclusions are reusable, and it is also convenient to land process data into a logging service for retrospection.
5. The Verification Loop: Only When Results Can Be Checked Do You Dare to Auto-Execute
An agent without a verification loop is just a high-speed generator. Practical systems make acceptance a closed loop: static checks, unit tests, type checks, builds, and necessary end-to-end cases. On failure, the error information is fed back into the main loop, forming a converging process of “execute → verify → fix,” with a maximum iteration count and a rollback strategy to avoid infinite loops.
Engineering recommendations:
- Write acceptance criteria up front as an immutable constraint for the main session;
- Keep changes small and rollback-friendly, advancing only one to-do at a time;
- Keep records of key conclusions to make review and responsibility allocation easier.
6. Adoption Advice and Common Misconceptions
When adopting, first enable restricted permissions in an isolated environment and gradually open them up; write repository conventions into machine-readable rule files to reduce model guessing; and collect tool calls, permission denials, and verification results in a unified way to form an observable closed loop. There are three common misconceptions: treating prompts as guardrails, treating context as an unlimited resource, and treating generation as completion. These four layers—the main loop, permission boundaries, context separation, and the verification loop—are the real technical principles of a repository-level coding agent, and they are also the core dimensions enterprises should focus on when evaluating such capabilities.
