Docs

Architecture · 11.01

The Durable Entity: The Atom of Everything

A restart-durable, single-writer record with a typed inbox and a wake clock — the atom behind agents, subjects, workflows, and apps.

Durable Entity

The same shape the rest of the industry converged on independently

A Durable Entity is one keyed, restart-durable record with a single writer, a typed inbox, and a wake clock. This isn't a bespoke Agentis invention — it's the same shape Restate's Virtual Objects, Cloudflare's Durable Objects, and Temporal's entity workflows each converged on independently, rebuilt here on plain SQLite instead of a dedicated distributed runtime. The payoff of recognizing that convergence: an Agent and a per-subject Subject actor aren't two different systems that happen to look similar — they're literally the same primitive, distinguished only by their kind column.

The trap this design specifically avoids

SQLite is single-writer for the whole file, but that is not the same guarantee as single-writer per entity — without an explicit safeguard, a cron tick and a webhook-driven wake could both try to mutate the same entity at once. The fix is a lease: leaseOwner and leaseExpiresAt columns that a worker must hold before advancing an entity, claimed via compare-and-swap so two workers can never both believe they hold the same lease simultaneously. A stale lease — the process that held it crashed or hung — is simply reclaimed once it expires, which is what makes the whole system safe under a multi-process or crash-restart world without needing a separate distributed lock service.

Out-of-order and multi-day, for free

Because every entity owns its own inbox, and a reply routes back to the correct entity by a unique correlation token rather than by arrival order, an entity can wait days for a response, receive events wildly out of order, and still resume correctly — there's no assumption anywhere that messages arrive in the sequence they were sent. Run-state is deliberately kept separate from entity-state: a run is the transient thing a single wake spawns, and this layer never touches workflow_runs directly, keeping the entity's own durable identity cleanly decoupled from any one execution.

Continue