Coding Agent Architecture: The Engineering System Beyond the Model

    This article separates large language models, reasoning models, and agent harnesses to clarify where coding-agent behavior actually comes from. It explains why the same model can perform differently in coding tasks, then examines core components such as repository context management, tool design, prompt-cache stability, memory, and long-session continuity. It also outlines the control loop, discusses engineering trade-offs in security, observability, and evaluation, and closes with practical implementation guidance.

    1. From Model to Agent: Three Distinct Layers

    When people discuss coding capability, they often conflate the model, the reasoning behavior, and the agent product. Separating these three layers is necessary to determine where a problem actually originates.

    A large language model (LLM) is fundamentally a next-token prediction model. It receives text and outputs the most likely continuation. The model itself cannot read or write files, execute commands, or remember past conversations. These capabilities must be provided by external systems.

    A reasoning model is still an LLM, but its training or prompting method makes it spend more inference compute before answering. Typical approaches include multi-step reasoning, self-verification, and selecting among multiple candidate answers. These models are often better at math, logic, and complex code problems, but each call is also more expensive and has higher latency.

    An agent and its agent harness sit at the outermost layer and can be understood as the control loop around the model. The harness decides what to inspect at each step, which tool to call, how to update task state, and when to stop. The model decides what should happen next; the harness turns that judgment into real actions and feeds the results back to the model.

    A rough analogy can summarize this: the LLM is an engine, a reasoning model is a more powerful but less fuel-efficient engine, and the agent harness is the system that allows the engine to drive a vehicle. The analogy is incomplete. Ordinary users can also call a model directly in a chat interface or script environment without any agent harness. But it is enough to illustrate a key fact: the same model, placed in different harnesses, can differ greatly in its ability to complete real tasks.

    2. Why the Same Model Behaves Differently in Coding

    In an ordinary chat interface, the model’s input is usually a user question and a small amount of conversation history. The model cannot see the full repository, run tests, inspect error logs, or modify files. Users must manually copy code, paste errors, and repeatedly confirm results. Every step of the task depends on human handoffs.

    A coding agent changes this workflow. It can proactively read relevant files, search for function definitions, run tests, correct code based on failure information, and verify again. At each round, the model receives new observations, so its decision basis becomes increasingly complete. Therefore, in coding scenarios, the main source of experience differences is often the harness’s management of context, tools, and state, not just the model’s parameter scale.

    3. Core Components of Coding Agents

    3.1 Repository Context Management

    Real projects often contain thousands of files, while a model’s context window has a clear limit. An agent needs to select the most relevant information within a limited budget. Common practices include:

    • Directory structure summaries: Provide the project’s module layout and key entry points so the model can quickly narrow its scope.
    • Symbol and reference search: Find relevant code through keywords, symbol names, or dependency relationships instead of putting the entire repository into context.
    • On-demand reading: Read specific file fragments only when the model explicitly needs them, with line-number ranges marked.
    • Project instruction files: Maintain agent-oriented instructions in the repository that describe build commands, directory conventions, testing methods, and code style. These files serve as an onboarding manual for the agent.

    The quality of context selection directly affects whether edits are accurate. If too little is read, the model may make changes that conflict with the existing implementation. If too much is read, key information can be buried in noise and costs increase.

    3.2 Tool Design

    Tools are the interface through which an agent interacts with the external environment. A reasonable toolset usually covers the following capabilities:

    • File reading and searching
    • File editing, using local replacements or patches rather than full-file overwrites
    • Command execution for builds, tests, and linting
    • Version information queries

    Several principles matter in tool design. First, tool descriptions must clearly state purpose, parameters, and limitations so the model can choose correctly. Second, tool output must be length-controlled; overly long logs need truncation or summarization to avoid consuming context. Third, editing operations should be as small-grained as possible to support review and rollback. Fourth, high-risk operations such as deleting files, accessing the network, or changing system configuration require permission checks and should ideally run in a sandbox or restricted environment.

    3.3 Prompt-Cache Stability

    LLM services often support caching prompt prefixes. When prefix content is identical, repeated calls can reuse earlier computation results, reducing latency and cost. This mechanism has a major impact on agents because an agent resubmits a large amount of history on every round.

    For caching to work, the harness must keep the prompt structure stable:

    1. Place system instructions, tool definitions, project instructions, and other rarely changing content at the front of the prompt.
    2. Place dynamic content, such as the current time, temporary state, and the latest observation results, closer to the end.
    3. Avoid randomly reordering the tool list or rewriting system instructions on every round; otherwise the prefix cannot be reused.
    4. Maintain history messages by appending; perform compression only when necessary and concentrate it where possible.

    These conventions may look trivial, but they directly determine the response speed and cost curve of long tasks.

    3.4 Memory Mechanisms

    Agent memory can be roughly divided into three layers:

    • In-session state: The current task goal, completed steps, and pending items.
    • In-session history: The complete interaction record between the model and tools, with key information retained after compression.
    • Cross-session memory: Long-term knowledge stored as files or databases, such as project conventions, known issues, and team preferences.

    Cross-session memory requires careful design. Written content should be filtered so that only stable, verifiable facts are retained. Outdated or incorrect memories can mislead later decisions, so update and deletion mechanisms are needed.

    3.5 Long-Session Continuity

    A complex task may last dozens of rounds or longer, and the context will eventually exceed the window limit. Common approaches include:

    • Staged summaries: When a threshold is reached, compress completed work, key findings, and open questions into a structured summary that replaces the original history.
    • Plan files: Break the task into a checklist and write it to a file, updating status after each step so a new context can quickly recover progress.
    • Checkpoints: Record state before critical edits so that failures can roll back to a known-good version.

    The quality of summaries determines the quality of continuity. If a summary omits constraints or failed attempts, the model may repeat approaches that have already been ruled out.

    4. Basic Structure of the Control Loop

    The following pseudocode shows a typical skeleton for an agent harness. It is intended only to illustrate structure and does not correspond to any specific implementation.

    1. state = initialize(task_goal, project_context)
    2. while not task_complete and within_budget:
    3. action = model_decide_next(state)
    4. if action is tool_call:
    5. check_permissions(action)
    6. result = execute_tool(action)
    7. result = truncate_or_summarize(result)
    8. state.append_observation(result)
    9. elif action is final_answer:
    10. break
    11. if history_length > threshold:
    12. state = compress_history(state)
    13. save_checkpoint(state)
    14. return output(state)

    This loop contains four key decision points: whether the next action is reasonable, whether the tool call is allowed, whether the observation needs compression, and whether the task should end. Budget limits such as maximum rounds, maximum elapsed time, and maximum cost are necessary safeguards against runaway behavior.

    5. Engineering Trade-offs

    5.1 Security and Permissions

    A coding agent can modify code and execute commands, so permission boundaries must be clear. Recommended practices include: read-only by default, with write operations requiring explicit authorization; command execution in an isolated environment; allowlists for network access and sensitive paths; and logging all tool calls for auditability.

    5.2 Observability

    An agent’s decision process is long, making problems difficult to locate when they occur. The harness should record each round’s input summary, model output, tool call parameters, and returned results. With these logs, teams can distinguish context-selection errors, tool-design flaws, and reasoning failures in the model itself.

    5.3 Evaluation Methods

    Evaluating a coding agent should not rely only on whether a single response is fluent. Instead, design task sets that test the results of the complete workflow, such as fixing a specified defect, passing existing tests, and avoiding regressions. Metrics can include task success rate, average number of rounds, cost per task, and amount of manual modification.

    6. Implementation Recommendations

    When building a similar system inside an enterprise, the following order can be used:

    1. Fix the toolset first: Start with four basic capabilities—reading, searching, editing, and testing—and expand gradually.
    2. Establish project instruction standards: Give every repository clear documentation for builds, tests, and conventions.
    3. Prioritize prompt structure stability: Design the boundary between prefix and dynamic content early to avoid large-scale refactoring later.
    4. Set up permissions and audit mechanisms: Complete isolated execution and logging before opening up write permissions.
    5. Evaluate continuously with task sets: After every change to prompts, tools, or compression strategies, compare results using the same set of tasks.

    At the infrastructure level, agents typically rely on general object storage for logs and checkpoints, message queues for asynchronous tasks, container platforms for isolated execution environments, and logging services plus monitoring and alerting to detect anomalies. These capabilities belong to common cloud computing categories, and the choice should depend on team size, compliance requirements, and cost budget.

    The effectiveness of a coding agent depends on the coordination of the model, the harness, and engineering support. The model provides judgment, the harness provides perception and action, and the engineering support keeps the system stable, controllable, and measurable over long-term operation. Understanding these three layers is the starting point for designing and evaluating such systems.