A metacognitive loop that perceives signals, makes falsifiable predictions, scores them when they mature, learns from the surprises, and keeps an honest audit trail — so an agent measures its own accuracy instead of asserting it.
Sentience Loop is a self-monitoring loop built on one idea from predictive processing: a system that models itself should predict, then check. Each tick it PERCEIVES signals from sensors you plug in, PREDICTS a few falsifiable things with a confidence and a test-after horizon, SCORES past predictions that have now come due against what actually happened, treats the wrong ones as SURPRISE (writing a belief-update), REFLECTS on the recent record, and RECORDS the cycle to an append-only ledger. Nothing self-judges: predictions are scored against real observed outcomes, never against the model's own opinion. Bring your own sensors and scorer; a deterministic built-in demo runs the whole loop with zero dependencies and no API key.
A sensor is just `() => [{ type, severity, detail }]`. Register as many as you like — a log reader, a metrics probe, a queue-depth check. The loop runs them each tick, collects the signals, and hands a thrower's failure to the soft-failure log instead of letting it crash the cycle. The loop owns the cadence; you own what counts as a signal.
From the signals the loop emits a few predictions — each with a confidence and a `test_after` time — and dedupes them so the same claim isn't logged every tick. When a prediction's horizon passes, a scorer you supply reads the real outcome and marks it correct or not. Predictions are graded against observed ground truth, never against the model's own judgment.
A prediction that was confident and missed is a surprise — the loop writes a belief-update naming the prior that needs recalibration, so the next prediction is sharper. Every tick appends an honest cycle record (signals, predictions made, scored, surprises, duration) to a ledger you can audit. Reflection surfaces the recent contradiction count. Nothing is hidden; nothing self-congratulates.
Every value comes from .env. Nothing here is tied to any account — bring your own.
# 1. no install needed — pure Node builtins node examples/demo.cjs # run the full loop with a deterministic built-in world # 2. run a handful of ticks and watch predictions mature + get scored node lib/sentience-loop.cjs --ticks=6 # 3. in your code — bring your own sensors + scorer # const { CognitiveLoop } = require('./lib/sentience-loop.cjs'); # const loop = new CognitiveLoop({ dataDir: './data' }); # loop.addSensor('errors', () => probeErrors()); // () => [{type,severity,detail}] # loop.addScorer('system', (pred) => readGroundTruth(pred)); // -> {actual, correct} # loop.tick(); // perceive→predict→score→surprise→reflect→record