Agent Mail Becomes Memory When Every Coordination Move Is an Event

repoaiagentsagent-loopsmemoryevent-sourcingtypescripteffectcliinfrastructure

maps directly to joelclaw agent loops: file reservations, checkpointed inboxes, and retro-style coordination history for improving future workers

Swarm Mail is an embedded, event-sourced messaging system for coordinating multiple agents in one codebase. It uses PGLite and Effect instead of an external server, then builds actor-style mailboxes, file reservations, request/response, and resumable cursors on top.

The clever bit is that the inbox isn’t just a chat thread. Every coordination move becomes an event. Messages, reads, acks, file reservations, and releases all hit an append-only log before they become queryable views. That means the agent swarm gets coordination now and receipts later.

That matters for joelclaw because agent loops need more than task handoff. They need to know who touched what, where contention happened, what crashed, what resumed cleanly, and what patterns were worth keeping. Joel’s note about agents checking in when they finish is the important second-order move: the coordination layer can become a retro database, not just plumbing.

Publishing Swarm Mail as a CLI and library is the sharper shape. Keep the primitive boring and portable: durable cursor, durable deferred, durable lock, durable mailbox. Let the weird agent systems compose on top of it.

Key Ideas

  • Swarm Mail is local-first coordination: PGLite plus Effect, no Redis, Kafka, or NATS required.
  • The architecture is event-first: agent_registered, message_sent, message_read, message_acked, file_reserved, and file_released build materialized views after the fact.
  • DurableCursor gives agents checkpointed inbox consumption, so crashes can resume from the last committed event instead of starting over.
  • DurableDeferred turns request/response into a URL-addressable future, which makes RPC-ish workflows possible over async streams.
  • DurableLock gives file reservations a concrete CAS-backed mechanism with TTL expiry, so parallel agents can avoid stomping each other’s edits.
  • The useful memory angle is the event log: coordination history can feed retros, evaluations, pattern maturity, and future tooling for agent loops.