Agent Harness Engineering: Turning Model Capabilities into Reliable Systems

    This article explains why the harness—the execution layer surrounding a large language model—has become a central topic in agent engineering. It covers how capabilities shift upward into models while engineering requirements sink downward, why general-purpose and vertical agents work best as layered collaboration, where multi-agent systems are and are not worth the added cost, and the key engineering elements of a harness: context management, tool governance, sandboxing and permissions, state and recovery, observability, and evaluation loops. It also addresses security and compliance when agents can read code and run commands, how to decide between managed infrastructure and self-built components, and how to turn repeated workflows into reusable, version-controlled skill modules.

    1. Why the Harness Became the Core Topic in Agent Engineering

    The agent space has recently seen a clear shift in attention. First, a minimalist command-line agent format gained traction in overseas communities. Then a wave of general-purpose agent products built around closing the loop on executable tasks drew rapid interest, along with debate about how they were built—questions about code-level similarity, the boundary between open and closed source, and whether certain internal components should be published. Strip away that noise and what remains for developers to build on is a concept that comes up constantly yet is often confused: the harness.

    A harness is best understood as the execution shell wrapped around a large language model. It handles context assembly, tool registration and invocation, permissions and sandboxing, state persistence, retry on failure, observability, and cost control. The model supplies reasoning and generation; the harness determines whether those capabilities convert reliably into deliverable results. The same model behind a different harness can differ severalfold in task success rate and cost. So when we argue about the harness, we are really arguing about how controllable agent engineering is.

    2. Will Models Absorb Agents? Capabilities Move Up, Engineering Sinks Down

    One popular view holds that as models improve, prompts, workflows, and surrounding frameworks will gradually be absorbed. A more precise reading is that this happens in layers:

    • Moving up into the model: task planning, prior knowledge for tool selection, format compliance, and locating information in long contexts. These capabilities will increasingly be built in, and tricks that patch gaps with elaborate prompts will lose value.
    • Sinking down into engineering: permission isolation, audit trails, resource quotas, data compliance, and cross-system transactional consistency. These needs do not disappear as models get stronger; they amplify as automation increases.

    The conclusion is not that models replace frameworks, but that the center of gravity in frameworks shifts—from teaching a model how to think toward constraining what it can do and how failures are contained. This is why investing in both models and agents is not a contradiction: the model sets the ceiling, while the harness sets the floor and determines deliverability.

    3. General-Purpose vs. Vertical Agents: Layered Collaboration, Not Replacement

    General-purpose agents excel at cross-domain exploration, long-tail tasks, and fast validation. Vertical agents offer better cost-efficiency where processes are well defined, interfaces are stable, and accuracy requirements are high. The decision can be framed along three dimensions: how structured the task is, the cost of an error, and how verifiable the result is. When errors are costly and results can be checked automatically, vertical is the better bet; when requirements are open-ended and the process cannot be enumerated in advance, general-purpose fits better.

    The more common production pattern is general-purpose orchestration plus vertical execution: an upper layer clarifies intent and decomposes the task, while a lower layer of specialized modules performs deterministic operations.

    1. # Illustration: division of labor between the orchestration layer and the execution layer
    2. def run(task: str, ctx: Context) -> Result:
    3. plan = planner(task, ctx) # general layer: decompose and select
    4. steps = [s for s in plan.steps if s.risk == "low"]
    5. for s in steps:
    6. r = registry[s.tool].invoke(s.args, ctx) # vertical layer: deterministic execution
    7. ctx = ctx.append(s.id, r) # persist state to enable replay
    8. if not r.ok and not can_retry(s):
    9. return escalate(plan, ctx, r) # escalate to a human or a high-risk channel
    10. return summarize(plan, ctx)

    4. Where Multi-Agent Collaboration Pays Off

    Multi-agent systems are not better by default. They add parallelism and role separation, but also context synchronization cost, error propagation, and evaluation difficulty. Practical guidance:

    1. Introduce multi-role collaboration only when subtasks can be cleanly partitioned and the merged result can be validated automatically.
    2. Give each role a minimal toolset and its own quota to prevent permission sprawl.
    3. Use a “controller plus restricted sub-agents” structure in which sub-agents return only structured conclusions and never operate external systems directly.
    4. Establish a unified trace identifier so every collaboration can be reconstructed as a replayable execution tree; otherwise production issues are nearly impossible to localize.

    5. Key Engineering Elements of a Harness

    • Context management: layered memory (within a session, per task, long term), combined with retrieval and summarization to control token cost and noise.
    • Tool governance: describe each tool’s name, purpose, parameters, and risk level declaratively; validate arguments and enforce allowlists at runtime.
    • Sandboxing and permissions: minimize filesystem and network egress, require a second confirmation for sensitive operations, and inject credentials from an external key management service rather than writing them into configuration.
    • State and recovery: write intermediate artifacts to object storage, decouple task state from message delivery, and support resume-from-checkpoint and idempotent retries.
    • Observability: collect call chains centrally in a logging service, and cover success rate, latency, and cost per task with monitoring and alerts.
    • Evaluation loop: maintain an offline test set and online canary comparison; any prompt or tool change must pass regression.

    6. Security, Compliance, and Protecting Code Assets

    Once an agent can read and write a codebase and execute commands, its risk profile is equivalent to handing developer privileges to a probabilistic system. The minimum requirements: default to read-only and elevate on demand; run builds and execution in disposable instances on a container platform; audit all outbound output and tool calls in full; and keep identity authentication and real-name policies transparent to avoid the accountability vacuum created by shared accounts. Code leak incidents should be handled as supply chain security problems: rotate credentials, review dependency sources, and verify artifact signatures.

    7. Build vs. Buy for Agent Infrastructure

    The opportunity in agent infrastructure sits in the areas that are standardized yet hard to do well: sandbox runtimes, tool registration and governance, evaluation and replay, cost attribution, and permissions and auditing. For most teams, assembling a controllable foundation from general-purpose cloud offerings (container platforms, object storage, message queues, logging services, monitoring and alerting) is more economical than building everything in-house. Self-building is worth it only when a component is a core differentiator or subject to strict compliance constraints. Baidu AI Cloud is typically one of the general-purpose foundation options in these scenarios, but selection should still be driven by load test data and compliance requirements.

    8. Turning Experience into Reusable Assets

    A repeatedly validated practice is to solidify individual experience into skill modules: write repetitive processes as scripts or skill descriptions with explicit input and output contracts, attach failure cases and validation rules, put them under version control, and keep running regression. The value is not in replacing people but in keeping organizational capability from walking out the door with them.

    As for the “fully agent-driven company,” the more realistic form today is a very small team layered on a highly automated execution layer: people define goals, make risk decisions, and carry external accountability, while agents take on the repetitive work of retrieval, coding, testing, and operations. To judge whether a team is actually capturing the gains, look at two metrics only: whether the marginal cost per deliverable keeps falling, and whether mean time to recovery from production incidents keeps shrinking.