AI agentsAny business
AI agents that watch their own cost
Three AI agents that broke in expensive ways, and the fixes that made them cheap and safe
12,000×cheaper per question: $12 down to $0.001
See the code on GitHub (opens in a new tab)
Proof you can check:Code on GitHub
AI agents

The same agents, 12,000× cheaper
- Cost per question
$12$0.00112,000× cheaper - AI tokens in one call
571K13399.98% less - Tools loaded each turn
256–11up to 76% fewer
Lubo Bali · lubobali.com
The problem
AI agents fail quietly and expensively: one dumps a whole database into the AI, one never stops researching, one gets 25 tools and picks the wrong one. The bill is the first sign.
What I built
Three agents with the real fixes: field stripping and size guards on what the AI sees, a budget manager that tracks every step's cost and stops in time, and a keyword router that loads only the tools a question needs.
Tech & why
LangChain with OpenAI, every call traced in Langfuse, so cost, tokens and speed are measured instead of guessed. The router uses no AI at all, so it costs nothing.
- Python
- LangChain
- OpenAI
- Langfuse
- MCP
The result
A question went from $12 and 8 minutes to $0.001 and 15 seconds, one call from 571K tokens to 133, and each turn now loads 6–11 tools instead of 25. 46 tests hit the real AI.
How this agent is built
Every AI agent has the same five parts. Here is what each one is in AI agents that watch their own cost, so you can judge any agent the same way.
- ModelOpenAI models through LangChain.
- HarnessThree LangChain agents; a budget manager tracks every step's tokens and cost and stops the run in time.
- GuardrailsOutput size guards, field stripping (no card numbers ever reach the AI), hard step and budget limits.
- KnowledgeA support database and research sources, cut down to the fields a question needs.
- ToolsMCP tool servers (GitHub, Slack, a database), loaded per question by a keyword router with no AI cost.
Safe by design
No card numbers ever reach the AI (fields stripped first), and every run has a hard budget and step limit.
Similar projects
- AI agentsThis site and its AI BlueprintDescribe a business problem and get a first AI plan in about 30 seconds, on this site30 s from your problem to a first plan, measured live
- AI agentsmergeAIUpload spreadsheets, ask a question in plain English, get a checked answer~8 s from question to a checked answer
- AI agentsSkyCast-AIA weather agent where every number in the answer comes from a tool, not the AI's memory5 tools the agent can call, each number from one of them
Have a problem like this? Get your free AI blueprint in about a minute.
