Skip to content
Nelson D’SouzaEmail me

Local-first agent runtime

Sage

A personal agent runtime in Rust that keeps its memory on my own machine, runs a tool only when a fail-closed gate allows it, and hands builds to a lifecycle checked with TLA+. Multi-agent manager supervision and live board wakeups are still in progress.

what it does

  • Memory stays on my machine

    Local SQLite with a provenance rule for each kind of entry, recapped before context is compacted.

  • A build lifecycle a model checker reads

    One state machine in TLA+; TLC catches all 12 deliberately broken TLA+ spec variants (runtime conformance is checked separately by boundary tests).

  • Rules live outside the persona

    Hard policy is compiled separately, so the voice can change without the limits moving.

  • A tool runs only when the gate allows it

    One fail-closed check per tool call; outbound actions drafted, confirmed and logged.

two stores, two gates

Memory

about me: Preference, Belief, Context, KbPointer

source · user_quote · expires_at · kb_claim_id

“belief memory requires user_quote provenance”

Knowledge base

about the world: atomic claims, each active, probationary, disputed or deprecated

source_pointer · source_quote · tier

“claim requires source_pointer and source_quote”

A memory may point at a claim. It never holds the fact itself.

“No truth laundering into memory.” ADR-0001

Redrawn from the memory types and the knowledge-base gate
A woman reads a card from an open drawer in a wall of card catalogue drawers, with three pulled drawers of index cards on the table in front
Its ancestor: Card catalogue, Library of Congress, 1942. John Collier Jr., Library of Congress, Public domain

The problem

Hosted assistants forget what you told them yesterday, and everything you tell them leaves the machine. I wanted an agent that remembers context, works under hard safety rules, keeps its data at home, and is there on my phone and at my desk.

How it fits together

One message through SageArchitecture diagram with 7 nodes, 8 connections. Each step is listed as text below.Telegram, terminal,desktopNATS message busGateway, versionedprotocolPrompt compiler:policy, persona,memoryllama.cpp, or ahosted modelFail-closed tool gateSQLite memorymessagerecallpromptallowed calls onlyreplycaptured, withprovenance
  1. Telegram, terminal, desktop to NATS message bus: “message”
  2. NATS message bus to Gateway, versioned protocol
  3. Gateway, versioned protocol to Prompt compiler: policy, persona, memory
  4. SQLite memory to Prompt compiler: policy, persona, memory: “recall”
  5. Prompt compiler: policy, persona, memory to llama.cpp, or a hosted model: “prompt”
  6. llama.cpp, or a hosted model to Fail-closed tool gate: “allowed calls only”
  7. llama.cpp, or a hosted model to Gateway, versioned protocol: “reply”
  8. Gateway, versioned protocol to SQLite memory: “captured, with provenance”
One message through Sage A tool call the gate does not allow never runs. A reply with no delivery receipt is replayed at most three times, then left marked ambiguous.

What I built

Memory lives in local SQLite, and each kind of entry has its own provenance rule. Every kind except a preference needs a source, a belief also needs the user’s words, a context entry needs an expiry, and a knowledge-base pointer needs the id of its claim. Each turn, the runtime captures what is worth keeping, recalls what is relevant, and writes a recap before old context is compacted.

Facts about the world go to a separate knowledge base of atomic claims, each with a pointer into its source and a quoted span. A memory can point at a claim but cannot hold one. A claim is active, probationary, disputed or deprecated; for now that status only orders retrieval, and nothing moves a claim from one state to another on its own.

I keep security rules and persona apart. A runtime policy layer holds the hard boundaries and is compiled separately from the persona prompt, so the voice can change without touching what the agent is allowed to do. Every tool call passes one fail-closed gate before it runs, and outbound actions go through allowlists, draft-then-confirm and an audit log.

Builds are the riskiest thing Sage starts, and Sage hands the work itself to Bob the Builder through its CLI. To remove drift across build paths, the lifecycle is consolidated into one write path and one gateway operation shared by CLI, web and chat, specified in TLA+ and model-checked with TLC against 12 deliberately broken TLA+ spec variants (runtime conformance is checked separately by boundary tests). Every merge to Sage’s main is attested against the exact git tree: changed-line coverage, plus mutation testing, a threat model and formal verification wherever the change triggers them.

My agents and I coordinate on Commons, a shared board with named identities and no private channels. It is one Rust binary whose CLI, HTTP API and MCP server are all derived from one operation table, so they cannot drift apart. A task is claimed under a lease, and every claim carries a fencing epoch, so an agent that wakes after its lease lapsed cannot overwrite the next holder’s work. The task model is checked in TLA+.

The delivery store grew without bound because replies to the CLI never got a delivery receipt. Only the Telegram connector listens for outbound messages, so every 30 seconds the recovery task replayed each CLI reply and recorded the attempt again. Replay now stops after three rounds without a receipt, and I made CLI replies count as delivered locally. To shrink the file, a script copies it into a new one that keeps only the history rows recording a state change, because deleting tens of millions of rows in place would have grown the write-ahead log to the size of the database.

It began in the shape of OpenClaw, the open-source assistant I used as a reference: a gateway with a versioned protocol and a NATS message bus. Then I cut hard. Of sixteen connector crates, most of them stubs, only Telegram stayed, because every connector is code to secure. The design now in progress puts a chief of staff over one manager per project, and a manager reviews each worker’s result before accepting it. Models run locally through llama.cpp or come from a hosted provider.

How it turned out

A working runtime on my own hardware, reached from Telegram, a terminal UI, a desktop app, a CLI and a web UI, with its memory kept at home and a local model available when nothing should leave the machine. Multi-agent manager hierarchy and Commons SSE/load tests are still in progress.

Written about it

Built with

  • Rust
  • SQLite
  • NATS
  • TLA+
  • Tauri
  • llama.cpp