{"slug": "why-browser-agents-waste-tokens-and-how-to-stop-it", "title": "Why browser agents waste tokens, and how to stop it", "summary": "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.", "body_md": "⭐ **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.\n\n*Working with [@susheem-k](https://dev.to/susheem-k) on TokenOps.*\n\nA 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.\n\nOpenAI, 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.\n\nAt 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.\n\nWe asked an agent:\n\nShow the blood relationship fraction between you and your father's mother's sister's son.\n\n|  | Steps | Tokens sent | Answer | \n|---|---|---|---|\n| Best run | 1 | 8,291 | 1/16 | \n| Worst run | 24 | 314,924 | 1/16 | \n\nBoth 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.\n\nMost of the waste we saw came from four problems.\n\nThe agent clicked a button and the page did not change. It clicked again. 25 of its 38 steps were the same click.\n\n**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.\n\nThe 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.\n\n**Fix:** the actions changed, but the page did not. TokenOps notices the same page coming back and sends the same note.\n\nA 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.\n\n**Fix:** when a request gets too big, TokenOps shrinks it before sending. It removes repeated content and keeps the task and the latest steps.\n\nThe model cannot tell step 30 from step 3.\n\n**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.\n\nTokenOps sits between your agent and the AI model, so it sees every step. Your agent's code does not change.\n\n```\npip install agent-tokenops\n```\n\nWrap the function your agent uses to call the model. In Browser Use, that is the model you pass in as `llm`.\n\n``` python\nfrom tokenops import tokenops_run\nfrom tokenops.capabilities import wrap_complete\nfrom tokenops.framework import Halt\nfrom tokenops.providers import complete\n\nGOVERNANCE = {\"governance\": {\n    \"budgets\": [{\"id\": \"run_cap\", \"limit_micros\": 2_000_000, \"dimension\": \"trace\"}],  # $2 per run\n    \"policies\": {\n        \"progress_guard\":     {\"input_repeats\": 3},            # problems 1 and 2\n        \"context_compaction\": {\"ctx_max\": 100_000},            # problem 3\n        \"budget_pace\":        {\"soft_limit_micros\": 1_000_000},  # problem 4\n        \"cost_budget\":        {\"budget\": \"run_cap\"},           # problem 4: hard limit\n    },\n}}\n\nwith tokenops_run(config=GOVERNANCE, service=\"browser-agent\",\n                  provider=\"openai\", model=\"gpt-4o\") as bound:\n    governed = wrap_complete(bound.governor, bound.controls, bound.attr,\n                             provider=\"openai\", model=\"gpt-4o\",\n                             dispatch=complete, service=\"browser-agent\")\n    try:\n        agent.run(task, complete_fn=governed)   # give the agent `governed`\n    except Halt as stopped:\n        print(f\"run stopped: {stopped}\")\n```\n\nIf you use Claude Code, run `/integrate-tokenops` in a copy of the repo to set this up.\n\nAn 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.\n\nIn 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:\n\nThe branch is not merged yet. We want feedback on it.\n\nWhere does your agent get stuck? Tell us in the comments or in [this GitHub Discussion](https://github.com/theagentplane/tokenops/discussions/207).", "url": "https://wpnews.pro/news/why-browser-agents-waste-tokens-and-how-to-stop-it", "canonical_source": "https://dev.to/tisha/why-browser-agents-waste-tokens-and-how-to-stop-it-2fjm", "published_at": "2026-11-18 16:06:24+00:00", "updated_at": "2026-11-18 16:12:42.248534+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "ai-products"], "entities": ["TokenOps", "Browser Use", "OpenAI", "Google", "Anthropic", "Perplexity", "GitHub", "Claude Code"], "also_reported_by": [], "takeaway": "Wrapping the model-call function with progress guards (halt after 3 repeated inputs), context compaction at 100k tokens and a per-run budget cap stopped browser-agent runs from burning 38x more tokens than needed on the same task.", "recommendation": {"advice": "Wrap your agent's model-call function with a progress guard that halts after 3 repeated inputs and a per-run budget cap, since repeated clicks and stale page history drove a 38x token gap in Browser Use runs.", "playbook": "llm-cost", "playbook_url": "https://wpnews.pro/playbooks/llm-cost"}, "alternates": {"html": "https://wpnews.pro/news/why-browser-agents-waste-tokens-and-how-to-stop-it", "markdown": "https://wpnews.pro/news/why-browser-agents-waste-tokens-and-how-to-stop-it.md", "text": "https://wpnews.pro/news/why-browser-agents-waste-tokens-and-how-to-stop-it.txt", "jsonld": "https://wpnews.pro/news/why-browser-agents-waste-tokens-and-how-to-stop-it.jsonld"}}