Layered Architecture and Verification Loops for AI Coding Agents
This article explains how to design AI coding agents as engineered systems. It breaks agent design into five capability surfaces: context, action, control, isolation, and verification. It also covers the collect, act, verify, and roll back loop, common symptoms of unbalanced designs, practical configuration principles, and a checklist for diagnosing unstable agent behavior.
1. The Starting Point: An Agent Is Not a Single Q&A Exchange
Many teams adopting AI coding agents first focus on output quality: whether the code looks reasonable, whether the explanations are clear, and whether completions are accurate. After real use, however, the bottleneck is usually not that the model lacks intelligence. The system design is incomplete. A typical Q&A exchange takes one input and produces one output. A coding agent runs a multi-step loop. It reads context, chooses an action, modifies files, runs checks, corrects itself based on feedback, and continues until the task is complete or it has to back out. If any step is missing, the agent shows engineering problems. The team may find that the agent writes code well but they do not dare let it make changes, that they cannot tell whether its changes are correct, or that they cannot undo a mistake.
A better way to think about a coding agent is not as a longer chat window. Break it into several capability surfaces: which information is always present, which capabilities are available, which actions must be restricted, which tasks need isolation, and how to decide that a task is complete and the result is trustworthy. This article organizes the discussion around five surfaces: context, action, control, isolation, and verification. Long-term rules and memory belong to the context surface. The agent loop runs across all five surfaces.
2. Five Capability Surfaces: Missing One Layer Throws the System Off Balance
1. Context Surface: Telling the Agent What It Is and Why
The context surface handles information supply. It usually includes two types of context: always-loaded context and on-demand context. Always-loaded context covers project constraints, directory conventions, coding standards, domain terms, prohibited actions, and key design decisions. On-demand context covers task templates, troubleshooting playbooks, interface descriptions, and historical change records.
More context is not always better. Overly long resident content pollutes the agent’s judgment. Conflicting rules, irrelevant details that bury key constraints, and outdated documents treated as facts all cause problems. A safer approach keeps resident context minimal, loads it in layers, retrieves it on demand, cleans it up regularly, and makes each rule as executable and verifiable as possible.
For example, the always-loaded context should keep only the boundaries that must be followed and the conventions used most often. Low-frequency material goes into an on-demand area. When the agent starts a specific task, it pulls the relevant module documentation instead of loading the whole knowledge base at the start. This reduces context noise, token cost, and reasoning interference.
2. Action Surface: Telling the Agent What It Can Do
The action surface is the set of capabilities that let the agent interact with the codebase and runtime environment. These include reading files, searching symbols, editing files, running tests, building the project, querying logs, and calling external services.
More capabilities raise the agent’s potential ceiling, but they also make selection harder. Too many tools, vague descriptions, and unclear parameter boundaries cause the agent to try different tools repeatedly, and it may even misuse high-privilege actions. Action design should follow several principles: clear capability categories, descriptions written around usage scenarios, constrained parameters, structured results, tiered risk levels for high-risk actions, and idempotent, retryable behavior where possible.
The action surface involves more than connecting a few extra tools. Each action should answer three questions. What task does it solve? What understandable information does it return on failure? What permissions does it need? If an action returns large blocks of unstructured text, the agent has difficulty correcting itself. If an action has no permission label, the control surface cannot intercept it effectively.
3. Control Surface: Deciding Which Actions Must Be Constrained, Blocked, or Audited
The control surface handles permissions, sandboxing, forced interception, approval, and auditing. The key point is that the system cannot rely entirely on the agent to decide when to stop. For high-risk actions such as reading credentials, writing to production, making bulk changes, and accessing the network, the system layer should enforce rules: allow, deny, require approval, or record. Controls must apply up front, not as a fix after the fact. Discovering that the agent changed files it should not have touched usually costs more than blocking the change in advance.
The control surface should also keep an auditable trail. The trail records who started the task, which context the agent read, which actions it ran, which gates it triggered, and what the result was. Auditing does not exist to add bureaucracy. It helps locate the cause when something fails and gives reviewers the evidence to improve the rules.
4. Isolation Surface: Deciding Which Tasks Need Isolated Context and Permissions
The isolation surface addresses context pollution and permission spread in complex tasks. Common approaches include sub-agents, separate worktrees, and session forks. A main agent handles planning and summarization, while sub-agents carry out specific tasks within a controlled scope. Isolation reduces mutual interference. Too much isolation, however, causes state drift. Each sub-agent acts on a different context, so the summarized conclusions may conflict. Subtasks that finish without being reclaimed also leave resources and state hanging for a long time.
Isolation design needs three things. It needs a clear granularity: isolate by task, by module, or by risk level. It needs a defined lifecycle: create, execute, reclaim, and summarize. It also needs limited permissions, so each sub-agent receives only the minimum capabilities required for its task. More isolation is not automatically better. Isolate what should be isolated, and share what should be shared.
5. Verification Surface: Deciding Whether a Task Is Complete and the Result Is Trustworthy
The verification surface closes the loop in agent engineering. It determines whether the output meets the completion criteria through tests, static checks, builds, screenshot comparisons, log checks, and continuous integration gates. Without a verification surface, an agent can only claim that it is finished. The team cannot judge whether the result is correct, and it cannot roll back when something fails. Verification should run automatically whenever possible. Failure messages should feed back into the next round as context, so the agent returns to gathering information and correcting its work instead of stopping.
The verification surface must also support rollback and auditing. Keep a baseline before changes and revert on failure. Block a merge when a critical gate fails. Link verification results to the action trail so reviewers can check them later. Completion does not mean that the model says the work is done. It means that objective gates pass and the task scope is fully covered.
3. The Agent Loop: Collect, Act, Verify, Roll Back
The core of a coding agent is not answering. It is a process that repeats in a loop:
Collect context -> Take action -> Verify result -> Done^ ||------ failed / insufficient -----|
A simplified state machine can express the same process:
while not done:ctx = collect(task, memory, repo, constraints)plan = choose(ctx, available_capabilities)action = execute(plan, guards)result = verify(action, gates)if result.passed and scope_complete:done = trueelif result.recoverable:memory.add(result.feedback)continueelse:rollback()escalate()
In this loop, the context surface determines what the agent sees, the action surface determines what it can do, the control surface determines what it must not do, the isolation surface determines the scope where it works, and the verification surface determines whether the work is finished. If any surface is missing, the loop degrades. Wrong context leads to wrong direction. Too many actions make selection difficult. Missing controls let risk spread. Poor isolation causes state drift. Missing verification makes the results untrustworthy.
4. Typical Symptoms of Layer Imbalance
Strengthening only one layer throws the system off balance. The table below lists common symptoms to check against:
| Imbalance | Typical symptom | Root cause |
|---|---|---|
| Only the context surface is strengthened | Resident instructions keep growing, and the ag |
