AI Coding Agent Architecture: Beyond the Model, the Systems Engineering
This article breaks down why a strong language model alone does not make a useful coding agent. It explains the layered boundaries between large language models, reasoning models, and the agent control loop, then examines the engineering harness around the model across five areas: codebase context construction, tool design, prompt cache stability, memory mechanisms, and long-session continuity. It also covers evaluation and observability metrics for building reliable software engineering agents.
1. Introduction: Why a Strong Model Does Not Equal a Useful Agent
When people discuss how coding tools perform in practice, a common attribution bias appears: a successful code generation is credited to the model, while a failure is blamed on insufficient model capability. This simplified narrative ignores the complexity of the real system. An agent built for software engineering tasks is essentially a model-driven distributed system. The model is only the compute kernel; what truly sets the upper limit of the experience is often the engineering shell built around it.
This shell is usually called the Agent Harness. It decides “what to do next”: which files to read, which tools to call, how to compress and update context, and when to decide the task is complete. Mounting the same model on different harnesses can produce several-fold differences in performance. Therefore, evaluating a coding agent requires treating it as a system, not a model.
2. Concept Layers: The Boundaries Between Models, Reasoning Models, and Agents
2.1 The Large Language Model Is the Engine
The core capability of a large language model is next-token prediction. It learns statistical patterns of syntax, semantics, and partial reasoning from massive corpora, forming the foundation for all higher-level capabilities. Used on its own, it behaves as a passive text completer: whatever you give it, it continues probabilistically.
2.2 The Reasoning Model Is an Enhanced Engine
A reasoning model is still a language model. The difference is that, through training or prompting strategies, it is guided to invest more “thinking compute” before producing an answer—unfolding intermediate steps, performing self-verification, and searching and comparing multiple candidate solutions. The cost is higher latency and compute consumption. It is better at tasks that require multi-step deduction, such as math, algorithm design, and complex refactoring, but it may be overkill for simple add, delete, and modify scenarios.
2.3 The Agent Is the Control Loop
The agent sits at the top layer as a feedback loop around the model: perceive the current state, choose an action, execute tools, observe results, update state, and decide whether to terminate. Its skeleton can be summarized with the following pseudocode:
state = init_state(goal, repo)while not state.done and state.steps < MAX_STEPS:action = model.plan(state) # decide the next stepobservation = tool_runtime.run(action) # execute the toolstate = state.update(observation) # update memory and contextreturn state.result
An apt analogy: the model is the engine, the reasoning model is a high-power engine, and the harness is the transmission, drivetrain, and steering wheel—it determines whether the engine’s power can be effectively delivered to the ground.
3. Codebase Context: The Agent’s Scarcest Resource
The biggest difference between software tasks and general question answering is that answers are scattered across thousands of files. The quality of context construction directly determines whether the agent will fabricate content.
- Retrieval and recall: A combination of symbol indexes, full-text search, and dependency graphs is needed—first locate entry files, then expand along call chains. Relying on vector similarity alone often misses key type definitions and configuration.
- Context budget allocation: When the window is limited, prioritize keeping interface signatures, type declarations, test cases, and error stack traces rather than stuffing in entire files.
- Structured summarization: For very long files, first produce a symbol-level summary and pull the original text on demand, which can significantly reduce noise.
A practical trade-off principle: prefer less but accurate over more but messy. Irrelevant context not only wastes budget but also dilutes the model’s attention and induces incorrect changes.
4. Tool Design: Making Capabilities Composable Primitives
Tools are the agent’s hands and feet. Good tool design shows in error recoverability and semantic clarity.
- Atomicity: Read, modify, query, and execute should be split into minimal actions with clear boundaries, avoiding one giant tool swallowing all logic.
- Rollback support: Editing tools should support diff preview and undo to reduce the cost of mistaken changes.
- Readable feedback: Error messages should be optimized for the model, clearly indicating the file, line number, and expected format, rather than throwing a stack trace only humans understand.
- Layered permissions: Set tiered authorization for writing files, executing commands, and accessing the network; high-risk actions require explicit confirmation.
An illustrative tool description structure:
{"name": "apply_patch","input": {"path": "string", "diff": "string"},"output": {"status": "ok|conflict", "message": "string"},"side_effect": "writes_file","reversible": true}
5. Prompt Cache Stability: An Undervalued Cost and Latency Lever
In long sessions, system prompts and project background are often sent repeatedly. If the prefix stays stable, the inference side can reuse the cache, significantly reducing time to first token and cost. Conversely, any meaningless change invalidates the cache.
Practical points include: put volatile content (timestamps, random IDs, dynamic retrieval results) at the end of the prompt; version system instructions to avoid frequent tweaks; concatenate retrieval results in a fixed order. A stable prefix is an architectural discipline, not an accidental result.
6. Memory Mechanisms: State Accumulation Across Sessions and Turns
Memory can be divided into three layers: short-term memory within a session, project-level long-term memory, and task-level intermediate artifacts.
- Short-term memory relies on the context window and needs rolling summarization to prevent overflow.
- Long-term memory is usually accumulated as structured entries such as project conventions, build commands, and directory descriptions. It can be stored in a general-purpose database or object storage and recalled on demand.
- Intermediate artifacts (such as failed attempts and ruled-out approaches) should be explicitly recorded to prevent the agent from repeating the same mistakes.
The key is “searchable, updatable, and evictable”; otherwise, memory degrades into a source of noise.
7. Long-Session Continuity: Combating Drift and Forgetting
As turns increase, early constraints are easily diluted, causing goal drift. Countermeasures include: periodically restating the goal and acceptance criteria; checking off and archiving completed subtasks; performing a global consistency check at key points. If a session becomes too long, a “main agent + subtasks” divide-and-conquer mode can isolate local context and return only conclusions, thereby controlling complexity. In scenarios requiring team collaboration, message queues and logging services can handle task distribution and tracking, while monitoring and alerting can observe success rates and latency.
8. Evaluation and Observability: Making the System Measurable
Without measurement there is no improvement. At minimum, collect task success rate, average number of turns, tool call failure rate, cache hit rate, and cost per task. Use unified logging and distributed tracing to reconstruct every decision path and pinpoint whether the issue is retrieval inaccuracy, a tool defect, or prompt drift. Baidu AI Cloud can provide a foundation for such an observability system through general capabilities such as container platforms, logging services, and monitoring and alerting.
9. Conclusion
The competition among coding agents has shifted from “whose model is stronger” to “whose system is more stable.” Understanding the model, reasoning model, and Agent Harness as separate layers, then continuously refining five dimensions—context, tools, caching, memory, and continuity—is the right path to building a highly available software engineering agent.
