cd /news/ai-agents/im-building-a-local-first-typescript… · home topics ai-agents article
[ARTICLE · art-29280] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=· neutral

I’m building a local-first TypeScript guard for runaway AI-agent costs

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.

read1 min views1 publishedJun 16, 2026

I’m building AI CostGuard, a local-first TypeScript / Node.js runtime safety layer for AI agents.

The problem I’m working on is not model quality or prompt engineering.

It is the boring failure mode where an agent keeps making provider calls because of bad control flow:

retry storms

similar prompt loops

max-step explosions

unknown model pricing

accidental budget overruns

repeated calls with no useful progress

The goal is to block risky calls before the provider API execution happens.

The current API is centered around guard() and guardFunction(). The package currently includes:

local-first runtime checks

CLI budget checks

local-only dashboard

opt-in JSONL event logs

structured errors

mocked runnable examples for OpenAI, Anthropic, Vercel AI SDK, LangChain-style usage, Mastra-style runners, CrewAI budget gating, and CI checks

Why this matters:

A lot of tooling shows what happened after the agent already spent money.

I’m interested in the smaller pre-call question:

“Should this agent be allowed to make another provider call right now?”

Limitations:

token estimation is approximate

provider pricing can change

false positives are possible

false negatives are possible

local-first state has limits

this is not a SaaS

this is not a billing ledger

this is not a hard security boundary

this does not replace provider billing alerts or production observability

npm:

https://www.npmjs.com/package/@salimassili/ai-costguard GitHub:

https://github.com/salimassili62-afk/ai-costguard I’d appreciate technical feedback on:

whether guard() / guardFunction() feel natural how false positives should be handled

whether local-first state is actually useful in real agent systems

what pricing assumptions are dangerous

what failure modes I’m missing

whether this should stay small or become more configurable

── more in #ai-agents 4 stories · sorted by recency
── more on @salim assili 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/im-building-a-local-…] indexed:0 read:1min 2026-06-16 ·