How to Stop AI Agent Background Token Consumption — Stop the Leak

Square

I got my first AI agent bill in January. $847. For a personal assistant that checked my email and told me the weather. I nearly choked on my coffee.

Here’s the thing nobody tells you when you set up an autonomous agent: 80% of your tokens are going straight into the garbage. Not hyperbole. Actual numbers from my own setup. And yours is probably worse.

The Silent Leak You Never See

AI agents don’t just run when you talk to them. They wake up. Constantly. Every 15 minutes, every 30 minutes — heartbeat polls checking if anything needs attention. Each time the agent boots up, loads its entire context, reads your memory files, re-checks the calendar, re-scans the inbox. And 90% of the time? Nothing’s changed. Nothing at all.

But you’re paying for it anyway.

Ryan Persitza over at BattleTested published his breakdown in 2026. His production agent was burning 40% of total spend on heartbeat polls that returned “HEARTBEAT_OK.” Another 25% on re-reading the same context over and over. Fifteen percent on routine checks — simple API calls wrapped in an expensive reasoning engine. Only 20% went to actual work: analysis, decisions, output that matters.

Read that again. Four out of every five dollars. Gone. On nothing.

And honestly? Most people don’t even know it’s happening. The token meters tick quietly. The API dashboard shows numbers going up. But nobody connects the dots between “my agent is always available” and “why am I spending $800 a month on a glorified calendar checker.”

Where Your Tokens Actually Go

Let’s get specific. There are five leaks. All of them fixable.

1. Heartbeat Polls — Your agent wakes on a schedule. Reads its entire system prompt. All the memory files. All the tool definitions. Every single time. Then decides “nope, nothing to do” and goes back to sleep. At 48 heartbeats per day, that’s 1,440 wake-ups a month. Each one burning a few thousand tokens. Do the math. It’s brutal.

2. Context Re-Reads — Every turn, your agent re-tokenizes the entire conversation history. Files it already read 10 minutes ago get re-read. Tool configs get re-loaded. The system prompt — probably thousands of tokens long — gets processed fresh every single interaction. Same bytes, same cost, every time.

3. Unused Tool Results — The agent calls a tool, gets pages of JSON back, and uses maybe the first two lines. The rest? Dead weight. Sitting in the context window, silently inflating every future turn. I once had an agent pull 40KB of weather API data to extract “it’s 72 degrees.”

4. Repeated System Prompts — Long, bloated system prompts with every possible instruction baked in. “You are a helpful assistant. You can do X. You can do Y. You can do Z. Here’s how to do A. Here’s how to do B…” Five thousand tokens before the agent even starts working. And it reads all of it, every single call.

5. Polling Loops — Agent checks something. Waits. Checks again. Waits. Checks again. Each check is a full context load. If your framework isn’t caching between turns, you’re paying for identical context over and over and over.

Fix #1: Kill the Heartbeat Tax

This one change saved me more than everything else combined. No exaggeration.

Instead of waking the full AI agent for every heartbeat, run a pre-filter. A simple bash script. Under 30 lines. It reads the heartbeat config, checks each data source directly — Gmail API, calendar, whatever — and only wakes the agent if there’s actually something new. No LLM involved. No tokens. No cost.

Result: 85% of heartbeat polls eliminated before they ever touch a model. At my rate, that was over 40 premium model calls per day down to maybe 6. The script takes 30 seconds to write and runs forever for free.

So the pattern is simple: pre-filter with traditional code, route to AI only when necessary. Don’t hire a PhD to check if the mail arrived.

Fix #2: Model Routing That Makes Sense

Not every task needs Claude Opus or GPT-4. A local model running on your own machine can handle classification, simple filtering, and drafting. Zero API cost.

