Technology · Language

SQL

SQL is how I query the stores everything else projects from: work graphs, tuple statistics, retrieval tables, cost ledgers.

AgentOS · Helix · Agent Swarm · FAFO CorePostgreSQLState as data
State as rows the newest transition, appended as a row
  • 88tables in the AgentOS schema, from 79 forward-only migrations
  • 13,000lines of SQL in that schema
  • 178tables in Helix's collaboration control store
  • 29columns in one presence-aware upsert

I use SQL to design state, contracts and correctness under concurrency, from a governance state machine to an agent runtime's event writer. The databases are PostgreSQL. Helix keeps the durable state of its collaboration shell in its own PostgreSQL control store, grown alongside the shell's features through numbered migrations.

A state machine kept as data

AgentOS runs a multi-agent state machine, and I chose to model it relationally, in forward-only migrations. A generic registry sits underneath and the domain sits on top.

The domain

work orders · criteria · tasks · contracts · evidence · cost

The registry underneath
objects
kinds
typed edges
transitions
Every move is a row in transitions, so a question about the state machine is a query, not a reconstruction.

A reported number computed next to its data

Logic that defines a reported number lives with the data. Validated human-equivalent hours, the labour measure AgentOS reports, is computed by PL/pgSQL functions in the database, with the old and new formulas side by side so a recalibration can be compared. See Why long agent runs fail.

the same rows
Old formulaNew formulareported
Illustrative lengths.

One statement per concurrent write

Agent Swarm writes agent state under heavy concurrency, and I wanted each write to be one exact statement. The schema uses partitioned tables and paired up and down migrations.

Two launches arrive at once

INSERT … ON CONFLICT: one wins, the other inserts nothing

One presence-aware upsert

Each square is one of its columns; only the ones an event carries change (which ones is illustrative). A materialized common table expression makes a terminal transition one statement as well.

A view as a function's contract

FAFO Core and Function Forge starts every function from a PostgreSQL work view, and I made that view the function's data contract, so schema design stays a human step.

the work view
the function's documentation
  • The view's SQL, checkedrequired
  • DDL run by the generatornever

196 deadlocks to zero came from the same habit.

In a performance diagnosis, the database's tuple statistics are the ground truth.