跪拜 Guibai
← Back to the summary

The Harness: Two Open-Source Designs for Turning LLMs into Agents

What is a harness: turning a thinking model into an acting Agent

The same model, placed in a chat box, only answers one question at a time; placed in a Coding Agent, it can modify files, run commands, and work continuously for dozens of rounds. What is that extra something in between?

That something is called a harness (挽具, reins, execution framework). It is all the code outside the model: the loop that runs, the assembly of context, the execution of tools, the management of memory, and the control of permissions.

Now two companies have open-sourced this code, with opposite design philosophies: one says "everything is a plugin," even the loop itself can be swapped; the other says "minimal kernel," deliberately omitting features like sub-tasks. Understanding this disagreement is to understand the harness.

This article is included in the WeChat public account: 愤怒的代码 AngryCode

0x00. The literal meaning of harness is a yoke

The word "harness" in English originally meant "yoke"—the leather gear set on a horse. A horse has strength, but a horse alone cannot pull a cart: you need reins, a saddle, and shafts to channel the horse's power into the cart, and only then the horse can haul goods. Since its creation, the word has referred to "a device for channeling force."

In machine learning contexts, harness was first used to refer to an evaluation harness. EleutherAI's lm-evaluation-harness is typical: a fixed device that fits any model into it, connects it to a benchmark, and runs the evaluation under a unified process, reporting scores. The model here is the "horse" being tested; the harness is the frame that fixes it and channels its force.

The Agent era pushes this word further: instead of just evaluation, the model is slotted into real environments—file systems, terminals, browsers, databases, external APIs. The harness is responsible for connecting the model to the environment: the model outputs "I want to execute this command," the harness actually executes it, then sends the result back.

So in one sentence: the harness is all the code outside the model. It is the shell that turns a large language model from "a function that generates text" into "an Agent that can act."


0x01. The model is a stateless function; it is a thinker

Why do we need this shell? Because the model itself can only do one thing: generate text.

A large language model (LLM) has only one interface: input a sequence of tokens, output a sequence of tokens. It has three innate shortcomings:

  1. It has no hands. It cannot call tools. If you ask "What's the weather in Shenzhen today" in a chat box, it only generates a text that looks like a weather report; it does not actually query—unless something behind it queries for it.
  2. It has no memory. Each call starts from zero. It knows nothing about the previous round unless you resend the entire history.
  3. It has no sense of boundaries. It does not know whether its tool calls ultimately succeeded, how many rounds the task has run, or where the permission boundaries lie. All of these belong to the external world.

The harness fills these three gaps: tool execution provides the "hands," conversation and context provide "memory," and permission and approval provide the "sense of boundaries."

The division of labor must be clear: the model only outputs "which tool I want to call, with what parameters," and the harness does the actual action. The model advises, the shell acts. Conversely, the harness produces no intelligence; it does not judge "how to fix this bug," it only faithfully executes the tools the model selects. The model handles "thinking," the harness handles "doing."


0x02. The agent loop: each step inside a turn

The first component to understand in a harness is the agent loop. A loop, three beats:

In real implementations there are two levels of timing units. Step is one model request plus all the tools it calls; turn contains zero or more steps—if a tool result prompts the next request, the turn continues; when the model declares completion, the turn closes. One user input often corresponds to a turn with multiple steps.

There are also details the textbooks do not mention in the loop:

These two words—step and turn—are the event-flow skeleton in the DeepSeek Harness documentation: between turn/start and turn/end are embedded several step/start to step/end, and each step internally connects a sequence of events: request, streaming output, tool calls. The core timing diagram of a harness is just this one picture.

The loop itself is only dozens of lines. But it is just one component of a harness: how the "full history" sent each round is assembled, how tools are executed, how the session is persisted—the ring around the loop is where the real work lies.


0x03. Context assembly: what is fed to the model each round

Each round the loop resends the full context, and "full" is not a single user message but an assembly pipeline. Taking real harnesses apart, there are at least four sources:

  1. System prompt, assembled independently. Identity setup, output specifications, approval policies, plus context files automatically discovered from the project (AGENTS.md, CLAUDE.md), typically tens of thousands of tokens at least.
  2. Tool and skill definitions. Each tool's name, parameter schema, and usage instructions must go into the request; skills only send a description first, and the body is loaded only when the model actually wants to use it—expanded on demand to reduce unnecessary tokens.
  3. Runtime context. The current directory, git status, time, environment variables, which can change each round and are not part of anyone's speech.
  4. Session history, reconstructed from persistent logs with branches (expanded in 0x04).

