Skip to content

Docs · SDK

Write colonies that run on Mandible.

Write agents that coordinate through a shared environment instead of a message bus. The Mandible SDK is open source; the runtime is where it becomes governable.

npm install @mandible-ai/mandible
GitHub

Quickstart

Install the SDK. It runs on Node 20 or later. Each harness's own SDK is an optional peer dependency: to use withClaudeCode, for example, also install @anthropic-ai/claude-agent-sdk.

npm install @mandible-ai/mandible

Minimal API

Define colonies inline or as reusable modules. They self-organize through signals. In this pipeline the keeper opens a pull request rather than merging: agents propose, and people merge.

// Three colonies. Zero coordination code.

const host = await mandible('code-pipeline')
  .environment(env)

  .colony('shaper', c => c
    .sense('task:ready', { unclaimed: true })
    .do('shape', withClaudeCode({
      model: 'sonnet',
      prompt: (s) => `Implement ${s.payload.title} on branch ${s.payload.branch}`,
      allowedTools: ['Read', 'Edit', 'Bash'],
      output: (_, s) => ({ type: 'artifact:shaped', payload: s.payload }),
    }))
    .concurrency(3)
    .claim('lease', 120_000))

  .colony('critic', c => c
    .sense('artifact:shaped', { unclaimed: true })
    .do('review', withStructuredOutput({
      model: 'sonnet',
      prompt: (s) => `Review the change on ${s.payload.branch}`,
      route: (r, s) => r.approved
        ? { type: 'review:approved', payload: s.payload }
        : { type: 'review:changes-needed', payload: r },
    })))

  .colony('keeper', c => c
    .sense('review:approved', { unclaimed: true })
    .do('open-pr', withBash({
      command: (s) => `gh pr create --head ${s.payload.branch} --fill`,
      output: { type: 'pr:opened' },
    }))
    .claim('exclusive'))
  .start();

Run it with the dashboard

The CLI starts every colony in a config file and opens a live dashboard of signals and colonies on localhost:4040.

mandible dev mandible.config.ts

Concepts

Colonies never talk to each other. They sense signals in a shared environment, act, and leave new signals behind, the way an ant colony coordinates through pheromone trails.

The Stigmergy Loop

No orchestrator. No message broker. Complex workflows emerge from simple rules.

  1. Sense

    Agents observe environment signals

  2. Match

    Signals match agent capabilities

  3. Claim

    Agent claims work atomically

  4. Act

    Agent performs the task

  5. Deposit

    New signals left in environment

  6. Repeat

    Other agents sense the new signals

Built on Biological Principles

Mandible borrows coordination patterns from ant colonies and other swarm systems.

Signals as Pheromones

Agents leave typed, structured signals in the environment. Signals have concentration that decays over time — stronger signals get processed first.

Environment is State

Filesystem, database, GitHub, Kubernetes — any shared substrate becomes a coordination layer. Observable, debuggable, and persistent.

Colonies, Not Agents

Groups of identical agents with shared rules. Stateless and replaceable. Scale by increasing concurrency — no rewiring required.

Pluggable Intelligence

Each colony uses the minimum LLM it needs. Full coding agents for complex work, structured output for judgment, shell commands for mechanics.

Pheromone Decay

Signals weaken and evaporate over time. No stale work, no unbounded queues. The system naturally recovers from abandoned tasks.

Emergent Behavior

Self-healing, load balancing, quality convergence — none of it is programmed. It arises from simple colonies following simple rules.

A Different Architecture

Stop building fragile pipelines. Let coordination emerge from the environment.

Message Passing

  • Agents must know who to talk to
  • Coordination scales O(n²)
  • Orchestrator failure halts everything
  • State scattered across agent memories
  • Adding agents means rewiring

Stigmergy

  • Agents only interact with the environment
  • Coordination scales O(n)
  • Agent dies, signal remains, another picks up
  • Environment IS the state — ls to debug
  • Add colonies with zero config changes

API

The environment is where signals live; the host is where colony code runs. They are independent, so the same colonies run on any host. Everything below is exported from @mandible-ai/mandible.

Environments

FilesystemEnvironment({ root })
Signals as files under a directory. The quickest way to start.
GitHubEnvironment({ owner, repo })
Issues, pull requests, labels and reviews as signals. Reads GITHUB_TOKEN.
DoltEnvironment({ owner, database })
Signals as rows in a DoltHub database, with branches.
Your own
Implement the Environment interface over any shared substrate.

Hosts

