Phase 10. Metacognition is a cognitive process with deterministic self-checks (insufficient evidence, single-source reliance, model output without evidence, repeated failed hypotheses, stale contradictions, calibration overconfidence); its warnings compete for attention and, when admitted, add counter-evidence or open an investigation goal. Reflection reviews the period since the last run (prediction errors, rejected beliefs, corrections, status changes, completed goals, contradictions, calibration), turns repeated failures into procedural lessons written once, and records a reflection event; a model may only word the prose within the mind's budget. Consolidation clusters unconsolidated episodes by shared stemmed terms, creates a belief whose confidence is computed from the episodes as evidence and a semantic memory linked to each episode by derived_from, and records jobs with inputs and outputs. Wording may come from the consolidate prompt within a per-run model budget; the job says which. Operators can run, pause and reject; originals are never touched. The narrative hook keeps a five-part first-person narrative built from state and stored with narrative_updated events. The notification hook applies explicit thresholded rules, aggregates repeats within a cooldown and records suppressions with reasons. A scheduled job runs consolidation and reflection per mind, switching the runtime mode while it works. API, Background tab, notifications page with unread badge, overview narrative and warnings, CLI commands, docs/cognition.md.
59 lines
2.5 KiB
SQL
59 lines
2.5 KiB
SQL
-- Consolidation jobs, reflections, narratives and notifications.
|
|
|
|
CREATE TABLE consolidation_jobs (
|
|
id uuid PRIMARY KEY,
|
|
mind_id uuid NOT NULL REFERENCES minds(id),
|
|
status text NOT NULL DEFAULT 'queued' CHECK (status IN ('queued','running','done','failed','rejected')),
|
|
trigger text NOT NULL DEFAULT 'schedule', -- schedule | operator
|
|
started_at timestamptz,
|
|
finished_at timestamptz,
|
|
clusters integer NOT NULL DEFAULT 0,
|
|
produced integer NOT NULL DEFAULT 0,
|
|
inputs jsonb NOT NULL DEFAULT '[]'::jsonb, -- episode ids considered
|
|
outputs jsonb NOT NULL DEFAULT '[]'::jsonb, -- {memory_id, belief_id, proposition, confidence, episodes}
|
|
error text NOT NULL DEFAULT '',
|
|
created_by text NOT NULL DEFAULT '',
|
|
created_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
CREATE INDEX consolidation_jobs_mind_idx ON consolidation_jobs (mind_id, created_at DESC);
|
|
|
|
CREATE TABLE reflections (
|
|
id uuid PRIMARY KEY,
|
|
mind_id uuid NOT NULL REFERENCES minds(id),
|
|
period_start timestamptz NOT NULL,
|
|
period_end timestamptz NOT NULL,
|
|
findings jsonb NOT NULL, -- structured review
|
|
prose text NOT NULL DEFAULT '',
|
|
event_id uuid,
|
|
llm_call_id uuid,
|
|
created_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
CREATE INDEX reflections_mind_idx ON reflections (mind_id, created_at DESC);
|
|
|
|
CREATE TABLE narratives (
|
|
mind_id uuid PRIMARY KEY REFERENCES minds(id),
|
|
text text NOT NULL,
|
|
structured jsonb NOT NULL DEFAULT '{}'::jsonb,
|
|
event_id uuid,
|
|
updated_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
|
|
CREATE TABLE notifications (
|
|
id uuid PRIMARY KEY,
|
|
mind_id uuid NOT NULL REFERENCES minds(id),
|
|
level text NOT NULL CHECK (level IN ('info','warn','alert')),
|
|
title text NOT NULL,
|
|
body text NOT NULL DEFAULT '',
|
|
rule text NOT NULL,
|
|
reason jsonb NOT NULL DEFAULT '{}'::jsonb, -- thresholds and values that fired the rule
|
|
aggregate_key text NOT NULL DEFAULT '',
|
|
count integer NOT NULL DEFAULT 1,
|
|
status text NOT NULL DEFAULT 'new' CHECK (status IN ('new','read','suppressed')),
|
|
source_event uuid,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
read_at timestamptz
|
|
);
|
|
CREATE INDEX notifications_mind_status_idx ON notifications (mind_id, status, created_at DESC);
|
|
CREATE INDEX notifications_aggregate_idx ON notifications (mind_id, aggregate_key, created_at DESC);
|