Assembly is one of the most engineering-heavy parts of a harness, because it directly hits the wall of context window—the maximum number of tokens a model can read at once. Four sources all crammed together raise the watermark; when it reaches the wall, trade-offs must be made. Trade-offs happen in two places: during assembly, decide "whether to show" (skill bodies loaded on demand, images omitted, history starting from summaries); during compression, decide "whether to keep" (next section).

The SWE-agent team articulated the weight of this part most clearly: they found that what the model sees and at what granularity has a bigger impact on final results than swapping to a stronger model. With the same GPT-4 Turbo, rebuilding the interface changed the solve rate on SWE-bench by an order of magnitude—expanded in 0x05.


0x04. The append-only log is the single source of truth

First define two words, used throughout the rest of this article.

Log (session log): everything the harness records that has happened—an append-only ledger. All conversation messages, all branches (including unused forks), traces of failed retries, token usage, model switches, compression records, all in it. Most things in the log are not sent to the model.

Context: the portion fed to the model each round—system prompt + messages rebuilt from the active branch + tool definitions. It is projected from the log on the spot before each request, discarded after use, and re-projected the next round.

The relationship between the two is a one-way edge: log —projection→ context. The log contains the context (log ⊃ context); projection is read-only and never reversed. The later discussion of branches, compression, and traces all revolves around this edge.

The model is stateless, so "what happened" must be stored in the harness's hands. The two leading projects almost agree on this matter, and their consistency actually underscores its importance.

pi's approach: the session is a tree. The session is stored as a JSONL file; each record has an ID and a parent pointer; continuing the conversation from any historical record grows a new branch; fork and clone copy selected history into a new session file. The current active branch serves the next round's request; other branches lie in the file for later reference.

pi's session tree self-explanatory diagram: entry is the append-only JSONL stream, with id, parentId, timestamp; header is the unique tree root; user/assistant/tool entries are color-coded, corresponding to Think→Act→Observe; continuing from entry 2 grows a new branch in the same file; fork/clone copy the selected prefix into a new session file. Image upload failed, please upload image file directly

DeepSeek Harness's approach: a principle written into the architecture document—"what the model can see is already recorded." Anything that goes into a model request must be reconstructable from the session log; to show something new to the model, you must add a new session event, not silently modify it in memory. The log is append-only, stored in generations (generations) with compressed files, and committed files are never renamed, replaced, or deleted. Even failures leave traces: failed, retried, and cancelled streaming outputs are stored as attempt records for diagnostics, but not fed into the model's history.

DeepSeek Harness's session log principle: what the model can see is already recorded—the left column is the append-only log, the single source of truth (assistant/attempt only leaves traces, not projected); the middle deriveMessages() only projects, never modifies the log; the right column is the replayable model-visible history for each round; bottom is persisted by generation, committed files never renamed or deleted. Image upload failed, please upload image file directly

The consensus of both can be condensed into one sentence: the session log is the single source of truth, and every "sight" of the model must be accountable. This is not just for debugging convenience—context compression, branch switching, forks, replays, and telemetry are all derived from this log.

Among the derivations, the most important is context compression (compaction). Looking at pi's implementation, the mechanism is concrete:

Trigger condition: contextTokens > contextWindow − reserveTokens
Default reserve: reserveTokens = 16384, keepRecentTokens = 20000

1. Count tokens backwards from the most recent records, stop when reaching keepRecentTokens, draw a cut point
2. Collect all messages before the cut point, call an LLM to generate a structured summary
3. Append the summary together with the cut position as a CompactionEntry, persist it
4. The next round's request sends: system prompt + summary + messages after the cut point

The original records remain untouched in the log. What is compressed is "the history sent to the model," not "the history that happened." This echoes the classification of Agent memory in the cognitive architecture framework CoALA (《Cognitive Architectures for Language Agents》, arxiv.org/abs/2309.02427, Sumers et al., 2023): working memory is the context assembled for the current round, episodic memory is the session log, semantic memory relies on retrieval tools temporarily, and procedural memory lives in the model weights. The harness manages the entry and exit of the first three; it cannot touch the model weights—session management, compression, retrieval, all revolve around "which parts of the past can enter the next request."


0x05. The interface decides the fulfillment rate: ACI and tool execution

Context determines what the model "sees," and the tool layer determines what the model "can do." The SWE-agent paper (《SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineering》, arxiv.org/abs/2405.15793, Yang et al., Princeton, 2024) gives a name to this layer: ACI (Agent-Computer Interface)—what the Agent sees, can do, and in what format it interacts.

