# Coding Agent Architecture Explained: Six Core Modules and How They Work Together
Ever wondered why the same LLM feels mediocre in a chat window but powerful inside a coding agent? This article breaks down the agent harness architecture, including the core observe-inspect-choose-act loop and six essential building blocks—tools, system prompts, context management, memory, sandboxing, and loop control—to help you evaluate, use, or build coding agents more effectively.
Why the Same Model Delivers Such Different Experiences
Many developers have run into this puzzle: when you use the same large language model directly in a chat window to make code changes, its performance is mediocre. Yet the same model, wrapped inside a coding agent product, can autonomously browse a codebase, edit files across modules, run commands, and fix errors. The difference doesn’t lie in the model itself—it lies in the system design around it, commonly known as the Agent Harness.
In real-world software engineering, whether a task succeeds depends on far more than model capability. It also depends on how codebase context is organized and injected, how tool interfaces are designed, whether prompt caching stays stable enough to keep costs and latency low, and how memory and state persist across long sessions. These engineering decisions matter just as much as the model itself.
Three Often-Confused Concepts: LLM, Reasoning Model, and Agent
Before diving into the architecture, let’s clarify three layers:
- LLM (large language model): The core next-token prediction model—the foundational engine of the whole system.
- Reasoning model: Still fundamentally an LLM, but trained or prompted to spend more compute on reasoning, self-verification, and candidate solution search. This improves accuracy on complex tasks at the cost of higher latency and expense.
- Agent: The control loop layer that sits above the model. It decides, based on the goal, what to inspect next, which tools to call, how to update state, and when to stop.
A helpful analogy: the LLM is the engine, the reasoning model is a souped-up engine, and the agent harness is the drivetrain and control system that lets the engine actually drive a car. The analogy isn’t perfect—plain LLMs can be used standalone—but on complex tasks, the value of the harness grows dramatically.
The Core Loop: Observe → Inspect → Choose → Act
A minimal but complete coding agent can be described as continuous iteration through four phases:
- Observe: Receive the user’s goal and gather the current environment state, such as working directory structure and recent command output.
- Inspect: Examine internal state and the context window, deciding which information is relevant to the current step, and whether history needs compression or memory needs supplementing.
- Choose: The model selects the next action based on the current context—read more files, run a command, edit code, or declare the task complete.
- Act: Invoke the tool to execute the action, write the results back into the context, and return to the observation phase.
This loop looks simple, but it’s the skeleton of every coding agent. The real engineering challenge lies in polishing the details of each phase.
The Six Core Building Blocks
1. Tool System
Tools are the agent’s hands and feet. Typical tools include reading files, writing/editing files, running shell commands, code search (such as regex-based full-text search), and directory listing. The key design principles are clear interface semantics and informative-but-low-noise return values. For example, an editing tool should support exact-match replacement rather than full-file rewrites—saving tokens and reducing the risk of unintended changes.
A minimal Python tool registry:
tools = {"read_file": read_file,"edit_file": edit_file,"run_command": run_command,}def dispatch(name, args):return tools[name](**args)
2. System Prompt and Environment Information
The system prompt defines the agent’s role, behavior guidelines, and tool usage conventions. Beyond static instructions, it should dynamically inject environment information: OS type, current working directory, and a directory structure summary. This gives the model enough “landmarks” from the very first turn, reducing blind trial and error.
3. Context Management and Prompt Caching
In long task sessions, context bloats quickly. Mature approaches include: keeping the conversation prefix stable to hit the prompt cache (which significantly reduces cost and first-token latency), summarizing and compressing message history, and truncating or offloading large tool outputs. Cache stability requires the prefix to change as little as possible—which is why environment info is typically placed in a fixed system prompt rather than updated every turn.
4. Memory and State Persistence
Cross-session continuity depends on persistence: task checklists, important decisions, and user preferences can be written to memory files and loaded when a new session begins. This gives the agent a sense of continuity across long-term, multi-session collaboration, instead of starting from scratch every time.
5. Execution Environment and Security Boundaries
An agent’s ability to execute commands must come with safety mechanisms: working directory isolation, dangerous command interception, confirmation for sensitive operations, and sandboxed or containerized execution. This is the dividing line between a demo and a production-ready product.
6. Loop Control and Termination
The control loop needs to handle: iteration limits, error retry strategies, completion signals (usually the model explicitly invoking a “finish” tool or outputting a specific structured result), and a mechanism for asking the user for clarification mid-task.
From Minimal Implementation to Production Systems
A runnable mini agent can be built in a couple hundred lines of Python. But production-grade systems require deeper work in several areas: efficient retrieval and indexing for multi-file repositories, parallel tool calls, sub-agent task decomposition, more granular permission tiers, and evaluation suites based on real workloads. Once you understand the six modules and the core loop, these advanced directions fall into a clear analytical framework.
Closing Thoughts
The essence of a coding agent is using an engineered surrounding system to transform a “next-token predictor” into an executor capable of autonomously completing software engineering tasks. The model sets the ceiling of capability; the harness determines how much of it you actually get. Hopefully this architectural lens helps you make sharper decisions when evaluating, using, or building your own AI coding tools.
