agentleFS
JihaoXinJihaoXin/paper-machine/skills/agent-cost-control/SKILL.md

agent-cost-control

Skill0 starsChanged 3 months agoMITView on GitHub

Keep a long agent run from costing more than the work is worth. Use when planning a multi-hour agent task, when a run is spending unexpectedly, or when tempted to shrink the context window to save money. Contains a measured negative result about history compaction.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Treat a context budget as a safety ceiling against a pathological history, never as a cost lever.

    line 51
  2. Very specific:

    Put the key files in the task: If the agent will obviously need results/exp1.json and the venue template, say so and let it read them once, …

    line 60

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Agent Cost Control

Where the money actually goes

Measured on a 2-page paper produced end to end by an agent, on the cheapest available model:

Input tokens12,456,795
Output tokens146,000
Ratio85 : 1
Cost$13.19

Almost none of that is the model writing the paper. It is the conversation history being re-sent on every request. A single writing phase averaged 1.7 million input tokens per agent call.

The same shape on a mid-tier model costs roughly $37, and on a frontier model considerably more. If a pipeline feels surprisingly expensive, this is why, and the fix is not a cheaper model.

The negative result: compacting harder costs more

The obvious optimisation is to compact conversation history aggressively so each request carries less. It was measured on the same task, against a baseline of 12.5M input tokens and $13.19:

History budgetInput tokensCostOutcome
90k (generous)11.4M$11.99completed
24k (tight)27.6M$29.75ran out of credit and died

Compacting harder was two and a half times more expensive. Sessions in the tight configuration reached 463 and 408 agent actions with 37 and 92 compactions. Starved of its working context, the agent re-read files it had already read, re-ran commands, and re-planned work it had already done. Per-request size fell. Turn count exploded. Total spend more than doubled.

An offline replay of the event stream had predicted the tight budget would cost 39 percent of the generous one. The prediction was worthless because it assumed the event stream stays the same when the budget changes. It does not. The budget changes what the agent does, and that feedback dominates everything else.

Treat a context budget as a safety ceiling against a pathological history, never as a cost lever.

What actually helps

Fewer turns, not smaller turns. Cost scales with how many times the agent goes around the loop. Give it what it needs up front rather than making it discover the workspace one tool call at a time.

Put the key files in the task. If the agent will obviously need results/exp1.json and the venue template, say so and let it read them once, deliberately.

Bound exploration. "Read the three files under results/ and write the Experiments section" is cheaper and better than "figure out what experiments were run".

Split long phases. A phase that will take 200 turns is better as three phases with checkpoints on disk between them. State on disk is free. Conversation history is not.

Watch the ratio, not the total. An input-to-output ratio above roughly 50:1 means you are paying to re-read rather than to think.

Before starting a long run

  • Estimated cost stated to the user up front
  • A ceiling set, and behaviour defined for reaching it
  • Long phases split, with results written to disk between them
  • Spend visible while running, not only at the end

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.