Model + Harness: How to Build an Agent That Can Actually Do Work
A larger model alone does not produce an agent. This article breaks down the Model + Harness = Agent principle: the model handles understanding, reasoning, and generation, while the harness connects those abilities to real workflows through context management, tool calls, planning, sandboxed execution, and feedback loops. It covers a recommended four-layer architecture, a minimal plugin contract, how a single task runs end to end, practical context rules, stop conditions, evaluation, safety, and a checklist for judging whether your framework is agent-grade or just "chat with tools."
An agent does not appear automatically when you swap in a bigger model. A more reliable engineering view is this: the model handles understanding, reasoning, and generation, while the harness connects those abilities to real workflows. Together they form an agent that can execute tasks. You can write it as a formula: Model + Harness = Agent. The point is not a product name but a division of labor. The base model supplies general intelligence; the execution framework fills in environment, state, permissions, and feedback.
Why the model alone is not enough
Large models are good at turning natural language into plans, draft code, or explanations, but they operate by default within the boundary of one request and one reply. Real work spans multiple turns, multiple files, and several external systems, and it has to be replayable, interruptible, and auditable. Writing a longer prompt does not solve these problems reliably.
The typical gaps include:
- Context for long tasks grows and can even contaminate itself.
- The model does not know the real state of the current repository, ticket, or data.
- Tool calls lack parameter validation and permission control.
- After a failure there is no structured feedback, so the model can only retry by guessing.
- There are no checkpoints between steps, so a crash midway forces the whole task to restart.
What the harness fills in is exactly this work beyond the model’s boundary.
What the harness actually contains
Think of the harness as a middle layer between the model and the environment, not as another, smarter model. It usually covers the following capabilities.
Context management. Assembling system instructions, task goals, relevant file fragments, tool results, and past decisions, plus trimming by relevance, summarizing, and layered caching. The goal is not to stuff in all history but to let the model see, within a limited window, the evidence required for the current decision.
Tool calls. Wrapping retrieval, computation, file reads and writes, API requests, terminal commands, and similar actions into schema-constrained actions. The model only proposes intent and parameters; the framework validates, executes, handles timeouts and retries, and feeds results back.
Task planning. Breaking a vague goal into verifiable sub-steps, marking dependencies, completion conditions, and stop conditions. The model can take part in planning, but the plan’s state machine should be held by the framework, so the model does not revise the goal mid-conversation and cause goal drift.
Environment execution. File changes, command execution, and external writes all need a working directory, sandbox, or permission scope. Read-only exploration and actions with side effects should be kept separate.
Feedback and evaluation loop. Every action should return a machine-readable result: exit codes, diffs, test output, validation errors. The agent corrects based on these rather than “feeling” in natural language that the fix is done.
A recommended layered structure
In practice you can use four layers instead of piling all the logic into one prompt.
- Model layer: dialogue, planning, and generation of code and explanations. Replaceable, not tied to a single vendor.
- Policy layer: role, goals, constraints, output format, and when a human must be asked first.
- Runtime layer: session state, context assembly, tool routing, concurrency and retries, checkpoints.
- Plugin layer: concrete tools and domain adapters. Retrieval, codebase, tickets, data tables, and release pipelines all plug in.
“Everything is a plugin” here means that domain capabilities are not hard-coded into the runtime core. The core only defines the lifecycle and interfaces; each plugin declares what it can do, what permissions it needs, and how it reports on failure. This lets the same runtime serve coding, operations troubleshooting, or knowledge organization without letting one scenario’s assumptions spread into global coupling.
The minimal plugin contract can stay plain: name, description, input schema, permission level, whether it has side effects, execution function, and result structure. The runtime depends only on the contract, not on the plugin’s internal implementation. An example:
plugin:
name: read_file
side_effect: false
permission: workspace_read
input: { path: string, max_bytes: int }
output: { content: string } | { error: string }
Plugins with side effects should additionally declare a confirmation policy. For example, writes, deletes, and outbound sends should require a diff preview or human confirmation by default, while read-only plugins can run automatically. Permissions should not rely on a prompt that says “please do not do anything dangerous”; they should rely on the runtime refusing unauthorized calls.
How a single task runs
Take “fix a defect based on a failure log and add a test” as an example. The loop can be:
- Feed in the task description, the relevant logs, and the directory scope that may be accessed.
- The runtime retrieves possibly relevant files and injects only summaries and matched fragments.
- The model gives a hypothesis and a next step, rather than outputting a whole-repository patch at once.
- The framework runs read-only checks and feeds the real error back.
- The model proposes a minimal change; the framework generates a diff and runs the tests in an isolated environment.
- If a test fails, the failing assertion and relevant line numbers are returned, with a limit on the number of retries.
- Once it passes, the agent writes a change description and remaining risks, then waits for human confirmation before merging.
The key here is being evidence-driven. The input to every step should be traceable to a tool result or user-provided material. The model’s inferences should be recorded separately from observations, so you can audit later why a particular change was made.
Practical rules for context management
Longer context is not better. Effective practices usually are: keep stable instructions short and fixed; store the task goal separately; summarize past dialogue by phase; keep the raw text of tool results only for the most recent few turns and retain only conclusions and location information for earlier ones; replace large files with paths, symbols, and fragments.
You also need to separate “what the model needs to see” from “what the framework keeps for itself.” Checkpoints, permissions, retry counts, and cost budgets are runtime state and need not all be turned into natural language. Otherwise the model will mistake internal control information for business content.
When context approaches the window limit, drop duplicate logs and outdated plans first, rather than truncating the latest error. Summarization should be done by a dedicated call and should retain traceable original references, so the summary does not quietly rewrite the facts.
Planning, execution, and stopping
A plan should be executable and falsifiable. Each sub-task is best paired with a completion criterion, such as “a specified test passes” or “the API returns fields that match the agreement,” rather than “looks optimized.” The executor schedules by dependency and, on failure, rolls back only the dirty state of that sub-task.
You must set stop conditions: reaching a step limit, the same error recurring, an action requiring excess permissions, or confidence too low to keep editing automatically. After stopping, hand the confirmed facts, unfinished items, and a suggested next step to a human. Being able to stop is part of an agent’s usability, not a failure.
The human-machine division of labor should also be spelled out. Exploration, drafting, and local edits are suited to automation; merging, releasing, deleting data, and external commitments are suited to confirmation. The confirmation interface should show the diff and the scope of impact, not just ask “continue?”
The evaluation loop
An agent without evaluation can only demo, not iterate. Evaluation has at least three layers.
- Tool level: whether parameters are valid, and whether timeouts, permission denials, and empty results are handled correctly.
- Task level: given a fixed ticket or defect sample, whether the agent reaches the criterion within a budgeted number of steps.
- Regression level: after a plugin or prompt change, whether old tasks got worse. Watch success rate, average steps, invalid-retry rate, and human-takeover rate, not just one impressive single-shot output.
Samples should cover edge cases such as insufficient permissions, missing files, flaky tests, and ambiguous instructions. Turning failure cases into replayable traces is worth more than piling on another system prompt.
Risks and rollout order
An agent expands the model’s radius of action, and with it the radius of mistakes. A minimal safety set includes: read-only by default, workspace isolation, a command allowlist, keeping secrets out of the context, second confirmation for outbound actions, and a full audit log. The model treats a plugin’s description as an available capability, so the description must be truthful; do not write unimplemented capabilities into the tool spec.
Roll out from narrow to broad. Start with a single repository, read-only plus controlled patches; then add test execution; once traces are confirmed replayable, connect to the ticket or release system. Each time you widen permissions, fill in the corresponding confirmation and rollback. Do not open many high-permission plugins at once while context management is still unstable.
Using cloud object storage to save traces, a message queue to split long tasks, containers to isolate command execution, and logging and monitoring to observe failure types are all just general categories of capability. Choose based on whether isolation, auditing, and cost fit, rather than binding the runtime to one proprietary set of interfaces.
How to judge whether a framework is up to the job
You can self-check with a few questions: after switching to a different model, do the tools, permissions, and evaluation still work; after removing “please be careful” from the prompt, are dangerous actions still refused; are failure results structured; can the same task resume from a checkpoint; can plugins be added independently without changing the core loop. If the answer to most of these is no, the system is still “chat with tools,” not an agent that can enter a workflow.
The model sets the ceiling on capability; the harness decides whether those capabilities can be constrained, verified, and reused. Only when context, tools, planning, execution, and evaluation are given clear boundaries does an agent turn from a one-time generation into an operable chain of work.
