Inside a Coding Agent: Six Building Blocks from the Model to the Agent Harness

    Coding agents often outperform the same large language model in a plain chat interface because the surrounding system matters as much as the model. This article explains what a coding agent is, how an agent harness works, and how six building blocks—system prompts, tools, context, memory, the execution loop, and session continuity with safety guardrails—fit together.

    When people discuss how well large language models write code, they often mix up three different things: the model itself, the model’s reasoning behavior, and the agent product that wraps the model. In many real applications, the system around the model—tool use, context management, and memory—matters as much as the model. That helps explain a common observation: the same model often performs noticeably better inside a dedicated coding tool, a coding agent, than it does in an ordinary chat interface.

    This article explains the overall architecture of a coding agent: what it is, how it works, and how its parts work together in practice.

    1. Clarifying the terms: LLM, reasoning model, and agent

    Before going into the details, it helps to separate three ideas that are easy to confuse:

    • LLM (large language model): the core engine for understanding and generation. At its core, it predicts the next token from context.
    • Reasoning model: a model that spends a longer internal chain of thought before producing an answer, trading more computation for higher-quality output. It is suited to complex logical tasks.
    • Agent: an LLM placed inside an application-layer framework so it can interact with the outside world—read files, run commands, observe results, and revise its work. That application-layer framework is usually called the agent harness.

    In short, agent capability = model capability × harness quality. The harness decides what the model can see, what it can do, and how it recovers from feedback.

    2. Why the harness matters so much

    Software engineering tasks have several natural traits that make simple question-and-answer interaction fall short:

    1. Codebases far exceed the context window. Real projects can contain hundreds of thousands of lines. They cannot all be placed in the prompt, so the harness must retrieve, filter, and inject the relevant fragments.
    2. Tasks are multi-step and stateful. Fixing a bug may require locating files, understanding dependencies, editing code, running tests, and then iterating on failures. That is not one conversation turn.
    3. Results need verification. Compilers and test suites decide whether the code is correct. The agent must be able to run them and interpret the feedback.

    A mature coding agent is therefore often differentiated less by which model it uses than by how carefully it handles context engineering, tool design, and session management.

    3. Six core building blocks

    The sections below use a minimal pure-Python implementation—a “mini coding agent”—to break the system into six modules.

    1. Model and system prompt

    The first layer of the harness is the system prompt. It defines the agent’s role, working rules, and output format. A good system prompt should state when and in what order to use tools, set editing conventions (such as preferring the smallest change), and constrain dangerous actions (such as destructive commands).

    1. SYSTEM_PROMPT = """You are a software engineering assistant.
    2. - Read the relevant files before changing code
    3. - Prefer the smallest possible change
    4. - Run tests after changes to verify the result
    5. - Do not run destructive operations such as deleting files"""

    2. Tool design

    Tools are the agent’s hands and feet. A typical set includes:

    • File reading: view source code, often with line numbers so later edits can be located precisely.
    • File search: navigate the repository by filename patterns (such as fuzzy matching) or content patterns (such as regular-expression search).
    • Code editing: edit by exact string replacement instead of rewriting whole files, which reduces cost and risk.
    • Command execution: run builds, tests, and scripts, and capture standard output and error output.

    The key design principle is structured input and output. Each tool accepts a clear parameter schema (such as JSON Schema) and returns text results with boundary markers so the model can parse them reliably. Output length per call should also be limited so large logs do not overflow the context.

    3. Context management

    Context is the agent’s scarcest resource. Useful strategies include:

    • Load on demand: read files only when needed, rather than injecting the whole codebase up front.
    • Explore progressively: list directories, then search content, then read specific files closely—similar to how a human engineer navigates.
    • Compress with summaries: in long sessions, fold historical tool output into summaries while keeping the key conclusions.
    • Stay cache-friendly: keep the system prompt and tool definitions stable at the start of the request so prefix caching can reduce latency and cost.

    4. Memory

    Persistent memory across sessions gives the agent project experience. A common approach is to keep an agreed file in the project root, such as a Markdown notes file, that records build commands, coding conventions, and architecture decisions. The agent loads this content at the start of a session and updates it when it learns something new. Memory has two layers:

    • Short-term memory: the message history of the current session.
    • Long-term memory: project knowledge and user preferences persisted across sessions.

    5. The execution loop: observe, inspect, choose, act

    This is the heart of the agent. A minimal implementation looks like this:

    1. def agent_loop(user_task):
    2. messages = [
    3. {"role": "system", "content": SYSTEM_PROMPT},
    4. {"role": "user", "content": user_task},
    5. ]
    6. for _ in range(MAX_TURNS):
    7. response = call_llm(messages)
    8. messages.append(response)
    9. if not response.tool_calls: # no tool calls; the task is done
    10. return response.text
    11. for call in response.tool_calls:
    12. result = execute_tool(call) # observe the environment
    13. messages.append({"role": "tool", "content": result})

    Each turn of the loop has four stages: observe (get tool output), inspect (check whether the result matches expectations), choose (pick the next action), and act (call a tool). The model decides when to continue and when to stop. The harness enforces a turn limit, timeouts, and error handling.

    6. Session continuity and safety guardrails

    Long-running tasks require the harness to support resuming after an interruption (by persisting message history), command timeouts and cancellation, permission control (sensitive commands need user confirmation), and loop detection (so the agent does not repeat the same failing action). These engineering details directly determine whether the agent is usable in real production environments.

    4. Assembling the full system

    Put the six modules together and the flow is: the user gives a task, memory and the system prompt are loaded, the execution loop starts, the model explores the codebase, edits files, and runs commands through tools, observes feedback and iterates, then updates memory and returns a summary when finished.

    These modules are tightly coupled. Tool output format affects context consumption, context strategy affects cache hit rate, and memory design affects prompt stability. A strong harness design is essentially a balance among those constraints.

    5. Conclusion

    A coding agent is not a chat box plus code completion. It is a complete engineering system built around an LLM. The model supplies intelligence; the harness turns that intelligence into reliable, verifiable software engineering capability through tools, context, memory, and an execution loop. Understanding these six building blocks helps developers use existing coding tools more effectively and gives a clear architectural blueprint for building domain-specific agents. If you are planning a programming assistant based on a large language model, evaluate and design it along these six dimensions—they set the ceiling on what the agent can do.