Skip to content
nyxCore/SwarmWireInstall
nyxCore

Multi-agent orchestration · TypeScript

SwarmWire

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+

Thesis — library, not framework

One sentence to decide on

Most frameworks own your app. SwarmWire is a library you call.

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 modeWhat SwarmWire does instead
Token bleeding — agent loops burn money silentlyBudget 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 oneProgressive 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 structurePlain functions and plain classes. No app skeleton required, no runtime to host.
Python-first ports with a TypeScript wrapper on topTypeScript-native. Strict mode, noUncheckedIndexedAccess, full generic typing on deps and outputs.
No cost visibility — frameworks treat cost as an afterthoughtPer-agent, per-provider, per-step cost breakdown on every execution. Dry-run before you spend.
Pattern — fan-out

One input · N personas · one merged output

Run specialists in parallel. Validate the merge with a contract.

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.

Default

Orchestrator-Worker

Workers run in parallel, a synthesizer merges results. The workhorse for most research and review tasks.

Sequential

Pipeline

Named stages, each agent's output feeds the next. Typed handoffs, per-stage budget slice, clear failure boundaries.

Parallel

Fan-Out

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.

Chunking

Map-Reduce

Split input, process chunks in parallel with a worker agent, fold with a reducer. Bounded parallelism, per-chunk cost tracking.

Multi-round

Debate · Blackboard · Hive-Mind

Argued positions with a judge, shared-state refinement, or domain-specialised swarms with a master orchestrator. Convergence thresholds in every variant.

Runtime topology

Loop · State Machine · EventFlow

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.

Budget-first — the whole thesis in one ledger

Hard limits, not advisory

Budget is a constraint, not a suggestion.

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

Five dials. No advisory ones.

  • maxCostCentsHard cost ceiling — the primary knob
  • maxTokensToken ceiling across the whole run
  • maxLatencyMsWall-clock stop line
  • maxAgentsCap on concurrent agents
  • warningAt0–1 fraction — fires budget:warning event

Dry-run projection: dryRun(plan, providers) returns likelyCents, willExceedBudget, and a per-step breakdown — before any call goes out.

Determinism — record once, replay forever

Arbiter voice · reproducibility is the contract

A test that calls a live model is not a test.

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.

Record / Replay providers

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.

Output contracts

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.

Time-travel + rollback

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.

Eval harness with regression

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.

Architecture — the seams we ship

Persona providers, budget ledger, planner, executor

Everything is a swap-in. Providers, memory, transports, guardrails.

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.

Provider bridge

Anthropic, OpenAI, Gemini, Ollama, and any OpenAI-compatible endpoint (LiteLLM, vLLM, Azure). Circuit breaker, failover chain, rate limit — compose as wrappers, not config.

Budget ledger

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.

Planner → DAG

Task scored, decomposed, routed through a five-layer stack: semantic cache, latency router, cascade, speculative cascade, query decomposer. Each layer is optional and introspectable.

Parallel executor

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.

Honest positioning — 03

What this is not

Before you import it, know what it refuses to be.

Ipcha Mistabra wrote this section. SwarmWire is narrow on purpose — the scope it refuses is the reason the scope it keeps stays sharp.

Disclosure

Not a daemon.

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

Not a hosted control plane.

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

Not an agent autonomy framework.

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.

Install — under a minute

Quick start

One dependency. No daemon, no config file.

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
Get it on GitHub npm · swarmwire Docs

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.

See the rest of the nyxCore ecosystem ArchReview uses this fan-out Talk to the team

Run it locally first. The library is yours the moment you install it.