Agent = Model + Harness: How to Engineer Agents for Production
An agent is more than a language model. This article explains the formula Agent = Model + Harness, why a model call alone cannot handle stateful, side-effecting work, and how context, execution, tools, memory, safety, and observability turn model output into reliable action. It also covers the execution loop, security boundaries, common cloud building blocks, frequent pitfalls, and a practical rollout path.
1. The core formula: separate “smart” from “able to work”
The most useful way to understand how an agent reaches production is a simple equation:
Agent = Model + Harness
The model is the “brain.” It interprets intent, reasons, plans, and generates content. The harness is the “body and tack” attached to that brain. The word harness originally means horse tack: if the model is the horse, the harness determines whether it can be controlled, run steadily, and complete the assigned work.
This split is valuable in engineering because it separates two different failure modes: “the model is not strong enough” and “the engineering is incomplete.” Many agent projects fail not because the model lacks capability, but because the harness is missing. The model cannot see real files, run commands, receive tool results, or retry after failure, so it can only talk about the work instead of doing it.
In short: the model thinks and generates; the harness connects those abilities to the file system, terminal, web, and tool chain so the AI can actually work in a real environment.
2. Why a model by itself is not an agent
A single model call is a stateless function with no side effects and no awareness of its environment: text in, text out. Real tasks have three properties that a model cannot cross on its own:
- State: A task spans multiple turns and must remember completed actions and intermediate artifacts.
- Side effects: Writing files, changing configuration, and calling interfaces means accepting failure and rollback.
- Environmental constraints: Directory structure, permission boundaries, dependency versions, and network reachability are not inside the model’s context.
The harness is the engineering layer that supplies these three properties. It decides what the model can see, what it can do, and what happens when it is wrong. As a result, the difference in task success for the same model under different harnesses is often larger than the difference between models.
3. A layered view of the harness
A mature harness usually provides six layers:
- Context: Assemble system instructions, the task description, an environment snapshot, the history, and the tool list, then trim and compress them to fit the budget.
- Execution: Run commands, read and write files, and access the network inside a sandbox, then collect standard output, error codes, and exit status.
- Tools: Expose capabilities through a unified protocol—retrieval, computation, code execution, and business interfaces—and declare parameter schemas and side-effect levels.
- State and memory: Store the task state machine, intermediate artifacts, and searchable long-term memory so a run can resume after interruption.
- Safety: Apply least privilege, confirmation for dangerous actions, path and network allowlists, and secret custody.
- Observability: Provide end-to-end tracing, token and latency accounting, failure attribution, and evaluation regression.
4. Key mechanism 1: context engineering
Context is the agent’s scarcest resource. Practical points include:
- Load in layers: Keep role and hard constraints resident; load tool descriptions and retrieved snippets on demand instead of filling the context all at once.
- Compress structurally: Fold long logs into “conclusion + key evidence + a retrievable reference,” rather than simply truncating them.
- Externalize memory: Write intermediate artifacts to a workspace or object storage. Keep only paths and summaries in context, and read them back when needed.
- Keep tool descriptions lean: More tools mean a higher chance of choosing the wrong one. Mount a subset dynamically for the current scenario.
5. Key mechanism 2: the execute–observe–correct loop
An agent is a controlled loop, not a single generation. A minimal skeleton looks like this:
def run_agent(task, harness, max_steps=20):ctx = harness.build_context(task) # context layerfor step in range(max_steps):action = model.plan(ctx) # model returns a structured actionif action.type == "final":return action.answerif harness.needs_confirm(action): # safety layer: confirm high-risk actionsharness.ask_user(action)result = harness.execute(action) # execution layer + tool layerctx = ctx.append(action, result) # state layer: keep the traceif result.failed and step > 0:ctx = ctx.append(harness.diagnose(result)) # error-feedback loopreturn harness.escalate(task) # terminal fallback
Four elements must be designed explicitly:
- A structured action protocol: Actions use schema-based fields so they can be validated and audited, avoiding ambiguous free-text parsing.
- Termination conditions: Success, budget exhaustion, a step limit, and repeated-action detection are all required. Without them, the loop can run indefinitely.
- Error feedback: Returning error codes and stack traces to the model is the main source of self-correction.
- Idempotency and rollback: Write operations must be re-entrant. Snapshot critical changes before applying them so failures can be recovered.
6. Security boundaries: stronger capability requires earlier constraints
- Sandbox isolation: Run code and commands in a separate container, with limits on CPU, memory, duration, and file-system scope.
- Least privilege: Default to read-only access. Grant write permission and network egress per task, and inject credentials from a secret-custody service instead of writing them into context.
- High-risk gates: Require human confirmation for deletion, bulk changes, production releases, and similar actions.
- Full audit: Keep the complete trace for review and compliance checks, and send logs and metrics to general logging and monitoring-and-alerting systems.
7. Combining the harness with common cloud capabilities
The harness’s “body” usually depends on infrastructure. These general capabilities can be combined as needed: a container platform hosts sandboxed execution; object storage keeps the workspace and artifacts; a message queue decouples long-running tasks from asynchronous callbacks; logging and monitoring provide observability; and secret and permission systems tighten access boundaries. In cloud environments such as Baidu AI Cloud, these general categories can be assembled as required. A controllable agent runtime does not have to be tied to one proprietary interface.
8. Common pitfalls
- Calling the model without building a harness: Engineering problems are misdiagnosed as model problems, and switching models repeatedly does not help.
- Expanding the tool set without limit: More tools increase both wrong selections and context bloat.
- No termination and no budget: Without step and cost limits, long-tail tasks run out of control.
- Favoring demos over evaluation: Without regression tests on a fixed task set, the success rate after a change is unknown.
- Ignoring rollback: Once an agent can write, rollback is a first-class requirement.
9. A practical rollout path
- Choose a frequent, verifiable scenario with clear boundaries, and define what “done” means.
- Build a minimal harness first: read-only tools, a sandbox, and trace retention, then get the loop working.
- Create an evaluation set of 20 to 50 tasks and measure success rate, step count, and cost.
- Gradually open write permissions and add tools, adding a safety gate and rollback at each step.
- Use context compression and tool pruning to control cost, and use monitoring and alerting to protect production stability.
Conclusion: The model sets the agent’s capability ceiling; the harness determines how much of that ceiling can actually be delivered. Treating the harness as a first-class engineering object—designed, measured, and governed—is the dividing line between an agent demo and an agent in production.
