Inspiration

Every AI agent demo works great until production. The core problem: agents take actions, but nobody can tell you why an agent did what it did, whether anyone authorized it, or what happened last time a similar action was proposed.

I published an argument that agentic loops need four states instead of two: Your Loop Has Two States. It Needs Four. This project is the working implementation — applied to agent memory governance, backed by CockroachDB on AWS.

What it does

The agent operates in a governance loop:

  1. A task arrives (schema change, access modification, data migration)
  2. The agent queries CockroachDB for semantically similar past decisions using pgvector distributed vector indexing
  3. A four-valued governance gate evaluates the proposal — not pass/fail, but YES, NO, MAYBE, or IFF
  4. The human decides — approve, reject, or modify
  5. The decision and execution receipt are persisted to CockroachDB as append-only governance memory
  6. Future proposals are informed by accumulated institutional judgment

Every evaluation produces a typed operator trace — named structural operations (SAME, NEAR, BECAUSE, INSIDE, TOGETHER) that show exactly how the verdict was computed. Every evidence gap is typed by a witness axis (WHAT, WHERE, WHICH, WHEN, FOR-WHAT, HOW, WHENCE) that tells the human exactly which question to answer. These come from published research by the author (cited in the repo).

How I built it

  • CockroachDB Cloud as the persistent governance memory store — proposals, gate evaluations, decisions, execution receipts, consequence reports, and exclusions with full referential integrity
  • CockroachDB Distributed Vector Indexing (pgvector) for semantic precedent search
  • ccloud CLI via a bounded read-only adapter for cluster-info evidence capture
  • AWS Lambda hosts the agent runtime as a serverless function
  • Python 3.12 with asyncpg for high-performance database access
  • Deterministic four-valued reducer (R1→R2→R3→R4 precedence) that selects verdicts by control flow, never by numeric comparison
  • Canonical JSON serialization with full SHA-256 trace digests for append-only auditability

Challenges I faced

The hardest design problem was making the four-valued gate genuinely useful rather than bureaucratic. The consequence-driven feedback loop required careful threshold calibration and append-only evaluation semantics. Every re-evaluation appends a new trace rather than mutating history, which means the gate's reasoning is fully auditable but the data model is more complex than a simple approve/reject table.

Making the operator traces deterministic — stable IDs, canonical serialization, reproducible digests across runs — took more effort than expected. The build verification harness itself uses the same four-valued verdict system, so the governance pattern governs its own construction.

What I learned

CockroachDB's distributed vector indexing handles the dual workload — transactional governance records plus semantic similarity search — in a single system. No separate vector store, no consistency gaps. The ccloud CLI's JSON output mode and consistent patterns made it straightforward to build a bounded evidence adapter.

The four-valued verdict system is genuinely different from binary pass/fail in practice. MAYBE with named evidence gaps changes the conversation from "rejected" to "here's what would resolve this."

What's next

The governance memory pattern is substrate-independent. The same loop applies to document processing, code deployment, infrastructure provisioning, and any domain where agent actions need authorization and audit trails.

Built With

  • agent-governance
  • append-only-audit
  • asyncpg
  • aws-lambda
  • cockroachdb
  • deterministic-evaluation
  • four-valued-logic
  • openai
  • pgvector
  • python
Share this project:

Updates

Submission history