Harness Engineering for Agents
Harness Engineering for Agents
A language model cannot act on its own. It emits text, and something else must parse that text, run the requested actions, and return the results. That surrounding runtime is the harness. Designing it is where most of the hard engineering in agent systems lives, because the harness must keep the system correct, bounded, secure, and recoverable when the model errs, the network fails, or the process dies mid-task.
Foundations & The Minimal Loop
Every agent starts as a loop: the model proposes an action, the harness executes it, and the result returns to the model's context. Build this loop yourself before trusting anything more elaborate, and watch it fail. The failures you meet, such as context rot from oversized tool output and half-applied edits after a crash, set the requirements for everything that follows.
Production Loops Context Control & Trust Boundaries
A minimal loop breaks under real load, so production harnesses add structure. Sessions hold turns, turns hold steps, and each step exposes explicit state that can be streamed out and steered mid-flight. Context becomes a managed resource rather than a growing transcript, and the sharpest boundary is trust: secrets and orchestration stay in a trusted runtime, while files and shell commands run in a sandbox that never holds a credential.
Durable Execution Replay Safety & Subagents
A process that dies mid-turn should resume where it stopped, not repeat a payment or resend an email. Durability comes from committing intent before a side effect runs and committing the result after it finishes. Call this pattern the effect sandwich. Recovery then knows exactly what happened, and structured concurrency keeps aborts and failures propagating through a tree of child conversations instead of leaving orphaned work behind.
Pure State Machines Fail-Closed Security & Systems Rigor
Recovery logic is where subtle bugs hide, so the decision code should be pure: given a state and an event, it returns a new state and actions, with no I/O and no clock reads. That purity makes retry and lease rules testable and checkable with a model checker such as TLA+. The same caution governs security, where an uncertain permission check, shell parse, or review means the action is held rather than allowed.
Code Mode Brain-vs-Hands & Multi-Harness SDKs
Calling tools one at a time forces every intermediate result through the model's context. Code Mode lets the model write a small program that runs many calls inside a sandbox and returns only the final result. Separating durable brains from ephemeral hands, and abstracting providers behind one runtime, lets the system scale across machines and model families without losing their native conventions.
Verification Simulation & Production Readiness
A harness that works on the happy path proves little, since the hard cases involve crashes, timeouts, and malformed JSON arriving at the worst moment. Verification therefore injects those faults deterministically, so any failing run can be replayed exactly rather than hoped away. Conformance suites confirm that each storage backend honors the same guarantees, while behavioral evals and OpenTelemetry tracing measure whether the agent does the right thing across many runs.
AI-generated study article from SophistAI. Sign up free to study it with an AI tutor.