Agent Underperforming? Start with Harness Engineering, Not a New Model

    When AI agents deliver poor results, teams often rewrite prompts or switch to larger models. This article argues that the root cause is usually the execution environment, or Harness, rather than model intelligence. It explains how to separate model issues from environment issues, outlines eight core capabilities of a production-grade Harness (request boundaries, query manuals, tool contracts, session memory, observability, permissions and approvals, rule redundancy, and problem hardening), and provides a four-step adoption path with cloud support considerations. Readers will learn how to turn model capability into reliable output by fixing the environment first.

    Introduction: Why a “Smarter Model” Does Not Always Deliver Better Results

    A recurring pattern appears when teams deploy AI agents in production: when the output is unsatisfactory, the first instinct is to rewrite prompts, switch to a model with more parameters or stronger reasoning, or stuff as much documentation as possible into the context. These tactics usually bring only a short-lived improvement, and the problem soon returns.

    The root cause is rarely intelligence. It is the environment. The model handles reasoning and suggestions, but it does not inherently know which tools to call, in what order to execute them, where intermediate artifacts should be written, what conditions define completion, or which actions must be blocked. These are defined by the external execution environment, commonly referred to as the Harness. The Harness determines whether model capability can be reliably converted into usable output.

    An analogy helps: talented people are not scarce, but without a sound education system and a good working environment, their ability is hard to realize. A Harness is like an organization with well-designed processes and complete infrastructure, enabling people with the same talent to produce higher-quality results.

    1. Problem Diagnosis: Separate Model Issues from Environment Issues

    Before optimizing anything, perform attribution so that engineering defects are not mistaken for model defects. Use the following sequence:

    1. For the same task, can a human succeed by following the same steps? If yes, the task is solvable and the problem lies in the execution environment.
    2. Are failures concentrated in a specific stage (finding files, running tests, writing artifacts, judging completion)? Concentration in one stage usually means that stage lacks a tool or lacks validation.
    3. Are the failures reproducible? Consistently reproducible failures are mostly caused by missing rules or permission misconfiguration, while random failures are mostly caused by missing observability and feedback.
    4. Is the prompt already specific enough to be verifiable? With vague instructions such as “help me optimize this,” no model can deliver reliably.

    An illustrative attribution record structure:

    1. failure_report:
    2. task_id: "T-1024"
    3. stage: "test_execution" # The stage where the failure occurred
    4. symptom: "Declared completion without running tests"
    5. hypothesis: "Missing completion validation" # Hypothesis about the environment defect
    6. evidence: ["log#88", "diff#12"]
    7. next_action: "Add a mandatory validation step before completion"

    Investing in Harness development pays off only when attribution points to the environment.

    2. Eight Core Capabilities of a Production-Grade Harness

    1. Request Boundaries and Acceptance Criteria

    First, converge the user request into a structured form, turning vague intent into a constrained task description with verifiable acceptance criteria. Constraints should include at least: the scope of changes, paths that must not be touched, resources that may be used, and the delivery format. Acceptance criteria must be machine-verifiable, for example, “new unit test coverage is no lower than the existing baseline” or “the specified command returns exit code 0.”

    1. Task: Fix the login timeout issue
    2. Scope: Only the service/auth directory
    3. Forbidden: Modifying database table structures
    4. Acceptance: New cases cover the timeout branch; all test commands pass; no new alerts

    Once boundaries are clear, the model no longer needs to guess intent, and the probability of going off track drops significantly.

    2. Query Manual: Let the Agent Know Where to Find Information

    An agent needs a stable entry document describing the repository structure, module responsibilities, available scripts, conventions, and where common issues are located. Its value is turning “searching” into “looking up a table,” reducing unproductive exploration and wasted context. The manual should stay concise, navigable, and synchronized with the code, and it should explicitly state what to do when information cannot be found.

    3. Tool Contracts: Every Interface Needs a Specification

    Each tool must declare its purpose, input structure, output structure, failure modes, and side effects. Without contracts, the model can only guess parameters, resulting in many invalid calls.

    1. {
    2. "name": "run_tests",
    3. "description": "Run automated tests for a specified scope and return structured results",
    4. "input": {"path": "string", "pattern": "string?"},
    5. "output": {"passed": "boolean", "failed_cases": "array", "duration_ms": "number"},
    6. "side_effect": "read_only",
    7. "failure_modes": ["compile_error", "timeout"]
    8. }

    Declaring side-effect attributes such as read_only or write is the foundation for subsequent permission control.

    4. Session Memory: Persist Decisions, Not Just Conversations

    Keeping only the raw conversation causes an agent to repeatedly forget key conclusions during long tasks. Decisions, outputs, errors, and risks should be externalized into readable files or structured records, forming a searchable memory layer. The principle is: important conclusions must be written to disk with timestamps and sources, so they can be traced and reused.

    1. ## Decision Log
    2. - Adopted asynchronous retries instead of synchronous blocking, because it avoids request pile-up
    3. ## Risks
    4. - Cache invalidation may cause transient spikes; rate limiting is needed as a fallback
    5. ## Incomplete
    6. - The canary switch has not yet been integrated with the configuration center

    5. Observability: Use Evidence to Judge Whether the Work Is Correct

    An agent needs “eyes.” Logs, command output, test reports, page screenshots, and static analysis results are all inputs for self-verification. What matters is not how much is recorded, but feeding evidence back to the model at the right moment: automatically attach validation results after each change so that judgments are based on facts rather than self-reporting.

    A minimal loop:

    1. Execute action -> Collect evidence -> Compare against acceptance criteria -> Retry with evidence if failed -> Submit if passed

    6. Permissions and Approvals: High-Risk Actions Must Be Blocked

    Grant permissions by side-effect level: read-only operations run freely; write operations are limited to specific directories; high-risk actions such as deletion, release, and external calls enter a sandbox and require human approval. Approval requests should include an impact description and a rollback plan so that a human can decide within seconds.

    1. policy:
    2. read: allow
    3. write: allow(path_prefix="workspace/")
    4. deploy: require_approval(approver="owner", rollback="documented")

    7. Rule Redundancy: Treat Critical Rules as Infrastructure

    Rules written only in the system prompt are easily overlooked in long contexts. A reliable practice is to state critical rules twice: once declaring that they must be followed, and once running a compliance check before output, with the check result as a precondition for delivery. Rules should also be enforced by tools or pipelines as much as possible, rather than relying on the model’s self-discipline.

    1. Rule: Never submit code that has not passed tests
    2. Declaration: State the constraint explicitly in the system instructions
    3. Validation: Run checks automatically before submission; block and return the reason if it fails

    8. Problem Hardening: Do Not Fall into the Same Pit Twice

    Recurring problems should be converted into rules, checklist items, or new tools rather than patched temporarily each time. The criterion is: if the same type of failure occurs more than twice, it must be hardened into an automated capability. This way, the system’s capability increases monotonically over time instead of looping in place.

    3. Adoption Path and Cloud Support

    A four-step approach is recommended to avoid a one-time rewrite:

    1. Observability first: connect logging services and monitoring alerts to see the failure distribution clearly.
    2. Fill in contracts: write input, output, and side-effect descriptions for high-frequency tools.
    3. Closed-loop validation: automatically feed back evidence such as tests, static checks, and screenshots.
    4. Tighten permissions: introduce sandboxes and human approvals based on risk levels.

    In the cloud, this system is typically carried by several general-purpose capabilities: container platforms provide isolated runtime environments, object storage holds memory and artifacts, message queues decouple long-running tasks, logging services and monitoring alerts provide observability, and key management protects credentials. When selecting services, focus on general metrics such as isolation strength, audit completeness, rollback efficiency, and permission granularity.

    Conclusion

    A Harness is like the laws of physics in the agent world: when rules are clear, feedback is timely, and boundaries are well defined, a model can carve rough input into a refined product; otherwise, even the strongest model can only swap one stone for another. When results fall short, checking the environment definition first is often more cost-effective than switching models.