System Optimizations for Cost-Efficient Agent Harnesses
Jongseok Park, Jiaxiang Yu, Eric Zhou, Tony Hong, Sunga Kim, Yusuf Afifi, Ian Wong, Ion Stoica, Alvin Cheung
cs.AI
2026-11-09
Berkeley finds cache re-reads of old context dominate agent cost (up to 73%); its Agency interposition layer cuts cost up to 35% on unmodified Claude Code and Codex.
A coding harness like Claude Code or Codex gives an LLM its system prompt, tool set, and call loop. The paper opens with a useful negative result: on current agentic models (GPT-6, Claude-5.5), swapping the full harness for a bare ReAct loop with no system prompt and only a bash tool leaves task accuracy essentially unchanged. Cost is another story. Claude Code and Codex runs easily cost 2x the minimal harness on the same model and task, and harness choice alone produces spreads up to 2.6x. Claude Code carries a 4.1K-token system prompt plus 8.7K tokens of tool schemas, all of it re-billed on every call. The harness layer's real optimization target is money, not accuracy.
First, the accounting. The authors profiled public traces (TraceLab, FreeInference) and their own benchmark runs, and found five cost patterns:
Agency is the delivery vehicle, inspired by Valgrind. A sandbox engine wraps the harness subprocess in ptrace and cgroups, captures every LLM call and file access, and translates them into a common format; context lives in hash-keyed message blocks that hooks can swap for empty or compressed versions. Neither the harness binary nor the model changes. Measured overhead: -1.50% per-task cost, 95% CI [-4.69%, +2.04%].
Five techniques follow. Context compression: tool output compaction (mechanical, near-lossless, 14% average reduction, zero cost); context garbage collection (a GBDT predicts per-line reuse probability and fires only when predicted net savings are positive, 47% per compaction); a subtask stack machine (context as a stack, finished subtasks popped, 91% per compaction, about once per 20 turns). Turn reduction: metadata-assisted search (offline SQLite tables over the filesystem; one SQL query replaces a chain of ls/grep, up to 80% fewer search calls); tool call batching (a user prompt nudges the model to issue independent calls together, up to 30% fewer turns).
200 tasks (100 coding, 100 retrieval) across 4 models and 3 harnesses:
| Setting | Metric | Result |
| All tasks average | cost / accuracy ratio | 0.77 / 0.97 |
| Largest saving (GPT-6-Luna) | cost ratio | 0.70 |
| OfficeQA, UUID names + tree | cost ratio | 0.51-0.66 |
| SWE-bench | cost ratio | 0.80-0.92 |
| Runs over 1M tokens | cost ratio | 0.67 |
| Ablation: metadata search alone | cost | -32% |
| Ablation: batching alone | cost | +2% |
Accuracy holds for the larger models (Opus 0.99, Sol 0.98, Sonnet 0.97); Luna drops to 0.93 because weaker instruction-following makes it misuse the SQLite tables. Per task, 71-83% get cheaper and 17-29% get more expensive, mostly short runs with nothing to compact. One SWE-bench Pro case: baseline context climbs to 61.3K tokens, the compacted run ends at 16.3K, and total prompt tokens fall from 4.0M to 2.6M. Savings scale with run length: tasks with at most four tool calls save 6%, runs over 1M tokens save 33%.
The accounting may be more valuable than the system itself: agent spend goes to re-reading old context, not generation, and turn count and context length are two independent levers, since every removed turn saves a full cache read. Metadata-assisted search pays off most in retrieval-heavy work, and the messier the directory layout the bigger the saving; coding tasks gain less because frontier models already know repository structure and rarely query the index. Agency shows that deterministic cost optimization can sit outside black-box commercial harnesses instead of waiting for vendors. The improvements are incremental, but the measurement method transfers directly to auditing your own agents.
The authors flag several: the analysis is built on current inference pricing, which may change; some techniques depend on model behavior, and the batching prompt is unreliable on smaller models; the Section 3 ratios are hindsight statistics and should be read as upper bounds, with Section 5 numbers as proof-of-concept floors. Points that stand out on a close read: benchmark traces run 2-3x shorter than real sessions, so neither end represents daily long-horizon use; batching is net-negative in the ablation (+2%) yet still enabled in the combined run; the 35% headline is an "up to" figure on specific setups, while the average saving is 23%; and Luna's accuracy drop shows real risk for weaker models.