DESIGNING HARNESSES

How to Design a Harness

A practical step-by-step guide to designing a multi-agent Harness — Services, Profiles & permissions, orchestration & events, and three core patterns.

You do not need a complex graph DSL to build a reliable multi-agent system. Every Harness on AnySwarm is a plain TypeScript program built in four concrete design steps.

The 4-step Harness design recipe

1. Design the Services (host-owned shared state)

Start by asking: what information or coordination rules must outlive any single Agent’s prompt? Put that state on the host as one or more typed Services:

  • Lightweight handoffs or boards: an inProcessService backed by memory or a local file.
  • Transactional queues, leases, or citation graphs: an inProcessService backed by SQLite.
  • External systems or evaluators: an httpService or mcpService wrapping a verifier, Git server, or chat platform.

Because Host Gateway validates schemas and attaches an unforgeable caller.agentId, your Service can enforce rules (such as exclusive leases, no self-review, or evaluation budgets) that Agents cannot bypass.

2. Design Profiles and permissions (who can do what)

Map each team role to a Profile with least-privilege boundaries:

  • Workspace write access: keep explorers, planners, and reviewers writable: false; grant writable: true only to roles that should produce files or patches (or unlock writes dynamically via runtime.files.replace()).
  • Service operations: expose only the exact operations each role needs (e.g., lead can post_direction, worker can claim_task and submit_patch).
  • Resources & models: assign different models, CPU/memory caps, or container images per role.

3. Orchestrate the team and handle Events

Wire the roles together in one createRuntime() loop:

  • Turn-based vs concurrent: use runInput() for sequential stages, or Promise.all / runtime.send() for parallel peers.
  • Event-driven steering: subscribe to runtime.onEvent() when one Agent’s action should trigger a reaction (waking an idle parent, steering a runaway peer with send({ mode: 'steer', wakeIfIdle: false }), or cancelling siblings when a target score is reached).
  • Explicit bounds: always set turn timeouts, wall-clock budgets, and clear stopping rules.

4. Verify and close cleanly

Never treat an Agent’s final message as proof of success. Check business acceptance on the host (byte checks, test suites, or an isolated Evaluator), then call runtime.close() so Stop → Export → Delete archives every trace and required artifact before removing containers.


Three core collaboration patterns

All three patterns below run on the same unmodified Runtime with zero external infrastructure — they differ only in how they choose Services, Profiles, and Orchestration:

Pattern When to use it Host Services Profiles & Permissions Orchestration & Events
Subagents A lead needs to split a complex task into independent subtasks and synthesize results Member tree & mailbox (collaboration) /root spawns children & aggregates; children inspect or edit scoped slices Event-driven wakeups when children finish or send mailbox messages
TaskPool Multiple workers should compete to discover and execute tasks without overwriting each other Task queue (task), shared notes (context), versioned workspace Workers start read-only; winning an exclusive timed lease unlocks writes Host enforces lease timeouts and rotates workers cleanly on finish/expiry
Substrate Equal peers should explore an open-ended space and build cumulatively on each other’s findings Append-only SQLite citation store (publish / search / visit) All peers share one equal Profile with no central manager Fully parallel exploration with no locks; progress emerges via explicit citations

Need external Git or team chat infrastructure? The repository also includes examples/peermesh (Gitea + Mattermost + MySQL) and examples/lead-worker (Gitea + transactional SQLite board) as advanced integration references.


Adapt a Harness with your coding agent

Pick the pattern closest to your problem, eject it, and let your coding agent adapt the Services, Profiles, and orchestration to your domain:

Help me design and build a custom AnySwarm Harness for my workflow.
1. Eject the closest starting template (e.g. `anyswarm eject subagents --dir ./my-harness`, or `taskpool` / `substrate` / `first-harness`) if ./my-harness does not exist.
2. Read the exported README.md, AGENTS.md, and installed @anyswarm/core types.
3. Ask me for my goal, input directory, and objective acceptance criteria if missing.
4. Design the host Services, Agent Profiles & permissions, event/orchestration loop, and host verification using public SDK APIs on one Runtime.
5. Run local checks and explain how to run the Harness — do not overwrite my source repository or start a paid model run without my approval.