Large language model agents rely on harnesses to manage context, tools, and termination, but a fixed harness is suboptimal across diverse tasks. The authors introduce Harness Primitives, reusable mechanisms mined from failed execution trajectories, each with a defined scope and composition contract. Their STITCH framework selects suitable primitives based on task information and compiles them into a task-specific harness at test time, avoiding the brittleness of generating harness code from scratch.
Experiments on SWE-bench Verified and Terminal-Bench 2 show that STITCH outperforms fixed harness baselines by up to 12 percentage points in success rate, surpassing human-designed harnesses like Codex CLI. The composition overhead is only 2.7% of execution cost, making it 638 times more efficient than generating task-specific harness code. The approach scales with the primitive library size and generalizes across models and task domains.