AI Agent Harness Optimization: 8x Higher Success Rate

    This article examines how the engineering harness around an AI agent—not just the base model—determines task success. Based on a controlled experiment with a fixed model and a fixed 40-task benchmark, it compares three optimization routes: modular refactoring with verification, unconstrained full rewrite, and prompt-rule changes only. Modular refactoring raised the success rate from 5.0% to 40.0% at about 46.7K tokens per task, while the full rewrite reached 42.5% at roughly 451.6K tokens per task, and prompt-only changes dropped success to 2.5%. The article explains why constraints must be enforced in code, how modular harnesses transfer better across models, and which metrics teams should track to evaluate cost versus benefit.

    1. Background: Why a Strong Model Does Not Guarantee Task Success

    A repeatedly confirmed fact in AI agent deployments is that the base model’s capability is only the ceiling. What usually decides whether a task succeeds is the engineering structure wrapped around the model—commonly called the harness. The harness handles prompt organization, tool-call orchestration, context trimming, failure retries, result validation, and state management. No matter how strong the model is, if the harness overflows the context, describes tools vaguely, or swallows errors without retrying, the success rate stays too low to be usable.

    A research team ran a controlled experiment: they fixed the base model and the evaluation tasks, changed only the harness, and observed large differences in outcomes. The value of this kind of experiment is that it breaks the vague problem of “poor agent performance” into engineering variables that can be attributed and addressed.

    2. Experiment Setup: Control Variables to Draw Valid Conclusions

    The core design has three points worth borrowing for any agent evaluation effort:

    1. Fixed model: All approaches use the same base model as the executor, eliminating interference from model capability fluctuations.
    2. Fixed task set untouched by optimization: The evaluation uses 40 software engineering benchmark tasks (issue-fixing) that did not participate in the optimization process, avoiding overfitting to the evaluation set.
    3. Harness changes only, no model changes: The variable is strictly limited to the form of the harness itself.

    Under this setup, the initial harness achieved a task success rate of only 5.0%. This is unsurprising—it matches the typical level of “bare model plus simple prompt”: the model can read requirements but cannot reliably locate files, verify changes, or correct itself after failures.

    3. Head-to-Head Comparison of Three Optimization Routes

    The approach splits the harness into modules with clear responsibilities (such as context construction, tool routing, execution loop, and result validation) and adds an explicit verification step: after a change, tests must run, and if they fail, the agent must roll back or retry.

    Result: The success rate rose from 5.0% to 40.0%, with an average of about 46.7K tokens per task.

    This is a typical engineering gain: no model swap, no brute-force compute—just structuring the workflow and adding validation.

    Route B: Unconstrained Full Rewrite

    The approach lets the optimization process rewrite the harness code without constraints, pursuing extreme performance.

    Result: A 42.5% success rate, only 2.5 percentage points above the modular approach, but with an average of about 451.6K tokens per task—nearly 10 times the modular cost.

    The conclusion is clear: the marginal gain from 40% to 42.5% costs 10 times more. In production, this trade-off almost never holds.

    Route C: Changing Only the Prompt Rules File (Counter-Example)

    The approach leaves the code untouched and only adds constraint clauses to the rules or prompt file.

    Result: The success rate dropped from 5.0% to 2.5%.

    This is the most cautionary finding in the article: constraints written in prompts can be “seen” or ignored by the model at its discretion. The more rules you add, the more diluted the model’s attention becomes, making it easier to go off track. A prompt is not an execution mechanism; it is only a suggestion.

    4. Key Takeaway: Constraints Must Live in Code

    Placing the three routes side by side yields one engineering principle:

    The gains from agent self-improvement come not from “saying more” but from “enforcing more.” Any constraint that must happen should be implemented as a mandatory path in code, not a polite request in a prompt.

    Actionable practices include:

    • Mandatory validation: Make “run tests” a fixed step in the execution loop that halts on failure, rather than leaving the decision to the model.
    • Structured tool contracts: Describe tool inputs and outputs with explicit schemas, and return structured error codes instead of natural-language complaints.
    • Hard context budget limits: Trigger trimming or summarization when the budget is exceeded, instead of expecting the model to ignore overflow on its own.
    • State-machine workflows: Model “locate—modify—verify—submit” as explicit state transitions, rejecting illegal jumps outright.

    Illustrative pseudocode (structure only, no specific product interfaces):

    1. def run_task(task, ctx_budget=50000):
    2. state = "LOCATE"
    3. while state != "DONE":
    4. if state == "LOCATE":
    5. state = locate(task) or "FAIL"
    6. elif state == "MODIFY":
    7. state = modify(task) or "FAIL"
    8. elif state == "VERIFY":
    9. ok, report = run_tests() # Mandatory step, cannot be skipped
    10. state = "DONE" if ok else "MODIFY"
    11. elif state == "FAIL":
    12. return {"success": False, "reason": report}
    13. enforce_context_budget(ctx_budget) # Hard constraint
    14. return {"success": True}

    5. Portability: A Good Harness Is a Reusable Asset

    The experiment also examined cross-model transfer. Without re-running the optimization search, the modular approach reached a 37.5% success rate after migrating to a newer, stronger model generation, while the full rewrite reached 30.0%.

    This reveals another hidden benefit of modularity: a harness with clear structure and explicit constraints delivers gains that carry across models, whereas a tightly coupled rewrite that depends on a specific model’s quirks is more likely to fail after a model switch. For engineering teams, this means the harness should be designed as a long-term asset, not a one-off tuning artifact.

    6. A Method for Evaluating Cost and Benefit

    This experiment offers a reusable evaluation framework. Teams building their own agents should track at least four metrics:

    1. Task success rate (the primary metric, measured on a held-out set untouched by optimization);
    2. Average token consumption (the cost metric that determines whether the system can ship);
    3. Success-rate/cost curve (to judge whether marginal gains have saturated);
    4. Cross-model transfer success rate (to judge asset reusability).

    If 10 times the cost buys only 2 percentage points, the right decision is to stop at the modular approach and invest the budget in expanding the held-out set, building a failure-case library, and adding monitoring and alerting.

    7. Engineering Implementation Recommendations

    • Start with modular refactoring to capture 80% of the gains, then assess whether extreme optimization is worth the investment;
    • Make verification an unavoidable step and ensure failures are observable (logging service plus monitoring and alerting);
    • Use a container platform to fix the execution environment and keep evaluations reproducible;
    • Archive large-scale evaluation samples and results to object storage for regression comparison;
    • If you need to handle concurrent multi-agent workloads, use a message queue for task distribution and rate limiting.

    8. Summary

    With the same model and the same task set, changing only the execution harness raised the success rate by about 8 times at one-tenth the cost of the extreme rewrite; changing only the prompt halved performance. The takeaway for developers is a single sentence: put key constraints in code, make verification part of the workflow, and treat the harness as an asset.