Orchestrator-Worker
Workers run in parallel, a synthesizer merges results. The workhorse for most research and review tasks.
Multi-agent orchestration · TypeScript
Coordinate LLM agents without giving up your budget.
A TypeScript library for multi-agent orchestration with a hard cost ceiling, deterministic record/replay in CI, and eleven composable patterns. You call it — it doesn't call you. Works standalone or with the rest of the nyxCore ecosystem.
Version
1.6.0
Orchestration patterns
11
Memory backends
10
Tests passing
638
Agent templates
17
TypeScript
5.5+
One sentence to decide on
No lifecycle hooks in your process. No required directory layout. No base class to extend. You import functions, pass typed inputs, and get typed outputs back. If you delete SwarmWire tomorrow, your app still compiles — it just loses the orchestration layer.
| Failure mode | What SwarmWire does instead |
|---|---|
| Token bleeding — agent loops burn money silently | Budget is a hard constraint. A run is structurally unable to exceed it. |
| Ceiling trap — easy tools can't scale, powerful tools are complex on day one | Progressive disclosure: swarm.run('prompt') works; the same object exposes the full DAG when you need it. |
| Framework lock-in — Mastra / LangGraph / CrewAI own your app structure | Plain functions and plain classes. No app skeleton required, no runtime to host. |
| Python-first ports with a TypeScript wrapper on top | TypeScript-native. Strict mode, noUncheckedIndexedAccess, full generic typing on deps and outputs. |
| No cost visibility — frameworks treat cost as an afterthought | Per-agent, per-provider, per-step cost breakdown on every execution. Dry-run before you spend. |
One input · N personas · one merged output
Fan-out is the workhorse pattern for multi-perspective review. One input goes to N persona-shaped agents at once; each returns a typed result; a post-merge output contract validates shape, severity vocabulary, and required fields before anything reaches the caller. ArchReview's six-persona Refactor Plan is a fan-out with a typed findings contract.
Workers run in parallel, a synthesizer merges results. The workhorse for most research and review tasks.
Named stages, each agent's output feeds the next. Typed handoffs, per-stage budget slice, clear failure boundaries.
One input, N agents, all at once. Optional per-leg, merged by contract. This is the pattern ArchReview uses for its six-persona Refactor Plan.
Split input, process chunks in parallel with a worker agent, fold with a reducer. Bounded parallelism, per-chunk cost tracking.
Argued positions with a judge, shared-state refinement, or domain-specialised swarms with a master orchestrator. Convergence thresholds in every variant.
Self-refining agents, LangGraph-style directed graphs with cycles, and event-subscribed workflows. Use when the shape is only known at runtime.
Used in production by ArchReview’s Refactor Plan — six persona providers, one merged findings object, budget enforced, contract validated before render.
Hard limits, not advisory
Every run owns a BudgetLedger. Before any step dispatches, the planner asks the ledger whether the estimated spend fits. If it does not, the run stops before the call — not after it. Dry-run projections tell you the worst-case cost before a single token is sent.
# A research + writer pipeline with a hard 50¢ ceiling import { Swarm, createProvider } from 'swarmwire' const swarm = new Swarm({ providers: [createProvider('anthropic', { apiKey: process.env.ANTHROPIC_API_KEY })], // ledger rejects a plan whose dry-run exceeds this budget: { maxCostCents: 100 }, }); const researcher = swarm.agent({ name: 'researcher', role: 'Research thoroughly', model }); const writer = swarm.agent({ name: 'writer', role: 'Write concise prose', model }); const result = await swarm.run('Research TypeScript ORMs and recommend one', { pattern: 'pipeline', stages: [ { name: 'research', agent: researcher }, { name: 'write', agent: writer }, ], // per-run override — cancels mid-flight if exceeded budget: { maxCostCents: 50, warningAt: 0.8 }, }); // always present, always typed console.log(result.cost.totalCostCents, // e.g. 42.7 result.cost.perAgent, // Map<name, { tokens, costCents, calls }> result.cost.budgetUsed); // 0–1 fraction of ceiling consumed
If budget exhausts mid-execution: running steps finish, no new steps start, a partial result returns with cost.budgetUsed = 1. The ledger does not lie about where it stopped.
Budget knobs
maxCostCentsHard cost ceiling — the primary knobmaxTokensToken ceiling across the whole runmaxLatencyMsWall-clock stop linemaxAgentsCap on concurrent agentswarningAt0–1 fraction — fires budget:warning eventDry-run projection: dryRun(plan, providers) returns likelyCents, willExceedBudget, and a per-step breakdown — before any call goes out.
Arbiter voice · reproducibility is the contract
Cael’s rule: if the same input can produce a different pass/fail tomorrow, the test is theatre. SwarmWire ships a RecordingProvider that captures real LLM interactions once, and a ReplayProvider that serves them back byte-for-byte. CI runs on replay — zero cost, zero flake, zero provider dependency. Output contracts fail the build if a persona returns the wrong shape.
Wrap a real provider with RecordingProvider, run the scenario once, save the fixture. In CI, swap to ReplayProvider pointed at that fixture. Your test pipeline no longer depends on anyone else’s uptime.
Typed llm<T>() with a Zod-validated response format. The model returns a string; SwarmWire parses, validates, and rejects with a structured error if the shape is wrong. The caller never sees an ambiguous payload.
TimeTravelStore checkpoints each step; you can fork a past run with a swapped agent at step N and replay forward. RollbackManager snapshots before tool calls so failed invocations undo cleanly.
Named eval suites keep their own run history. Each run reports pass-rate and a trend — improving, stable, degrading — plus the list of eval names that regressed since last run. Wire it into CI as a quality gate, not a postmortem.
Persona providers, budget ledger, planner, executor
The library is ten independent surfaces that happen to fit together well. Bring your own provider adapter, your own memory backend, your own transport. The Swarm class is thin glue; the interesting code lives behind interfaces you can replace.
Anthropic, OpenAI, Gemini, Ollama, and any OpenAI-compatible endpoint (LiteLLM, vLLM, Azure). Circuit breaker, failover chain, rate limit — compose as wrappers, not config.
Single source of truth for cost on a run. Checks before dispatch, records after response, emits warning events at configurable thresholds. Savings tracked per optimisation layer.
Task scored, decomposed, routed through a five-layer stack: semantic cache, latency router, cascade, speculative cascade, query decomposer. Each layer is optional and introspectable.
Runs the DAG with checkpoint/resume, dry-run, differential execution (skips steps whose inputs haven't changed), and OTel auto-export. Approval gates pause a step until a callback resolves.
Plus ten memory backends (ANCS, A-MEM, temporal, self-editing, episodic, procedural, vector, and three external stores), seventeen agent templates, and the A2A / MCP protocol surfaces. All optional, all lazy-loaded.
What this is not
Ipcha Mistabra wrote this section. SwarmWire is narrow on purpose — the scope it refuses is the reason the scope it keeps stays sharp.
Disclosure
SwarmWire is a library you import. No background process, no service to run, no port to expose. If your app is not running, SwarmWire is not running. That is the design.
Disclosure
We do not proxy your keys, bill your usage, or store your traces on our servers. Budget ledgers live in your process. Recordings live on your disk. OTel goes to your collector.
Disclosure
Agents here run inside a bounded DAG with a cost ceiling and a guardrail stack. They do not wake themselves up, rewrite their own goals, or self-deploy. If you want that, use something else.
Quick start
Node 20+, TypeScript 5.5+. Zero runtime dependencies besides Zod. Provider SDKs are optional peer deps — you only install the one you use. Nothing phones home, nothing registers on a control plane.
# Add to your project npm install swarmwire # Install only the provider you use — all peer deps are optional npm install @anthropic-ai/sdk # or openai, or neither for ollama/local # Or clone to read the source — it's meant to be read git clone https://github.com/nyxCore-Systems/SwarmWire cd SwarmWire && npm install && npm test
Free for OSS, small business, education · commercial licence above EUR 25k/yr
Before you wire it into production
Start with swarm.run('prompt') and a low maxCostCents. Record one real run with RecordingProvider, replay it in CI, and keep the fixture under version control. Only then reach for fan-out, debate, or hierarchy. The first week is calibration, not scale — every pattern here is powerful enough to burn through a budget the first time you misconfigure it.
Metis says: ship the boring run first, earn the interesting one.
Run it locally first. The library is yours the moment you install it.