Their experiments are the hardest evidence of the engineering value of a harness. Initially, when the Agent was directly exposed to the entire repository, it was flooded by the massive code and could not fix issues; after rebuilding the interface—a dedicated file viewer, lint tools, and a search that returns only error-related lines—the same GPT-4 Turbo achieves a solve rate on SWE-bench (the benchmark for fixing real GitHub issues, swebench.com, original paper arxiv.org/abs/2310.06770) that goes from 1.31% for the RAG baseline to 12.47%. No model change, only the interface changed, the results differ by nearly ten times.

Beyond SWE-agent, the engineering details of the tool layer also converge:

There is also a standardization action in the tool layer: at the end of 2024, Anthropic released MCP (Model Context Protocol, modelcontextprotocol.io), defining "how models connect to tools and data sources" as an open protocol, and various harnesses have adopted it. The protocol is converging, but the polishing of interfaces never converges—whether an ACI works well is something each project has to work on itself.


0x06. Route one: DeepSeek Harness, everything is a plugin

Sections 0x00-0x05 discuss the "common denominator" of harnesses—the parts every project must have. From here, divergence begins.

DeepSeek Harness (henceforth dsh) is an agent harness open-sourced by DeepSeek in 2026, with hundreds of thousands of stars on GitHub within months. Its self-description is just four words: Everything is a Plugin.

Concretely, dsh has no layered "core + plugin" structure. Model adapters, the tool registry, session logs, sandbox policies, even the agent loop itself, are all plugins, all replaceable from configuration. The architecture document states verbatim: "There is no privileged core that requires patching." If you want different loop behavior, you do not file an issue with the official team and wait for scheduling; you write a plugin that replaces the default loop.

Underpinning this design is the underlying framework Cordis, backed by a proper programming paradigm paper: A Programming Paradigm for Spatiotemporal Composability (arxiv.org/abs/2608.25512, Shi Yifan, Zhang Wei, Cui Tianyi, Peking University + DeepSeek, 2026). The paper splits dynamic composition into two orthogonal dimensions:

On the usage side, dsh's product form is a "layered plugin tree":

A mechanism that best illustrates the design intent is seam (capability seam): each capability is split into three roles: interface definition / provider / consumer. Replacing the provider changes the entire product behavior. The documentation's example involves three standard means by which Agents manipulate the code world; first get to know them:

These three all live on the same underlying layer in a harness: file system access and process creation. dsh turns them into the same seam: the file system and process provider shares the same execution world; pointing them at a remote sandbox moves Bash, PTY, and LSP over together—the Agent does not feel it is already "working on another machine," and no provider-specific code needs changing.

The philosophy behind this architecture is: Agent forms will vary wildly—some want a web interface, some want headless automation, some want to delegate subagents to another product. Rather than presupposing a product form, make the harness a composable base and let the form grow out of the configuration.


0x07. Route two: pi, minimal core, your own assembly

pi is another open-source agent harness (github.com/earendil-works/pi), self-described in one sentence: "minimal, extensible agent harness that you can make your own." Its philosophy stands on the opposite side of dsh.

pi has a clear, non-replaceable core: the agent loop is fixed, and the session tree, compression, and trust decisions live in the core. What it exposes are four extension points: extensions (TypeScript modules running in-process, can register tools, intercept events, change compression strategies, support hot reload), skills (instruction bundles loaded on demand), prompt templates, and themes; these resources are packed into packages (packages) distributed via npm or git.

What it deliberately omits is more eye-catching. The README states that pi comes with sufficient defaults, and deliberately does not implement sub-agent and plan mode. Want them? Two paths: let pi itself write you an extension, or install a package someone else has built. "Adapt Pi to your workflows, not the other way around"—but the way to adapt is by adding to extension points, not by reorganizing the assembly.

The full logic chain of this philosophy: the core loop takes only dozens of lines, the real work is around the loop (see 0x02); every project re-invents that surrounding stuff, so make the most general parts a product with good defaults, and leave the differentiated parts to a few extension points; extension points need not be many—too many and the combinatorial cost is passed to the user.

pi's philosophy is: a set of strong defaults + a few carefully chosen extension points can cover the majority of workflows; excess freedom is a burden.

