Understanding Agent Architecture: How LLMs and Harnesses Work Together
This article breaks down the agent architecture behind tools that can read codebases, edit files, and iterate on test failures. It explains the Agent = LLM + Harness model, the Observe–Reason–Act loop, the two layers of capability supply (Tools and Skills), context engineering practices, and the reliability and safety guardrails needed to run agents in production. Readers will also find a practical rollout sequence for building similar capabilities in their own systems.
1. From Answering Questions to Getting Work Done
A large language model is fundamentally a component that predicts and generates sequences based on context. It excels at understanding semantics, recognizing patterns, and producing code and text. What it inherently lacks are three things: perception of the external environment, persistent memory of state changes, and the ability to produce side effects in the real world.
So when we talk about an AI coding tool that can read a codebase, modify files, run tests, and repeatedly fix issues based on errors, what actually makes it work is not the model alone, but the entire execution mechanism wrapped around it.
The industry often summarizes this relationship with a simple formula:
Agent = LLM + Harness
The LLM is the decision-making core, and the Harness (the runtime framework) is the “body” that carries the core. The core handles thinking and choosing; the body handles perception, execution, constraints, and state maintenance. Remove either one and the system’s capabilities degrade significantly: a model without a framework cannot act on its output, and a framework without a strong model just loops on flawed reasoning.
2. The Three Stages of the Loop: Observe, Reason, Act
The core structure of an agent is a continuously running loop, which can be abstracted as Observe–Reason–Act.
2.1 Observe: Turning Environment State into Structured Context
The observation stage collects feedback from the external world and trims it into a form the model can digest. Typical observation sources include a command’s standard output and error output, file contents and directory structure, test reports, API response bodies, and log fragments. The key design decision here is not “how much to collect” but “how to trim.” A full build log can run to tens of thousands of lines, and stuffing it directly into the context is both expensive and inefficient. Instead, you filter by error level, aggregate by call stack, and preserve key line numbers and assertion details.
2.2 Reason: Locating the Problem and Planning the Next Step
The reasoning stage turns observations into decisions: whether the task is complete, which tool to call next, what the arguments are, and whether a rollback is needed. In engineering practice, the model is usually required to emit an explicit structured decision rather than free-form prose, so the framework can validate and execute it:
{"thought": "Test failures are concentrated in the parsing function, which lacks an empty-input branch","action": "edit_file","args": { "path": "src/parser.py", "old": "...", "new": "..." },"expect": "The target test case passes after this change"}
Making decisions explicit makes them auditable, replayable, and interceptable when arguments are invalid, which prevents a wrong action from being applied directly to a real environment.
2.3 Act: Controlled Execution and Feeding Results Back
The action stage produces real side effects through tools, then feeds the new environment state back as the next round of observation. The loop is now complete. A full trajectory in an AI coding scenario looks roughly like this: a unit test fails → read the failing case and error log → locate the relevant files and call chain → modify the implementation → re-run the target case → keep fixing if it still fails. The loop’s exit conditions must be defined explicitly, and there are three common types: task achieved (all target cases pass), judged unsolvable (insufficient information or contradictory requirements), or limit triggered (step, time, cost, or permission cap).
3. Tools and Skills: Two Layers of Capability Supply
A framework’s capability supply is usually split into two layers with different responsibilities and different granularity.
- Tools are atomic capabilities that map to a single clear, verifiable action: reading a file, writing a patch, executing a command, searching code, querying a database, or calling an external API. A tool must have a clear input schema, timeout control, output truncation, and permission boundaries.
- Skills are composite capabilities: “ways of getting things done” that orchestrate multiple tools in a fixed workflow, such as “reproduce and fix a failing test case” or “add contract tests for a new endpoint.” A skill captures process knowledge and checklists, not new low-level permissions.
The value of this layering is that the tool set stays small and stable, which lowers the model’s selection cost, while process knowledge is reused in the form of skills instead of being re-derived for every task. In practice, the principle of least privilege should also apply: write operations and network access should be authorized separately from read-only operations, and dangerous actions should require explicit confirmation.
4. Context Engineering: The Hidden Variable That Decides Success
Whether the loop converges depends largely on the quality of context management. Practices that work in practice include:
- Layered loading: provide the directory structure and a summary first, then expand specific files on demand, instead of loading the entire repository at once.
- Result compression: keep a summary and key fragments of long output, write the raw content to disk, and reference it by path.
- Externalized state: write todos, modified files, and verified conclusions to an external checklist so nothing is forgotten during a long loop.
- Failure memory: record approaches that have been tried and did not work, to avoid spinning on the same spot.
An illustrative state structure:
task: fix failing unit testsdone: [located failing module, added empty-input branch]failed_attempts: [changed return type only]open: [edge case with nested null]limits: { max_steps: 30, timeout: 900s }
5. Reliability and Safety Boundaries
An agent framework that is ready for production must have guardrails. First is execution isolation: commands run in a controlled sandbox or containerized environment, and file writes are confined to the working directory. Second is rollback capability: all changes are recorded as patches so they can be reviewed and reverted. Third is observability: the action, arguments, and observation summary of every step are retained in full, forming a replayable trajectory. Fourth is cost control: set caps on steps and calls to avoid infinite loops. Finally, there is human takeover: pause and request confirmation for operations involving deletion, permission changes, or production environments.
6. Implementation Recommendations
To build similar capabilities in your own system, follow the order “loop first, then expand tools, then codify skills”: start with a minimal tool set (read, write, execute) to get the loop working and verify that it converges; then gradually add atomic tools such as search, databases, and APIs; finally, turn high-frequency workflows into skills. On the operations side, you can use a container platform for environment isolation, object storage to keep trajectories and artifacts, and logging and monitoring with alerting to track step counts, success rates, and latency distribution. This is how an agent moves from a demo to an engineering component that can be operated sustainably.
