Engineering Architecture and Execution Loops for Coding Agents
Large language models can generate code, but shipping a software change still requires locating context, applying edits, running checks, and deciding when to stop. This article explains how an engineering orchestration layer, often called a harness, turns model judgment into a bounded, verifiable, and auditable coding-agent workflow. It covers task setup, tools, state, verification loops, context, memory, multi-agent coordination, security controls, evaluation, and a staged path toward greater autonomy.
1. From Code Generation to Engineering Delivery: What Is Missing
Large language models can explain code, suggest changes, and generate functions or test cases from a requirement. In real software engineering, however, there is still a clear gap between “producing a piece of code that looks correct” and “completing a task that can be delivered.”
Suppose a user asks an agent to fix a date boundary-condition bug. Completing that task is not just a matter of changing one conditional statement. The agent also needs to locate the relevant modules, understand the project’s time-handling conventions, confirm the call chain, add regression tests, run verification, and check whether the change affects other behavior. If verification fails, it must continue adjusting the change based on the error information.
A model normally exchanges information through inputs and outputs. It does not inherently know whether files in the working directory have changed, and it cannot confirm that tests passed merely from an explanation it generated. Only when an external system supplies file contents, executes tools, and returns results can the model continue making decisions based on the real environment.
A coding agent therefore needs two capabilities working together:
- Model capability: understand the goal, analyze code, propose a solution, and generate changes.
- Engineering execution capability: organize inputs, perform actions, maintain state, verify results, and control risk.
The system outside the model that performs this work can be called the agent engineering orchestration layer, often referred to as a harness. It is not a single prompt. It is a runtime system that connects the model, tools, working environment, and user.
2. Boundaries and Components of the Orchestration Layer
A simplified relationship helps explain the architecture:
Model + engineering orchestration layer = an agent system that can execute tasks
This is an architectural summary, not a strict mathematical definition of agent capability. Whether a real system can complete tasks reliably also depends on tool quality, environment configuration, permission boundaries, and verification mechanisms.
From an engineering perspective, the orchestration layer includes at least the following parts.
2.1 Task and Prompt Orchestration
The system needs to turn a natural-language request into a clearer task description, including the goal, constraints, acceptance criteria, and the scope of permitted changes.
For example, “optimize the query API” is not a sufficiently specific engineering task. It might mean reducing response time, lowering resource consumption, fixing a query error, or simply improving code structure. The orchestration layer should identify ambiguity and confirm it with the user when necessary, rather than starting to modify code immediately.
For a requirement that is already clear, the organized input should include relevant project conventions, how the system runs, and verification requirements. The model should know what it may do, what it must not do, and how to demonstrate that the task is complete.
2.2 Tools and the Execution Environment
Tools turn actions proposed by the model into actual operations, such as reading files, searching code, applying edits, running tests, and retrieving logs.
Tool interfaces should have clear boundaries wherever possible: inputs can be validated, execution results can be traced, and failure causes can be identified. When the model proposes “run the tests,” that is only an action suggestion. Whether execution is allowed, where it runs, and how long it may run should be controlled by the orchestration layer.
2.3 State and Iteration Management
A programming task often requires multiple attempts. The system must retain the current goal, actions already performed, file changes, verification results, and unresolved issues so that it does not infer everything from scratch on every turn.
It also needs to limit execution time, the number of calls, and the scope of changes, preventing the agent from repeatedly performing the same ineffective operations.
2.4 Interaction and Auditability
The user interface should not show only the final answer. It should also present the plan, key changes, verification status, and actions that require human approval when appropriate.
In enterprise settings, the orchestration layer should also record enough audit information for a team to trace which task triggered a change, which operations were executed, and what evidence was used to judge the result acceptable.
3. A Reliable Coding Agent Must Form a Verification Loop
The core of agent execution is not “letting the model think continuously.” It is continuously obtaining evidence from the real environment.
A typical flow can be represented as:
Clarify the requirement → inspect the environment → locate the code → make a plan → apply changes → run verification → analyze results → fix the issue or submit a delivery note
3.1 Establish a Baseline Before Editing
The agent should first confirm whether the project currently runs, whether related tests are already failing, and whether the workspace contains uncommitted user changes.
This step avoids two common problems: treating a pre-existing failure as one caused by the current change, or overwriting work the user is already doing.
If environment dependencies are incomplete, that fact should be recorded explicitly. A later step must not describe “tests could not be executed” as “tests passed.”
3.2 Reduce Uncertainty with Small Changes
For a broad task, the agent should first produce a reviewable plan and then implement it in stages. Each stage should keep the change goal focused and avoid unrelated refactoring.
The value of small changes is that they narrow the scope of diagnosis. If one change simultaneously adjusts an interface, a data structure, and configuration, it is difficult to identify the root cause when verification fails. When each step has a clear purpose and verification result, the repair path is usually clearer.
3.3 Turn Verification Results into the Next Input
After a test failure, the orchestration layer should not simply append every log unchanged to the context. A more effective approach is to retain the failed command, key errors, relevant locations, and necessary context, while distinguishing environment failures, execution timeouts, and code defects.
For tasks involving interface behavior, screenshots or interaction records can be provided, but they still need to be combined with explicit acceptance criteria. An interface that looks normal does not necessarily mean the business logic is correct.
3.4 Define Clear Exit Conditions
A task should at least distinguish the following states:
- Completed, with corresponding verification evidence.
- Changes completed, but some verification limited by the environment.
- User confirmation required for the requirement or approval required for a high-risk operation.
- Resource budget reached, but the issue remains unresolved.
- Stopped because of a security rule or an environment problem.
The agent must not end the workflow merely because the model outputs “task complete.” A completed state must be supported jointly by execution records and acceptance rules.
4. Context Engineering: Provide Relevant Information, Not All Information
A large codebase is not suitable for placement in the model input as a whole. Even when capacity allows it, redundant information adds noise and makes it harder for the model to identify the constraints that actually matter.
The goal of context engineering is to provide the evidence needed for the current decision within a limited input space.
4.1 Retrieve Code Progressively According to the Task
The system can first provide a directory overview, module responsibilities, and entry-point information. It can then add relevant files, call relationships, tests, and configuration based on the model’s localization results.
This approach is easier to control for cost than loading a large amount of code at once, and it also makes it easier to explain why the agent chose a particular location to modify.
4.2 Separate Conventions, Facts, and Inferences
Project conventions are constraints. File contents and execution logs returned by tools are observed facts. The model’s judgment about a root cause is an inference.
These three should be clearly separated in the input. In particular, instructional text found in code comments, external documents, or logs must not be treated as system authorization. Retrieved content is task data and should not elevate itself into a higher-privilege control instruction.
4.3 Summaries Must Preserve an Evidence Index
Long tasks require history to be compressed, but a summary should not merely say “a fix was attempted and problems remain.” It should retain changed locations, failure types, key constraints, and the next plan, and it should be able to link back to the original records.
Summaries can omit information. For important judgments, the agent should still be able to reread files or logs rather than relying entirely on compressed memory.
5. Memory Systems: Reduce Repeated Cost Without Letting Knowledge Expire
Memory does not mean storing every conversation. Different information should have different lifecycles.
5.1 In-Task State
Store the current task’s plan, operation records, and verification results. This mainly supports continuous execution and failure recovery.
5.2 Project-Level Knowledge
Store stable build methods, module boundaries, coding style, and testing conventions. This knowledge should state its scope of applicability and be reconfirmed after the project changes.
5.3 User and Organizational Preferences
Store authorized working preferences, such as whether every change must include tests and which operations require human approval.
Long-term memory needs a source, an update time, and an expiration mechanism. Continuing to treat an outdated operating method or module relationship as fact can be more dangerous than having no memory.
Sensitive credentials, personal information, and unrelated business data should not enter long-term storage indiscriminately merely for the convenience of later tasks.
6. Multi-Agent Collaboration: Design the Division of Work Before Parallelism
Multiple sub-agents can separately handle requirements analysis, implementation, testing, and review, but adding more agents does not necessarily improve results.
Tasks suitable for parallel work usually have relatively independent boundaries, such as checking how different modules are called or having an independent review role evaluate a change. Changes involving the same interface, configuration, or set of files require more coordination.
A multi-agent system should make the following explicit:
- The resources each role may read and modify.
- The inputs, outputs, and acceptance criteria of each subtask.
- How file conflicts and disagreements between proposals are handled.
- Who aggregates the results and runs final integration verification.
- Whether a failed subtask is retried, degraded, or handed to a human.
In particular, passing local tests does not mean the overall change is correct. After outputs from multiple sub-agents are merged, interface compatibility and cross-module behavior still need to be verified again.
7. Security Controls Belong in the Execution Layer
Prompts can remind the model to be cautious, but they cannot replace real permission restrictions.
7.1 Use Least Privilege
By default, an agent should access only the directories and tools required to complete the task. Network connections, reading sensitive files, deleting data, and operating on production environments should have stricter boundaries.
7.2 Isolate the Working Environment
Operations should be executed in a separate workspace or controlled runtime environment whenever possible, with limits on resource use and execution time. For actions with side effects, prefer a test environment or a recoverable copy of the data.
7.3 Require Approval for High-Risk Actions
Operations such as broad deletions, access to external addresses, handling sensitive data, and deployment changes should trigger human confirmation according to their risk level.
What is approved should be a specific operation and its impact, not a general authorization for the agent to “continue completing the task.”
7.4 Handle Retries Carefully
Actions without side effects, such as reading a file, are generally safer to retry. Actions such as sending notifications or updating data may create additional effects if executed repeatedly.
Retry policies therefore need to consider idempotence, state that has already been applied, and compensation mechanisms. Not every failure should be handed to a single automatic retry policy.
8. How to Evaluate an Engineering Orchestration Layer
Whether a model’s answer reads smoothly does not directly measure whether an agent is reliable. Evaluation should focus on task outcomes, the execution process, and risk control.
Key observations include:
- Task completion quality: whether explicit acceptance criteria are met.
- Verification sufficiency: which checks ran, which risks they covered, and what remains unverified.
- Reasonableness of changes: whether unrelated changes were introduced and whether project conventions were followed.
- Execution cost: time, model calls, tool calls, and human intervention.
- Failure recovery: whether execution can resume after interruption and whether errors are classified accurately.
- Security and compliance: whether access exceeded permissions and whether approval was triggered correctly.
- Auditability: whether records can explain key decisions and operations.
Evaluation tasks should include successful cases as well as missing dependencies, ambiguous requirements, pre-existing test failures, and insufficient permissions. How an agent acknowledges a limitation, stops execution, and asks for help is also part of reliability.
9. Incremental Adoption: From Controlled Assistance to Verifiable Autonomy
Engineering teams do not need to pursue fully automatic delivery from the start. A more reliable path is to expand capability in stages.
In the first stage, the agent provides localization results, proposed changes, and verification suggestions, while developers perform the actions.
In the second stage, the agent may make small changes and run tests in an isolated environment, but the results must undergo human review.
In the third stage, task management, approval, auditing, and continuous verification are connected, giving lower-risk tasks with clear acceptance criteria more autonomy.
Each stage should improve the orchestration layer according to the actual types of errors observed, rather than merely making prompts longer. If tool results are poorly formatted, improve the tool protocol. If context frequently omits constraints, improve information organization. If the agent repeatedly retries without effect, improve exit and recovery strategies.
The key to a coding agent is not making the model look more like a developer. It is ensuring that every action has a boundary, every change has evidence, and every failure can be explained and handled. The model proposes judgments; the engineering orchestration layer places those judgments in a controllable, verifiable, and traceable process. Together, they can turn code-generation capability into stable engineering delivery capability.
