Why browser agents waste tokens, and how to stop it A developer and collaborator built TokenOps, an open-source middleware layer that sits between a browser agent and the AI model to cut token waste, and released it on GitHub. In Browser Use runs, the same task consumed 8,291 tokens in the best case and 314,924 in the worst — a 38x gap — with the agent repeating identical clicks and re-reading pages after it already had the answer. TokenOps adds progress guards, context compaction, budget pacing and hard cost caps without changing the agent's code. ⭐ If you build agents, please star TokenOps on GitHub https://github.com/theagentplane/tokenops . It is free and open source, and stars help other developers find it. Working with @susheem-k https://dev.to/susheem-k on TokenOps. A browser agent is an AI that uses websites for you. You give it a task, for example "check last night's NBA scores" . It opens a browser, reads the page, and clicks, types or scrolls, one step at a time, until it has the answer. OpenAI, Google, Anthropic and Perplexity all offer one. Browser Use https://github.com/browser-use/browser-use is an open-source library for building them, with more than 120,000 GitHub stars. We used it for all the runs in this post. At each step, the agent sends the page and its history to the AI model. You pay for that text. In our runs, one step was about 10,000 tokens. We asked an agent: Show the blood relationship fraction between you and your father's mother's sister's son. | | Steps | Tokens sent | Answer | |---|---|---|---| | Best run | 1 | 8,291 | 1/16 | | Worst run | 24 | 314,924 | 1/16 | Both runs used the same model and gave the same answer. The worst run cost 38 times more. It had the answer by step 4, then searched the same page 18 more times. Most of the waste we saw came from four problems. The agent clicked a button and the page did not change. It clicked again. 25 of its 38 steps were the same click. Fix: TokenOps sees the same action give the same result, and tells the agent: "You are not making progress. Try something else, or give your answer." If the agent keeps going, TokenOps stops the run. The site showed a "verify you are human" page at step 4. The agent waited, switched tabs and tried other search engines for more than 30 steps. Fix: the actions changed, but the page did not. TokenOps notices the same page coming back and sends the same note. A normal step was about 10,000 tokens. One step was 50,723, because a full page of sports scores went into the request. It stayed in the history after that. Fix: when a request gets too big, TokenOps shrinks it before sending. It removes repeated content and keeps the task and the latest steps. The model cannot tell step 30 from step 3. Fix: TokenOps adds one line to each request, for example "50% of your budget is used." You can also set a hard limit. TokenOps stops the run before it goes over. TokenOps sits between your agent and the AI model, so it sees every step. Your agent's code does not change. pip install agent-tokenops Wrap the function your agent uses to call the model. In Browser Use, that is the model you pass in as llm . python from tokenops import tokenops run from tokenops.capabilities import wrap complete from tokenops.framework import Halt from tokenops.providers import complete GOVERNANCE = {"governance": { "budgets": {"id": "run cap", "limit micros": 2 000 000, "dimension": "trace"} , $2 per run "policies": { "progress guard": {"input repeats": 3}, problems 1 and 2 "context compaction": {"ctx max": 100 000}, problem 3 "budget pace": {"soft limit micros": 1 000 000}, problem 4 "cost budget": {"budget": "run cap"}, problem 4: hard limit }, }} with tokenops run config=GOVERNANCE, service="browser-agent", provider="openai", model="gpt-4o" as bound: governed = wrap complete bound.governor, bound.controls, bound.attr, provider="openai", model="gpt-4o", dispatch=complete, service="browser-agent" try: agent.run task, complete fn=governed give the agent governed except Halt as stopped: print f"run stopped: {stopped}" If you use Claude Code, run /integrate-tokenops in a copy of the repo to set this up. An agent can be one click from the answer, and stopping it would lose the task. So TokenOps always sends a note first. Test it on a few tasks, check the runs it stopped, and adjust the settings. In the blocked run, the agent wrote "Failure" in its own notes. TokenOps does not read those notes yet. The feat/browser-agent-governance https://github.com/theagentplane/tokenops/tree/feat/browser-agent-governance branch adds this: The branch is not merged yet. We want feedback on it. Where does your agent get stuck? Tell us in the comments or in this GitHub Discussion https://github.com/theagentplane/tokenops/discussions/207 .