Files
noema/migrations/0009_motivation.up.sql
T
Andy Dixon 9eb873cbe6 feat: add goals, drives, affect state, predictions and curiosity
Phase 9. Goals form a mind-scoped tree with kind, priority, progress and
blockers; their deterministic relevance to a candidate feeds the
goal_relevance attention feature and a goal monitor raises stalled goals
and observations that touch one. Drives are a closed set of eight
scalars with operator-configured ranges and personality-derived
baselines; there is no self-preservation, replication or acquisition
drive and no way to add one at runtime. Affect is ten scalars moved by an
explicit rule table over events and decaying towards baseline; both
modulate attention weights each cycle and the effective weights are
recorded with every cycle and shown beside the configured ones.

Predictions carry a window and machine-checkable criteria (event terms
occurring or staying absent, a belief reaching a confidence, or operator
judgement). A resolver job judges them deterministically, keeps an
append-only outcome history for calibration (accuracy, Brier score,
confidence buckets, overconfidence flag), emits prediction_error events
scaled by how confident the miss was, and feeds the outcome back into the
linked belief as evidence. Causal hypotheses derive predictions
automatically. Curiosity turns misses, contradictions and unexplained
observations into questions that compete for attention and become
investigation goals when admitted.

Brain gains after-cycle hooks and goal/motivation state. API, UI (goals,
prediction dashboard, cognitive state panel, effective weights) and CLI
(goal, prediction, state). Demo scenario 4 verified end to end.
2026-06-27 20:41:03 +01:00

77 lines
3.5 KiB
SQL

-- Goals, drives, affect and predictions.
CREATE TABLE goals (
id uuid PRIMARY KEY,
mind_id uuid NOT NULL REFERENCES minds(id),
parent_id uuid REFERENCES goals(id),
title text NOT NULL,
description text NOT NULL DEFAULT '',
kind text NOT NULL DEFAULT 'task' CHECK (kind IN ('task','investigation','question','maintenance')),
status text NOT NULL DEFAULT 'active' CHECK (status IN ('active','blocked','paused','completed','abandoned')),
priority double precision NOT NULL DEFAULT 0.5 CHECK (priority >= 0 AND priority <= 1),
progress double precision NOT NULL DEFAULT 0 CHECK (progress >= 0 AND progress <= 1),
owner text NOT NULL DEFAULT 'mind', -- mind | operator
blockers jsonb NOT NULL DEFAULT '[]'::jsonb,
origin_event uuid,
subject text NOT NULL DEFAULT '',
due_at timestamptz,
last_progress_at timestamptz NOT NULL DEFAULT now(),
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
completed_at timestamptz
);
CREATE INDEX goals_mind_status_idx ON goals (mind_id, status, priority DESC);
CREATE INDEX goals_parent_idx ON goals (parent_id) WHERE parent_id IS NOT NULL;
CREATE TABLE drives (
mind_id uuid NOT NULL REFERENCES minds(id),
name text NOT NULL,
value double precision NOT NULL,
min double precision NOT NULL DEFAULT 0,
max double precision NOT NULL DEFAULT 1,
baseline double precision NOT NULL DEFAULT 0.5,
updated_at timestamptz NOT NULL DEFAULT now(),
PRIMARY KEY (mind_id, name)
);
CREATE TABLE affect_states (
mind_id uuid PRIMARY KEY REFERENCES minds(id),
state jsonb NOT NULL,
updated_at timestamptz NOT NULL DEFAULT now()
);
CREATE TABLE predictions (
id uuid PRIMARY KEY,
mind_id uuid NOT NULL REFERENCES minds(id),
statement text NOT NULL,
subject text NOT NULL DEFAULT '',
confidence double precision NOT NULL CHECK (confidence >= 0 AND confidence <= 1),
window_start timestamptz NOT NULL DEFAULT now(),
window_end timestamptz NOT NULL,
criteria jsonb NOT NULL, -- {"kind":"event_match","expect":"occurs|absent","terms":[...],"types":[...]} | {"kind":"belief","belief_id":..,"min_confidence":..} | {"kind":"operator"}
status text NOT NULL DEFAULT 'open' CHECK (status IN ('open','confirmed','refuted','expired','withdrawn')),
source text NOT NULL DEFAULT '',
origin_event uuid,
belief_id uuid REFERENCES beliefs(id),
resolved_at timestamptz,
resolution jsonb,
created_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX predictions_mind_status_idx ON predictions (mind_id, status, window_end);
-- Append-only outcomes for calibration.
CREATE TABLE prediction_results (
id uuid PRIMARY KEY,
prediction_id uuid NOT NULL REFERENCES predictions(id),
mind_id uuid NOT NULL REFERENCES minds(id),
outcome text NOT NULL CHECK (outcome IN ('confirmed','refuted','expired','withdrawn')),
confidence double precision NOT NULL,
error double precision NOT NULL, -- |outcome(1/0) - confidence| for confirmed/refuted
evidence jsonb NOT NULL DEFAULT '[]'::jsonb,
event_id uuid,
resolved_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX prediction_results_mind_idx ON prediction_results (mind_id, resolved_at DESC);
CREATE TRIGGER prediction_results_append_only BEFORE UPDATE OR DELETE ON prediction_results
FOR EACH ROW EXECUTE FUNCTION noema_forbid_change();