Under the Hood of Coding Agents: How the Model-Harness Architecture Operates
An architectural breakdown reveals how stateless language models combine with deterministic execution harnesses and context management to run autonomous coding workflows.

Autonomous coding assistants such as Claude Code and Codex have quickly become fixture tools across the software development industry. While many developers interact with these tools daily to generate code or automate complex development workflows, the mechanics governing their autonomy are often viewed as a black box. At a structural level, modern coding agents are not sentient intelligences, but rather a combination of two primary components: a next-token predicting large language model (LLM) and a surrounding software harness that gives the model memory and the ability to act.
Because base language models are fundamentally stateless and unable to directly interact with outside environments, they require deterministic software scaffolding to operate autonomously. Understanding how this relationship works in practice reveals how agents read directories, search codebases, and execute multi-step modifications.
The Anatomy of an Agent: Model Plus Harness
At the core of an AI agent lies an LLM—a statistical pattern-recognition engine trained to predict subsequent tokens based on input sequences. Because modern LLMs rely on self-attention mechanisms with quadratic computational complexity, they are constrained by context windows and can experience performance degradation, known as context rot, as prompts grow too large. Furthermore, models are nondeterministic and stateless, meaning each query starts without any memory of previous interactions, and the model alone cannot modify files or run terminal commands.
The harness solves these constraints. Acting as deterministic code surrounding the model, the harness gives the LLM tools and manages its memory. Tools consist of two elements: a tool definition (containing a name, description, and input schema) exposed to the model, and an execution function written in traditional code that runs when requested.
To bridge the gap between static text output and multi-step tasks, the harness establishes an agentic loop. Triggered by a prompt or automated event, the harness feeds the current context to the model. If the model determines it needs information or must alter a file, it requests a tool call instead of returning a final answer. The harness executes the requested function, logs the result back into the context, and invokes the model again. This cycle repeats until the model issues a final response indicating the task is complete.
Tracing the Loop in Production Architecture
A practical examination of OpenCode (version 1.18.33), an open-source coding agent, shows how this architecture operates under the hood. OpenCode separates responsibilities between a terminal interface and a local background server, delegating model interactions to the Vercel AI SDK. State is maintained outside the runtime loop within a local SQLite database, allowing sessions to be paused, resumed, or branched at arbitrary points.
When a developer requests a code modification—such as changing a UI button style—the server initializes a session record, appends the user's prompt, and begins a standard programmatic while-loop. On every turn, the loop reads the conversation history, evaluates whether the previous step indicated a stoppage or another tool call, and selects the designated model.
Context assembly is critical during this process. The harness combines system prompts (role definitions and guidance from files like AGENTS.md), available tool schemas from a tool registry, and session history. To prevent exceeding context limits, the harness employs compaction techniques, summarizing earlier conversation steps into specialized history records before sending the payload. The Vercel AI SDK then streams the interaction using discrete events: text-delta when streaming raw output, tool-call when the model invokes utility scripts like file searching, tool-result when the harness completes the operation, and step-finish when a cycle ends.
What it means for developers
Understanding the separation between model and harness demystifies how agents solve problems and highlights where autonomous workflows can fail. Because the harness governs context, tool selection, and loop termination, agent reliability depends as much on traditional software engineering—such as schema precision, state storage, and context compaction—as it does on the underlying model's reasoning capabilities.
For engineers building custom agents or internal developer platforms, the architecture demonstrated by tools like OpenCode shows that agents do not require proprietary orchestration engines. Instead, standard deterministic loops, SQLite state persistence, and well-defined input schemas allow standard models to iteratively modify files and execute tests. Developers experimenting with custom harnesses across different foundation models can try top AI models cheaply through one API at https://apixoai.online to evaluate performance variations during agentic execution.
Ultimately, viewing an agent as a model wrapped in a deterministic harness allows engineering teams to treat agent development as a software systems problem. Designing better tools, controlling context rot through aggressive summarization, and enforcing strict execution schemas are the key levers for improving autonomous coding outcomes.
Source: A Software Engineer’s Guide to Agents — Towards AI. Written by the Apixo team from that report.
One key for Claude, GPT, GLM, DeepSeek and more. Pay per token with crypto.
Get your API key