There is a superficial difference between the two projects that is easily mistaken for a real one (it is not): dsh's event waterfall (waterfall events, listeners wrap results one after another) and pi's extension events (tool_call listeners can pass, intercept, or rewrite) are mechanistically the same—both are around middleware. The real divergence is not about "can you extend," but how big the core is left, and at which layer the combinatorial power is placed.


0x08. The core of the divergence: where to draw the boundary of composition

Put the two routes side by side:

DeepSeek Harness pi
Core No privileged core, loop is also a plugin Core explicit and fixed
Composition unit Plugin / bundle / patch, configuration as product Extension / skill / template / theme, packaged as package
Composition timing Runtime dynamic mount, unmount, hot reload Startup discovery + manual /reload
Form source Profile stacking + patch override One product form, fine-tuning at extension points
Theoretical support Formal paper (effects / coeffects) Engineering intuition, no formalization
Default features omitted No presupposition—everything can be replaced Deliberately not doing sub-agent, plan mode
Security model Sandbox, approval are replaceable providers Trust decision + process permissions, no sandbox

There are three pieces of consensus that are real gold between the two, worth seeing first:

  1. The session log is the single source of truth. pi's session tree and dsh's "what the model can see is already recorded" are two expressions of the same principle.
  2. Extensions are ordinary code, permissions same as the process. Both use equally blunt wording in their docs: extensions can read your prompts, files, credentials; only install ones you trust.
  3. A harness is deterministic software. No reliance on probability; it can be tested, versioned, and replayed.

The divergence is only one, but it runs through everything: where the boundary of composition is drawn. dsh puts the combinatorial power down to every layer, including the loop and the product form itself—the cost is that you face a plugin tree that needs understanding, and even simple tasks must pass through the layers of configuration. pi welds the core tightly and leaves only a few extension points—the cost is that needs outside the extension points can only wait for a core change. Also note: the nature of the two "openings" differs—dsh's seam is a replaceable implementation; swapping the provider changes behavior. pi's extension points are pre-buried hooks; they can intercept and inject, but cannot replace the implementation in the core.

There is no referee. dsh's bet rests on "Agent platforms will be like operating systems, where the ecosystem wins through composability"; pi's bet rests on "harnesses will be like editors, winning on default experience and restraint." Both bets can win because the users they serve are not the same crowd.


0x09. The model sets the ceiling, the harness sets the success rate

Both harnesses are heavy, which can easily lead to the conclusion that "the heavier the harness, the better." Evidence in the opposite direction is equally strong.

mini-swe-agent (github.com/SWE-agent/mini-swe-agent) writes an ultra-minimal Agent in 100 lines of Python, and at release claimed 65% on SWE-bench Verified; the README now says over 74%. In those 100 lines there is no context assembly pipeline, no event system, no plugin tree—a loop plus two or three tools, and it reaches first-tier performance. This shows that as long as the model is strong enough, the harness can be thin to the point of being invisible.

First define the term clearly: task success rate is the column % Resolved in the benchmark—the proportion of tasks assigned to the Agent that are actually completed. For the same model, this number can vary ninefold, and the difference is entirely on the harness's account. Putting the three pieces of evidence together, the conclusion is that the two things operate on different layers:

In software engineering terms: the model is "capability," the harness is "the process that turns capability into output." Both ceiling and success rate matter; missing either is empty talk. This also explains why a 100-line and a hundreds-of-thousands-line harness can coexist: the former simplifies the success-rate problem into "the model is already strong, just don't get in its way"; the latter bets that "for long tasks, multiple sources, and multiple forms, every point of success rate must be squeezed from engineering."


0x0A. How to fit the harness: more than one answer

Back to the beginning: why does the same model only respond to prompts in a chat box, yet act in a Coding Agent? Because a harness has been added in between. The model provides "thinking," the harness provides "acting"—tool execution is the hand, context assembly is the eye, the session log is the ledger, and the permission system is the boundary.

Returning to the harness in 0x00: the horse is still the same horse, but the fitting of the harness differs. DeepSeek Harness breaks the whole harness into replaceable parts, even the yoke can be removed and swapped; pi gives you a carefully fitted harness, leaving buckles only where you truly need them. The divergence will not converge soon, because both paths are right—but the most useful consensus for readers is also hidden here: a harness is ordinary software. The model weights are fixed and cannot be modified, but every line of the harness can be configured. When an Agent performs poorly, you have handles: change the interface, change the assembly, change the compression strategy, change the tools. This is the ticket to understanding Agent engineering—the shell is not magic, it is code, and code can be read.


This article is included in the WeChat public account: 愤怒的代码 AngryCode