Project

legion

experimental

Self-hosted durable agents and WASM/Bun functions across a self-forming Raft cluster.

Overview

I started Legion because I wanted Piclaw's backend to survive process and node failures without adopting a cloud control plane. It is a Rust platform for event-sourced AI agent turns and content-addressed WASM or Bun functions, spread across a LAN-first cluster that discovers and reconnects to peers automatically.

The same durable state sits behind a 9P namespace, so functions, sessions and cluster resources are available as paths rather than through a collection of unrelated APIs. The project is experimental; storage and networking dependencies are still settling.

How it works

Clients use a 9P namespace over authenticated iroh QUIC to reach functions, sessions and cluster state. Agent turns record intent before execution, append model and tool events as they happen, and can resume from the committed event log on another node. WASM modules and Bun bundles are stored by content hash and registered separately, which makes deployment immutable and keeps architecture-specific code out of WASM workloads.

Raft-replicated SQLite holds strongly consistent metadata, fjall stores the Raft log, and iroh-blobs carries larger content-addressed payloads. Nodes find each other through mDNS on a LAN, use public-key identities instead of fixed IP addresses, and exchange membership and health information through iroh-gossip.

Features
→
Durable agent turns

Event-sourced turns record model output, tool calls, budgets and completion state so another node can resume interrupted work.

→
Self-forming cluster

mDNS bootstraps local peers; iroh QUIC, gossip and Raft maintain identity, membership and replicated state as addresses change.

→
Content-addressed functions

WASM modules and Bun bundles are uploaded as immutable blobs, registered by CID and promoted through weighted routing.

🗂️
9P namespace

Functions, sessions, peers and cluster state appear under a single filesystem-like namespace for clients, scripts and agents.

→
WASM and Bun runtimes

Wasmtime and Extism execute portable WASM components, while supervised Bun subprocesses handle JavaScript and TypeScript workloads.

→
Operations

OpenTelemetry metrics, restic backups with restore checks, health reporting and load gates help monitor and recover the cluster.

Architecture
Clients CLI · REST · Bun workers 9P namespace functions · sessions · cluster Durable execution event-sourced workloads Agent loop resume turns Functions WASM · Bun Event store SQLite · fjall · blob CAS Legion cluster Raft · iroh QUIC · mDNS Durable agents and functions on a self-forming Raft cluster