{"slug": "im-building-a-local-first-typescript-guard-for-runaway-ai-agent-costs", "title": "I’m building a local-first TypeScript guard for runaway AI-agent costs", "summary": "Developer Salim Assili is building AI CostGuard, a local-first TypeScript/Node.js runtime safety layer that blocks costly AI agent calls before they reach provider APIs. The tool addresses failure modes like retry storms, prompt loops, and budget overruns by checking whether an agent should be allowed to make another provider call. It includes guard() and guardFunction() APIs, CLI budget checks, and integrations with OpenAI, Anthropic, and other frameworks.", "body_md": "I’m building AI CostGuard, a local-first TypeScript / Node.js runtime safety layer for AI agents.\n\nThe problem I’m working on is not model quality or prompt engineering.\n\nIt is the boring failure mode where an agent keeps making provider calls because of bad control flow:\n\nretry storms\n\nsimilar prompt loops\n\nmax-step explosions\n\nunknown model pricing\n\naccidental budget overruns\n\nrepeated calls with no useful progress\n\nThe goal is to block risky calls before the provider API execution happens.\n\nThe current API is centered around guard() and guardFunction().\n\nThe package currently includes:\n\nlocal-first runtime checks\n\nCLI budget checks\n\nlocal-only dashboard\n\nopt-in JSONL event logs\n\nstructured errors\n\nmocked runnable examples for OpenAI, Anthropic, Vercel AI SDK, LangChain-style usage, Mastra-style runners, CrewAI budget gating, and CI checks\n\nWhy this matters:\n\nA lot of tooling shows what happened after the agent already spent money.\n\nI’m interested in the smaller pre-call question:\n\n“Should this agent be allowed to make another provider call right now?”\n\nLimitations:\n\ntoken estimation is approximate\n\nprovider pricing can change\n\nfalse positives are possible\n\nfalse negatives are possible\n\nlocal-first state has limits\n\nthis is not a SaaS\n\nthis is not a billing ledger\n\nthis is not a hard security boundary\n\nthis does not replace provider billing alerts or production observability\n\nnpm:\n\n[https://www.npmjs.com/package/@salimassili/ai-costguard](https://www.npmjs.com/package/@salimassili/ai-costguard)\n\nGitHub:\n\n[https://github.com/salimassili62-afk/ai-costguard](https://github.com/salimassili62-afk/ai-costguard)\n\nI’d appreciate technical feedback on:\n\nwhether guard() / guardFunction() feel natural\n\nhow false positives should be handled\n\nwhether local-first state is actually useful in real agent systems\n\nwhat pricing assumptions are dangerous\n\nwhat failure modes I’m missing\n\nwhether this should stay small or become more configurable", "url": "https://wpnews.pro/news/im-building-a-local-first-typescript-guard-for-runaway-ai-agent-costs", "canonical_source": "https://dev.to/assili_salim_e3c07f9954de/im-building-a-local-first-typescript-guard-for-runaway-ai-agent-costs-3i53", "published_at": "2026-06-16 10:07:36+00:00", "updated_at": "2026-06-16 10:17:03.714425+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "ai-infrastructure"], "entities": ["Salim Assili", "AI CostGuard", "OpenAI", "Anthropic", "Vercel AI SDK", "LangChain", "CrewAI", "Mastra"], "alternates": {"html": "https://wpnews.pro/news/im-building-a-local-first-typescript-guard-for-runaway-ai-agent-costs", "markdown": "https://wpnews.pro/news/im-building-a-local-first-typescript-guard-for-runaway-ai-agent-costs.md", "text": "https://wpnews.pro/news/im-building-a-local-first-typescript-guard-for-runaway-ai-agent-costs.txt", "jsonld": "https://wpnews.pro/news/im-building-a-local-first-typescript-guard-for-runaway-ai-agent-costs.jsonld"}}