Hi There! Did you enjoy any of my projects? I am always open for mentorship and/or contract work. You can reach me here.
Home

Saving Money with AI Agents

20 distilled tips for leaner agent & fleet development
Published 2 November 2026

Building with AI agents moves fast, but the bills move faster. Whether you are running a single autonomous assistant or orchestrating a multi-agent graph, cost discipline separates prototypes that survive from ones that get shut down. These twenty tips draw on hard-won lessons from the field — from intelligent routing inspired by Spotify's Shunt approach, to the unglamorous work of trimming token waste from tool schemas.


1.Route by task complexity

Not every task needs GPT-4 or Claude Opus. Build a routing layer that dispatches simple queries to cheaper models (Haiku, Gemini Flash) and reserves expensive models for reasoning-heavy work. Spotify's Shunt philosophy — intelligent traffic shunting — applies directly here.

2.Cache aggressively with semantic similarity

Exact-match caching only saves you when prompts are identical. Semantic caching finds near-duplicate queries and returns stored answers, cutting a large share of redundant LLM calls.

3.Enable prompt caching on supported providers

Anthropic, OpenAI, and Google all offer prompt prefix caching. Pin your system prompt and static context as a cached prefix — re-reads cost a fraction of full input tokens.

4.Measure before you optimise

Track tokens, latency, and cost per agent step from day one. You cannot cut what you cannot see. Attach an observability layer before doing anything else.

5.Set hard budget limits per agent

Add a token or dollar ceiling to every agent run. When the budget is hit, surface a graceful fallback rather than silently burning credits on a runaway loop.

6.Run open-source models locally for non-critical tasks

Summarisation, classification, and formatting tasks often need no proprietary API. Run Llama, Mistral, or Qwen locally for free on commodity hardware.

→ Ollama
7.Batch non-urgent requests

Most cloud providers discount async batch endpoints by 50 % or more. Queue low-priority agent work (nightly reports, bulk enrichment) and flush it through the batch API.

8.Shrink context with RAG instead of stuffing

Retrieval-Augmented Generation lets you fetch only the relevant chunks at query time rather than cramming an entire knowledge base into every prompt. Fewer tokens, same quality.

9.Use structured outputs to eliminate parsing retries

Ill-defined prompts that return free-text often require a follow-up call to extract structured data. Force JSON or typed schemas on the first call and cut those retries entirely.

10.Implement circuit breakers

If an agent sub-task is looping or hitting errors repeatedly, a circuit breaker stops the bleeding. Without one, a single misconfigured tool can exhaust a daily budget in minutes.

11.Compress and summarise long agent memory

As an agent conversation grows, periodically summarise completed steps into a compact note rather than carrying the full transcript. Shorter context = lower cost per turn.

12.Fine-tune a small model for repetitive tasks

If your agent repeatedly calls a large model to do the same narrow task (intent classification, slot filling), a fine-tuned 7 B model can match the quality at a fraction of the price.

13.Profile tool definitions for token waste

Tool schemas are injected into every call. Verbose descriptions with unnecessary examples can add hundreds of tokens per turn. Audit and trim tool definitions regularly.

14.Use multi-provider fallback routing

Different providers price identically-capable models very differently. A load balancer that routes to whichever provider is cheapest at the moment can cut costs without touching your code.

15.Throttle agent concurrency

Unbounded parallel agent runs spike costs unpredictably. Cap concurrency with a semaphore or queue, and shape traffic so you stay within provider rate-limit tiers.

→ Celery
16.Evaluate quality at lower temperature first

High temperature = more tokens wasted on exploration. Start deterministic runs (temp 0) and only raise temperature when you actually need creative variance.

17.Checkpoint long-running agents

For agents that run multi-step workflows, serialise state between steps. On failure you resume from a checkpoint rather than replaying the entire (expensive) run from scratch.

18.Monitor usage with real-time metering

Stream cost events into a metering system so you can alert on anomalies before end-of-month surprises. Treat token spend like any other infrastructure metric.

19.Reuse embeddings, never recompute them

Embedding the same documents on every run is pure waste. Store vectors in a persistent index and only re-embed when the source changes.

→ Chroma
20.Review logs for dead agent branches

Regular log reviews surface agent paths that always fail or never contribute to the final answer — dead weight that costs tokens on every run. Kill them.


Perhaps it would be more estetic to have it like this: Made with ❤️ by dirkjbosman © (sitemap)

The common thread across all twenty is the same: measure first, then cut. Blind optimisation wastes engineering time. A solid observability layer, a routing proxy, and a caching strategy will cover 80 % of most cost problems — the remaining 20 % is usually a misbehaving loop or an oversized context that a quick audit will surface.

Stay in the loop

New articles, tools and experiments — no noise.