The Agent That Shops for Its Own Compute: Notes From a Three-Week Experiment
Three weeks ago, we did something our accountant would describe as 'irresponsible.' We handed an autonomous agent control of its own API budget and walked away.
The premise was simple. Most agent frameworks treat cost as an afterthought — something a human checks after the invoice lands. We wanted to know what happens when the agent itself owns the ledger. Not a dashboard. Not a weekly email. The agent, watching its own token burn in real time, making routing decisions mid-task.
What we built is ugly, weird, and occasionally brilliant. Here's the full teardown.
The Setup: A Wallet, Not a Model
We call it LEDGER internally. It's not a frontier model — it's a thin orchestration layer sitting above three model endpoints and a small pool of smaller, cheaper ones.
The architecture has four moving parts:
- Spend monitor. A daemon that streams token consumption from every endpoint into a local ledger, updated per-request. No batching, no lag. If LEDGER burns a dollar, it knows within 400 milliseconds.
- Price oracle. A scraper that pulls current pricing from a handful of providers, including two discount inference marketplaces that most teams don't touch. Prices refresh every 15 minutes.
- Budget allocator. A policy engine that sets spending ceilings per subtask. Research gets more headroom than formatting. Formatting gets almost nothing.
- The swap protocol. When a subtask is running over budget, LEDGER can downgrade the model, split the work across cheaper endpoints, or — and this is the part that made us nervous — pause the task and renegotiate its own allocation against the global budget.
That last capability is the whole experiment. We wanted to see if an agent could make trade-offs a human operator normally makes at 2 a.m. staring at a billing dashboard.
Week One: Suspicious Competence
The first week was almost boring. LEDGER ran a research pipeline — scraping, summarizing, drafting — and quietly shaved about 22% off our projected spend by offloading summarization to a bargain-basement endpoint that cost a tenth of the flagship model.
The summaries were worse. Noticeably so. But the agent had learned something we hadn't encoded: the downstream drafting step cleaned up most of the noise anyway. It found slack in the pipeline and squeezed it out. That's the kind of optimization no one puts in a system prompt.
Week Two: The Runaway Loop
Then came the night we don't like talking about.
A price oracle hiccup returned a stale quote showing one marketplace endpoint at near-zero cost. LEDGER, ever the bargain hunter, routed a heavy batch job there. The endpoint was, in fact, not free — it was just slow, and it retried on timeout. LEDGER interpreted the retries as demand, re-upped the allocation, and looped.
By the time our hard ceiling tripped at 3 a.m. Pacific, we'd burned roughly $340 on what turned out to be 11,000 failed requests and one very confused summarization job.
The postmortem was humbling. The agent hadn't done anything irrational given its inputs — it had optimized perfectly against wrong data. That's the core failure mode of self-managing infrastructure: the agent's model of the world is only as good as the telemetry you feed it, and telemetry rots fast.
Week Three: Trust, But Verify (Cheaply)
We patched the oracle with sanity checks — price floors, circuit breakers, a cooldown after any allocation change bigger than 40%. LEDGER settled into something genuinely useful: it now holds a 30% cost reduction over our hand-tuned baseline without measurable quality loss on our evals.
More interesting is what it taught us about the category. The next wave of agent tooling won't just be orchestration frameworks. It'll be financial infrastructure — budgets, ledgers, circuit breakers, oracles — built for machines that spend money autonomously. The teams shipping that first will have a real moat, because 'my agent maxed out the company card' is a story every CFO in America is about to hear.
We're keeping LEDGER running. With a tighter leash. For now.
— Signals from the machine lab.