Skip to content
techpotions
ai agent swarm · token budget · agent-orchestration · multi-agent systemsNovember 24, 20267 min read

Building an AI Agent Swarm Without Burning Your Token Budget

Your first agent swarm can easily 8x your token costs from coordination overhead. Learn when fan-out actually saves money and how to build a lean swarm with planner-worker splits, dedupe, hard token caps, and real observability.

Cover illustration for “Building an AI Agent Swarm Without Burning Your Token Budget”

Why most ai agent swarms burn twice the budget you planned

An ai agent swarm looks elegant on a diagram — a flock of agents passing notes — until you see the token meter spin up. The promise is parallel intelligence, but the reality is often duplicative chatter and context bloat. TokenKarma’s cost analysis warns that coordination overhead multiplies token costs through context carry-over, duplicate work, and error recovery. You can hit 8× the usage you expected before the swarm produces a single reliable answer.

The fix isn’t “use fewer agents.” It’s a design discipline that tells you exactly when fan‑out pays for itself and when it’s just expensive gossip.

When fan-out actually pays — and when it’s cheap gossip

Fan‑out returns your investment only when subtasks are independent and verifiable. Each worker retrieves or checks a discrete signal; the output is a structured fact you can validate without another agent’s opinion. Merge is a simple union, deduplication, or filter.

Consider a lead‑generation swarm that scans hiring posts, forums, reviews, and map listings. One worker checks “Are they hiring?” Another checks “Did they complain about a competitor?” Both return true/false plus a snippet. Nobody debates. The aggregated result is a scored lead with a plain‑English reason — no consensus required.

Fan‑out becomes gossip the moment agents have to agree on a single answer. If you ask four agents to debate a code fix, you’ll pay for overlapping reasoning, duplicate analysis, and half the conversation could have been handled by one well‑prompted LLM.

Rule: if the output of two workers could contradict each other and someone needs to judge, don’t fan out. If each worker can succeed or fail independently and you just need to collect the successes, fan out aggressively.

Planner-worker split: the one pattern that saves tokens

A lean ai agent swarm has exactly one big‑brain call and many embarrassingly cheap worker calls. The planner decides the strategy and the questions; the workers execute narrow tasks with minimal context.

We built our own lead‑gen product, techpotions leads, exactly like this. The planner reads the target business profile and selects which data sources to hit: hiring posts, forums, reviews, map listings. It spawns a worker per source with a simple instruction:

Text
Check this URL: {url}
Look for evidence that this business is hiring, complaining about a problem, or expanding.
Return JSON: { signal_found: bool, snippet: string, confidence: 0-1 }
Token limit: 500

The worker doesn’t know why we want the signal. It doesn’t have the full search history or the business’s revenue model. It just returns a verdict. That’s the secret: stop giving workers context they don’t need.

What context each worker really needs (hint: less than you think)

Every token you send to a worker that isn’t strictly required to produce its output is a tax. In an ai agent swarm, that tax multiplies by the number of workers.

Send only:

  • The specific input (URL, query, structured data)
  • The output schema (JSON or enum)
  • A hard token cap and that’s it

No chat history, no “here’s what the other agent found,” no strategic musings. If a worker can’t complete its task with a 0‑shot prompt, the task is probably too broad. Split it further.

Mastra’s overview of agent swarms explains that the value comes from specialization. But specialisation only saves money when you starve each agent of everything except its single responsibility.

Dedupe and merge: stop paying twice for the same insight

Five workers might find the same hiring post. Without dedup, you’ll insert duplicate leads, confuse your pipeline, and waste tokens on follow‑up processing.

Don’t use an agent for this. A cheap deterministic step — fuzzy matching on business name, domain, or social handle — is all you need. Here’s the merge logic we use in techpotions leads:

