cd /news/ai-agents/how-we-cut-70-of-multi-agent-token-w… Β· home β€Ί topics β€Ί ai-agents β€Ί article
[ARTICLE Β· art-138299] src=dev.to β†— pub= topic=ai-agents verified=true sentiment=↑ positive

How We Cut 70% of Multi-Agent Token Waste by Replacing Supervisor LLMs with Typed State Machines

A developer redesigned a multi-agent AI runtime by replacing a central supervisor LLM with a deterministic typed state machine, cutting token consumption by more than 70% and eliminating non-deterministic supervisor drift. In the new design, worker agents return schema-validated receipts with explicit transition keys instead of free-form prose, and constraints are encoded as code-level transition guards rather than long supervisor prompts. Raw LLM transcripts are sealed to persistent storage while only the receipt is passed forward to the state machine.

by read3 min views1 publishedSep 23, 2026

If you have built a multi-agent AI system over the past two years, you have almost certainly encountered what we call the Supervisor Tax.

The pattern usually starts with clean intentions: you have 3–4 specialized subagents (a researcher, an executor, an evaluator, and a reporter) coordinated by a central "Supervisor" or "Router" LLM. The supervisor inspects intermediate outputs, decides who gets called next, evaluates task completion, and synthesizes the final response.

In local testing with 2 steps, it works great. But once you deploy it against real workloads with flaky APIs, 40-step workflows, and messy user requests, three problems immediately emerge:

Here is how we redesigned our agent runtime to cut 70%+ of token consumption and eliminate non-deterministic supervisor drift.

LLMs are extraordinary at fuzzy cognitive translation: understanding ambiguous user intent, parsing unstructured tool output, and authoring code or summaries.

They are remarkably inefficient and unreliable at finite state routing.

❌ Traditional Hierarchical Supervisor (Every Step Re-evaluates Context)
[User Request] 
      β”‚
      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    (Raw Prompt + History)
β”‚  Supervisor  β”‚ ──────────────────────────► [Worker Agent 1]
β”‚     LLM      β”‚ ◄────────────────────────── (Natural Language Output)
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    (Balloons Context Window)
      β”‚
      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Supervisor  β”‚ ──────────────────────────► [Worker Agent 2]
β”‚     LLM      β”‚ ◄────────────────────────── ...
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

────────────────────────────────────────────────────────────────────────────

βœ… Typed State Machine (Zero-Token Deterministic Handoff)
[User Request] ──► [Intent Classifier / Fast Model] ──► { State: RESEARCH }
                                                               β”‚
                                                               β–Ό
                                                     [Worker Agent 1]
                                                               β”‚
                                                               β–Ό (Emits Typed Receipt)
                                                     { status: "SUCCESS", ... }
                                                               β”‚
                                     (Deterministic Transition Rule)
                                                               β”‚
                                                               β–Ό
                                                     { State: CODE_EXEC }

When you replace the supervisor LLM with a deterministic typed state machine (e.g. using XState, a custom DAG, or a lightweight transition matrix), every agent step has an explicit contract:

Instead of letting worker agents dump markdown or free-form prose back to a coordinator, every leaf agent must return a schema-validated receipt.

// types/agent-receipt.ts
export interface AgentReceipt<TResult = unknown> {
  stepId: string;
  agentName: string;
  status: "COMPLETED" | "FAILED" | "NEEDS_HUMAN" | "RETRYABLE_ERROR";
  durationMs: number;
  tokensConsumed: {
    inputTokens: number;
    outputTokens: number;
  };
  // The actual verifiable payload
  result: TResult;
  // Deterministic transition key
  nextTrigger: string;
  // Cryptographic or verifiable hash of artifacts created
  artifactHashes: string[];
}

When the worker finishes, its raw LLM transcript is sealed into a persistent session log on disk or in object storage, and only the receipt is passed forward to the state machine.

Instead of writing long supervisor prompts like "Please make sure you only run the executor once and check that the tests pass before finishing", encode these constraints as code-level transition guards:

// workflow/agent-machine.ts
import { createMachine } from "xstate";

export const buildPipeline = createMachine({
  id: "agentPipeline",
  initial: "plan",
  states: {
    plan: {
      on: {
        PLAN_VALIDATED: "execute",
        PLAN_REJECTED: "plan_retry",
      },
    },
    execute: {
      on: {
        EXECUTION_SUCCESS: "verify",
        EXECUTION_TIMEOUT: "recover_state",
      },
    },
    verify: {
      on: {
        TESTS_PASSED: "finalize",
        TESTS_FAILED: "repair",
      },
    },
    repair: {
      // Hard ceiling: max 3 repair attempts before escalating to human
      always: [{ target: "escalate_human", guard: ({ context }) => context.repairCount >= 3 }],
      on: {
        REPAIR_READY: "execute",
      },
    },
    finalize: { type: "final" },
    escalate_human: { type: "final" },
  },
});

execute to verify costs exactly 0 LLM tokens and executes in sub-millisecond CPU time.context.repairCount >= 3 halts execution immediately. An LLM supervisor will often retry 15 times before running out of max tokens.repair agent only receives the test failure diff and the code file, not the entire 30,000-token historical transcript of planning and exploratory browsing. When we migrated our production agent workflows from LLM supervisor loops to deterministic typed state transitions, here is what our telemetry recorded across 500+ complex multi-step tasks:

Save the LLMs for what they do best: creative synthesis, complex reasoning, messy parsing, and domain coding.

For the control plane, coordination, routing, and ceilingsβ€”stick to the tools computer science gave us fifty years ago: deterministic state machines, typed schemas, and verifiable receipts.

What architecture does your team use to prevent agent routing drift? Drop your experience or questions in the comments below!

── more in #ai-agents 4 stories Β· sorted by recency
── more on @xstate 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/how-we-cut-70-of-mul…] indexed:0 read:3min 2026-09-23 Β· β€”