Case study

Lean Swarm: how cheap can a multi-agent system run?

A simulation engine that treats token cost as the primary constraint: tiered model routing, sparse activation, and a benchmark harness so the savings are measured rather than claimed.

status · Published on PyPIrepo ↗package ↗demo ↗stack · Python, SQLite, Vector search

Highlights

The cost problem

The default multi-agent pattern is wasteful by construction: every agent runs every step, on the best model available, whether or not it has anything to do. That is fine for a demo and ruinous for a simulation with dozens of agents over thousands of ticks. Lean Swarm starts from the opposite premise: token spend is the primary constraint, and the architecture should minimize it by design.

Two levers

The first lever is sparse activation. Each simulation tick, the engine determines which agents the tick actually needs and wakes only those; everyone else stays as stored state, costing nothing. The second is tiered model routing: routine steps go to cheap models, and only work that needs stronger reasoning gets escalated. Neither idea is exotic on its own; the engineering is in making them the default path rather than an optimization bolted on later.

State that is not all text

Agent state is hybrid: numeric fields for what math handles better than prose (resources, positions, counters) and text only where language genuinely carries the information. That keeps prompts short and lets much of a tick resolve without any model call at all. Longer-term memory is SQLite-backed and hierarchical, with vector search for retrieval, so an agent recalls what matters without hauling its full history into every context window.

Measured, not asserted

Cost claims in agent frameworks tend to be vibes. Lean Swarm ships a benchmark harness that runs the same scenario under lean activation and under the naive all-agents-every-tick baseline and reports the difference, so the central claim of the project is reproducible by anyone who installs it. Building the harness also enforced honesty during development: several ideas that felt efficient did not survive measurement.

Why it is on this page

Most of my work sits at the intersection of agent systems and pragmatic cost engineering: jobops routes scoring to whatever model the connected client already pays for, Hierocode keeps frontier tokens for judgment while a local model drafts code. Lean Swarm is that same instinct turned into the whole project.

← Back to projects