JavaScript
// Merge results with dedup
function mergeSignals(results) {
  const seen = new Set();
  return results
    .filter(r => r.signal_found)
    .reduce((merged, r) => {
      const key = normalize(r.business_name);
      if (!seen.has(key)) {
        seen.add(key);
        merged.push({ ...r, source: r.url });
      }
      return merged;
    }, []);
}

That’s 0 tokens, full dedup. The moment you let an LLM decide if two slightly different strings are the same business, you’re burning budget on a solved problem.

Hard step caps and token budgets: the kill switch every swarm needs

Every autonomous system needs a circuit breaker. In an ai agent swarm, that breaker is a per‑agent token cap and a run‑level budget that kills the swarm on the spot when exceeded.

Per worker:

  • max_tokens (both for the call and any tool use)
  • a hard step limit (if the agent loops, cut it)

Per run:

  • planner estimates total tokens as workerCount * maxTokensPerWorker + planner cost
  • if at any point actual usage exceeds budget, the orchestrator aborts and returns partial results plus a billing report

The Swarms API dynamic pricing now charges per model, but that doesn’t protect you from an agent that decides to browse the entire internet. Your orchestrator must enforce the limits internally. We learned this the hard way building techpotions leads — an early version hit $3 in one run because a worker tried to read a 5,000‑page job board. The next deployment added a per‑worker 1,500‑token cap and a run‑budget alarm at $0.50.

Observability before autonomy: don’t let the swarm run blind

Before you trust an ai agent swarm to run on a schedule, you need to see exactly how it spends every token:

  • Which worker consumed how many tokens?
  • Which source gave a signal, and which workers returned nothing?
  • What was the cost per lead?
  • Where did we hit a cap or fail?

We instrumented techpotions leads with a Next.js dashboard that streams real‑time metrics: worker started, token count, result, and cost. It’s exposed via an MCP endpoint so other systems can consume the same data. That visibility is what lets you tune the planner, adjust per‑source budgets, and spot sources that never yield signals — so you stop paying for them.

If you’re building your own swarm, our AI agent development services start with this observability layer because a swarm without metrics is just a token bonfire. For teams that prefer to hand off the build, our AI agent development company ships production‑grade swarms with the kill switches and monitoring already baked in.

Building techpotions leads: a swarm that sells without overspending

We built techpotions leads because we were tired of pay‑per‑contact lists that were stale before we could open them. The product doesn’t scrape contacts; it looks for the buying signal that makes someone reachable today.

Every daily run follows the pattern above:

  • Planner selects the target market and picks data sources.
  • Workers fan out to job boards, review sites, and social channels, each with a 500‑token cap and a single binary question.
  • Merge & dedupe collects the true signals, strips duplicates, and attaches a date‑stamped reason.
  • Output lands in a pipeline ready for email and WhatsApp outreach.

Cost per run: under $0.50. Value per lead: a warm signal, not a cold number. The techpotions leads case study has the full breakdown.

The discipline is what matters: independent verifiable tasks, starving workers of context, hard token caps, and real‑time observability. Apply those to your own ai agent swarm and you’ll stop burning budget and start shipping reliable output.

FAQ

What is an ai agent swarm?

An ai agent swarm is a multi-agent system where a planner agent coordinates specialized worker agents that independently perform subtasks and return structured results, which are then merged — all without constant inter-agent chatter.

When should I avoid fan-out in agent swarms?

Avoid fan‑out when agents must reach consensus on one answer; the debate multiplies token usage. Use it only for independent, verifiable subtasks that can be merged without conflict.

How do I set a token budget for an agent swarm?

Assign each agent a strict per‑step token cap and a run‑level budget. The planner estimates total tokens upfront and aborts the run if the cap is exceeded early, so you never pay for a runaway swarm.

Written by
techpotions
All entries
Next.js App Router: Four Cache Layers That Lie
The weekly

One email a week, from the workshop.

What we published, what we shipped, and the free packs as they land. No drip sequence, no webinar, unsubscribe in one click.