Here’s what I run now:

  • Tier 1 — Local (free): Llama 3.2 3B via Ollama. Handles heartbeat pre-filtering, email classification, memory compaction drafts. 40-50% of all agent invocations never leave the machine.
  • Tier 2 — Cheap cloud (~$0.15/M tokens): Claude Haiku or GPT-4o Mini. Structured data extraction, template-based reports, medium-complexity Q&A. Another 25-30% of calls at 1/10th the cost.
  • Tier 3 — Premium ($15-75/M tokens): Reserved exclusively for complex multi-tool orchestration, nuanced conversation, financial decisions, and code generation. Maybe 20-25% of total calls.

The routing decision itself costs nothing. It’s an if-statement, not another LLM call. Use rules, not AI, to decide which AI to use.

Fix #3: Stop Re-Reading Everything

Context bloat is the silent killer. Most agents load every memory file, every tool definition, every scrap of conversation history on every single turn. By day three of a running agent, you’re re-reading 80,000 tokens of raw logs every time it blinks.

The fix is layering. Short-term memory in daily Markdown files that auto-rotate after 3 days. Medium-term for active projects and key decisions. Long-term for distilled core memories, updated weekly. Structured data in SQLite — queryable, not loaded into context. Semantic search via vector DB for recall by meaning, not brute-force re-reading.

And the critical rule: only inject today’s notes and the core MEMORY.md into the system prompt. Everything else stays on disk, queried only when needed.

My per-turn context went from ~80K tokens to ~15K. That’s 5x fewer input tokens on every single interaction. Multiply that across thousands of turns a month and it’s real money.

Fix #4: Compact, Don’t Truncate

Most frameworks handle long conversations by just chopping off old messages. Worst possible approach. You lose information unpredictably — sometimes the most important detail was in the first exchange.

Compaction is different. You summarize the oldest conversation segment into a dense, information-preserving blob. A cheap local model drafts the summary. The raw messages get archived to daily notes. Critical decisions get promoted to structured memory. The summary replaces the raw messages in context.

The result: an agent that’s been running for 8 hours has the same per-turn cost as one that just started, but remembers everything that happened. No information loss, no context bloat.

Fix #5: Batch Your Tool Calls

Every tool call is a round trip: model thinks, generates call, you execute, return result, model processes. Each round trip adds tokens. Reading three files? If your framework does it sequentially, that’s three round trips. Batch them into one call — all three reads in a single turn — and you cut the overhead by two-thirds.

Most agent frameworks default to sequential. Change it. Parallel tool calls reduce total turns by 30-50% in any data-gathering workflow. It sounds trivial until you see your monthly bill.

Fix #6: Cache What Repeats

Semantic caching. Prompt normalization. Saved intermediate results. If your agent asks the same question twice, don’t pay for the answer twice. Start with your most expensive repeated calls — usually the ones that process the same documents or query the same APIs over and over. Cache only where you understand the freshness requirements. But cache something.

The thing is, most people never even look. They assume the platform handles it. It doesn’t. You’re paying for every duplicate, every redundant context load, every unnecessary heartbeat. The platform makes money when you burn tokens.

What This Looks Like In Practice

After implementing all six fixes, my monthly AI bill dropped from $847 to roughly $110. Same functionality. Same reliability. The agent still monitors email, still checks the calendar, still does everything I built it to do. It just stopped burning thousands of tokens asking itself whether anything had changed.

And look — I’m not some optimization wizard. I’m just a guy who got angry at a bill. The principles are dead simple: route simple work to cheap models, pre-filter before invoking AI, layer your memory so you’re not re-reading everything, compact instead of truncating, batch your tool calls, cache the repeats. None of this requires a PhD. A weekend of refactoring. Two, tops.

The hardest part isn’t the code. It’s looking at the dashboard and admitting 80% of your spend is waste. That stings.

But once you see it, you can’t unsee it. Every heartbeat poll becomes a little drip. Every re-read of system prompts becomes a slow leak. And all those drips and leaks? They add up to hundreds of dollars a month. Month after month after month.

So stop the leak. You’ve already got the tools.

Leave a Reply

Your email address will not be published. Required fields are marked *