English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

AutoHarness: Small LLMs Self-Write Code Shields to Eliminate Illegal Moves

Forum topic · ✨步子哥 · 2026-03-21

Summary

AutoHarness (arXiv:2603.03329) tackles a common failure of LLM agents: generating invalid actions in rule-bound environments. In Kaggle's GameArena chess competition, Gemini-2.5-Flash lost 78% of its games not due to weak play but because it produced outright illegal moves. AutoHarness lets the small model iteratively synthesize its own Python-based harness: it proposes candidate validation code, runs it in the real environment, reads error feedback, and refines the code using Thompson sampling—converging in about 14.5 iterations on average. After harnessing, Gemini-2.5-Flash achieves a zero illegal-move rate across all 145 TextArena game variants, and outperforms the unharnessed Gemini-2.5-Pro in two-player win rate (56.3% vs 38.2%). Pushing further, the model distills entire game policies into pure Python code, achieving a 0.870 average reward on 16 single-player games with zero inference cost, surpassing Gemini-2.5-Pro and GPT-5.2-High. The work shows that code synthesis plus feedback loops can let lightweight models self-improve beyond larger ones.

Imagine an AI agent stepping into a game universe of boards, text adventures, and card duels—only to hear "Illegal move! Game over!" That was the reality in early 2026: large language models, brilliant at conversation, kept tripping over environment rules when acting as agents. A research effort called AutoHarness (arXiv:2603.03329) changes this by letting small models weave their own "code armor."

The Problem: Why Smart AI Breaks the Rules

In Kaggle's GameArena chess competition, Gemini-2.5-Flash lost 78% of its games not because of weak chess skill, but by playing outright illegal moves—like moving a king into check. LLMs are, at heart, next-token predictors without a built-in "rule radar." In TextArena, a benchmark spanning 145 game variants (single- and two-player, from riddles to strategy), any game can trigger violations.

A quick primer: an LLM agent is a language model placed inside a decision loop, outputting actions based on environment state. If the model invents an impossible action ("fly into the sky"), the environment rejects it and the agent stalls. This "environment incompatibility" is a core pain point for future AI assistants, robot butlers, and automated programmers.

Old Solutions: Manual Shields and Expensive Fine-Tuning

Previous fixes had serious drawbacks:

  • Hand-written harnesses: Programmers wrote guard code that checked every action. Effective but costly—every new environment needed a new harness, and rule changes broke them.
  • Fine-tuning giant models: Trying to make a huge model "memorize" all rules is expensive and unreliable. Even Gemini-2.5-Pro, when unharnessed, still violates rules.
  • The AutoHarness Method: Iterative Self-Refinement

    AutoHarness lets Gemini-2.5-Flash write its own Python shield:

    1. The model proposes a candidate harness—a function that checks whether an action is legal in the current state (e.g., castling in chess requires never having been in check). 2. The code runs in the real game environment, which returns error logs ("this move leaves the king in check—invalid"). 3. The model revises the code based on feedback, with Thompson sampling selecting the most promising modification paths. 4. After an average of 14.5 iterations, a perfect shield emerges.

    Crucially, the whole process is driven by the small model itself—no large teacher model required.

    Results: Zero Violations and a Small-Model Upset

  • Zero illegal moves across all 145 TextArena games (single- and two-player variants).
  • Two-player win rate: 56.3% for harnessed Gemini-2.5-Flash, versus only 38.2% for unharnessed Gemini-2.5-Pro.
  • Single-player average reward improved from 0.707 to 0.745.
Why does a small model beat a bigger one? The harness outsources rule compliance to code, freeing the model to focus on strategy.

The Endgame: Pure-Code Policies

Pushing further, the team had Gemini-2.5-Flash compile entire game strategies into pure Python scripts—no LLM call needed at decision time. The result: zero inference latency and cost, and an average reward of 0.870 across 16 TextArena single-player games, beating both Gemini-2.5-Pro and GPT-5.2-High. It's like a chef writing down a lifetime of recipes—fast, cheap, stable, and portable.

Implications

Beyond games, the approach suggests applications in autonomous driving (real-time traffic-rule validation), coding assistants (avoiding syntax errors and vulnerabilities), and robotics. The core insight: lightweight models, through code synthesis plus feedback loops, can self-evolve and outperform giant models.

References

1. Lou, X. et al. AutoHarness: improving LLM agents by automatically synthesizing a code harness. arXiv:2603.03329 (2026). 2. TextArena benchmark environments: evaluating text agents across multi-game variants (per the paper's extended description). 3. Gemini model family technical reports: performance comparisons and Kaggle competition data for Gemini-2.5-Flash and Pro. 4. Research on code synthesis in AI agents: iterative feedback and Thompson sampling for self-generated policies. 5. parikhakshat/AutoHarness GitHub repository: an early fuzzing-harness auto-generation tool echoing the code-synthesis idea.

Tags

#llm-agents#autoharness#code-synthesis#gemini#textarena#reinforcement#ai-agents#thompson-sampling

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/177168936