local()
Runs colonies in the current process. The default when .host() is omitted.
docker()
Runs each colony in its own container. Colonies are passed as module refs.
The Mandible runtime
Hosted, in your account, or air-gapped, with identity, policy and evidence.

The builder

mandible(name)
Starts a pipeline. Chain .environment(env), .host(host), .colony(name, …) and .start().
.colony(name, configure)
Adds a colony, from an inline configurator or a module ref: { module, export }.
.sense(type, query?)
Which signals the colony perceives. * matches within a segment, ** across segments.
.when(predicate)
An extra filter on sensed signals.
.do(name, action)
The action: a harness such as withClaudeCode, or your own async (signal, ctx) function.
.claim(strategy, lease?)
exclusive (the default), lease, optimistic or none.
.concurrency(n)
How many agents work at once; a number or { min, max }. Defaults to 1.
.timeout(ms) · .retry(n, backoffMs)
Bound each action and retry failures.
.decay(enabled)
Turn concentration decay off for this colony.

The action context

ctx.deposit(type, payload?, options?)
Leaves a signal. Lineage (causedBy) defaults to the signal that triggered the action; tags and ttl are optional.
ctx.withdraw(id)
Removes a signal once its work is done.
ctx.enrich(id, changes)
Adds payload fields or tags to an existing signal.
ctx.release(id?)
Gives up a claim so another agent can take the work.
ctx.log(message, level?) · ctx.heartbeat()
Logging and liveness.

Signals and decay

A signal has a type, a payload and metadata: concentration from 1.0 down to 0.0, lineage, claim state, tags and a TTL. Stronger signals are processed first. By default concentration falls 1% a second, a signal evaporates below 5%, and the sweep runs every five seconds.

How-to guides on GitHub

Harness integrations

A colony's action can be another team's agent. Each runs as one bounded stage: it senses a signal, does its work, and deposits the result. Models accept a tier alias (fable, opus, sonnet, haiku, local) or a full model ID.

Providers

withClaudeCode
Claude Code, through the Claude Agent SDK.
withDroid
Factory.ai Droids, with an autonomy level and a tool allowlist.
withOpenCode
An OpenCode server.
withOpenHands
An OpenHands server.
withQwenCode
Qwen Code against an endpoint you run. From @mandible-ai/mandible/providers.
withStructuredOutput · withLLM
One model call with a typed result, routed to a signal: Anthropic, Bedrock, OpenAI, Vercel AI or Gemini.
vllmProvider · withToolLoop
Models on your own GPUs through vLLM. From @mandible-ai/mandible/providers.
withBash
A shell command, for mechanical steps.
withModelRouter · withClassifier
Pick a model per signal from marks already in the environment.

Model routing without a router

How a colony becomes governed

The SDK is how you write colonies. On the local or Docker host they run exactly as written. On the Mandible runtime, the same colonies are governed.

Identity

Each colony's sandbox holds a SPIFFE identity. Its model access and network follow that identity and expire with it.

Memory, not actions

On the runtime a colony writes only to operational memory, through typed writes: a result, a narrative, a decision. A keeper that calls gh itself, as in the sample above, becomes a proposal in memory instead. Nothing a colony emits touches your estate.

Policy

Before a controller acts, the proposed action is checked against Cedar policy: the actor's identity, the action (open a pull request, transition a ticket, emit evidence, call a model), and the autonomy gate signed for that capability. A refusal is recorded with the policy bundle hash and its reasons, and nothing acts.

Controllers

Controllers are small Go programs with one action each and no model behind them. Each checks policy, advances the episode under the fence token minted when the work was claimed, performs its action, and writes a change record under the same fence. A stale fence means do not act.

A build-time boundary

A lint rule over the Go import graph keeps the planes apart: actors cannot import controllers, vendor adapters, or source-control, Kubernetes, cloud and model SDKs. The build writes a boundary attestation. Could the agent have done it? is answered by the import graph.

Evidence

Every decision, change and closure is an in-toto statement in a DSSE envelope, exported per episode as OSCAL assessment results and a POA&M entry. Declines are statements too.

Where this stands: the controllers, fence tokens, policy checks and boundary lint above run in the reference deployment today, with the policy check in-process. A shared policy decision point in signal-server, and the equivalent boundary rule for SDK colony bundles, are designed and not yet shipped. We would rather say so here than have you find out in a review.

The hosted host package (@mandible-ai/cloud) is distributed through GitHub Packages, not public npm. The hosted-deployment guide covers package access, project credentials, module references, and the console.