Canon

05 — Data Model

The triage data model: candidates, classifications, links, quality scores, and audit records.

Core Tables

triage_results

The primary table for triage candidates. Lives in Neon (Fortress) with D1 mirror.

CREATE TABLE triage_results (
  id UUID PRIMARY KEY,
  message_id TEXT,
  platform TEXT,              -- 'ai_conversation', 'integratewise_session', etc.
  content TEXT,
  priority TEXT,              -- 'low', 'medium', 'high', 'urgent'
  category TEXT,
  confidence REAL,
  reasoning TEXT,
  sentiment TEXT,             -- 'positive', 'neutral', 'negative'
  metadata JSONB,            -- tenant_id, user_id, source, etc.
  approval_status TEXT DEFAULT 'pending'
    CHECK (approval_status IN ('pending', 'approved', 'discarded', 'deferred')),
  approved_by TEXT,
  approved_at TIMESTAMPTZ,
  created_at TIMESTAMPTZ,
  updated_at TIMESTAMPTZ
);

Approval States:

StateMeaningNext States
pendingAwaiting human reviewapproved, discarded, deferred
approvedHuman approved → triggers consolidation(terminal for triage)
discardedRejected by human or auto-discard(terminal)
deferredDeferred for later reviewpending, discarded

consolidated_memories

Consolidated memories produced by the Memory Consolidator.

CREATE TABLE consolidated_memories (
  id UUID PRIMARY KEY,
  tenant_id TEXT,
  consolidation_type TEXT,   -- 'topic', 'user', 'account', 'pattern'
  topic TEXT,
  user_id TEXT,
  account_id TEXT,
  summary TEXT,
  key_insights JSON,         -- JSON array
  recurring_themes JSON,     -- JSON array
  action_patterns JSON,      -- JSON array
  session_count INTEGER,
  time_range_start TIMESTAMPTZ,
  time_range_end TIMESTAMPTZ,
  created_at TIMESTAMPTZ
);

org_memory

Canonical organizational memory. Written only by the Pipeline promotion engine.

CREATE TABLE org_memory (
  id UUID PRIMARY KEY,
  tenant_id TEXT,
  topic TEXT,
  category TEXT,
  content TEXT,
  source_session_id TEXT,
  governance_state TEXT,      -- 'staging' or 'approved'
  confidence REAL,
  embedding TEXT,
  metadata JSON,
  created_at TIMESTAMPTZ,
  updated_at TIMESTAMPTZ,
  related_entity_ids JSON,
  related_departments JSON,
  access_scope TEXT,
  lineage_ref TEXT,
  tier TEXT
);

memory_promotion_audit

Audit trail for every promotion decision.

CREATE TABLE memory_promotion_audit (
  id UUID PRIMARY KEY,
  tenant_id TEXT,
  entity_id TEXT,
  signals JSON,
  score REAL,
  category TEXT,
  promoted BOOLEAN,
  governance_state TEXT,
  rationale TEXT,
  decided_by TEXT,
  created_at TIMESTAMPTZ
);

Durable Object State (iw-agent-runtime)

The TriageAgent Durable Object maintains operational state in SQLite:

CREATE TABLE triage_items (
  id TEXT PRIMARY KEY,
  tenant_id TEXT,
  kind TEXT,
  content TEXT,
  route TEXT,
  status TEXT,
  created_at TEXT,
  resolved_at TEXT
);

This is operational state, not canonical truth. It expires and is rebuildable.

Memory Scopes (Logical)

ScopeTableGovernancePromotion
Personalpersonal_memoryUser-ownedNever widens
Agentagent_memoryWorking stateEvidence only
Conversationalconversational_memoryEphemeralNever promoted directly
Organizational stagingtriage_results (pending)Human review requiredVia approval
Organizational publishedorg_memory (approved)Canonical governed stateSole write path