Skip to content

5-Layer Brain Architecture โ€‹

WakeIQX implements a temporal intelligence brain with five specialized layers that work together to provide AI agents with sophisticated context awareness across time dimensions.

The Five Layers โ€‹

Research Foundation

The 5-layer temporal architecture (Past-Present-Future-Adaptive-Personality) implements principles from semantic intent research. This design treats context as a living graph where each node carries semantic meaning about why it exists, how it remains relevant, what future value it holds, how well that prediction works, and how it should be presented.

๐Ÿ“š Read the foundational research: Semantic Intent as Single Source of Truth

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Layer 5: PERSONALITY MODES (Presentation)          โ”‚
โ”‚  historian ยท prophet ยท archaeologist ยท minimalist   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ†‘
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Layer 4: META-LEARNING (Adaptive - HOW WELL)       โ”‚
โ”‚  Tunes prediction weights per project over time     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ†‘
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Layer 3: PROPAGATION ENGINE (Future - WHAT)        โ”‚
โ”‚  Predicts which contexts will be needed next        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ†‘
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Layer 2: MEMORY MANAGER (Present - HOW)            โ”‚
โ”‚  Manages context relevance and lifecycle            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ†‘
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Layer 1: CAUSALITY ENGINE (Past - WHY)             โ”‚
โ”‚  Tracks decision history and reasoning chains       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Overview โ€‹

Each layer serves a distinct temporal purpose:

๐Ÿ” Layer 1: Causality Engine (Past) โ€‹

Answers: "WHY was this context created?"

Tracks the causal relationships between contexts, allowing you to:

  • Trace decision history backwards through time
  • Understand what led to each context being created
  • Reconstruct reasoning chains from root causes
  • Analyze action types and their dependencies

Key Features:

  • Causal chain tracking with causedBy relationships
  • Action type classification (conversation, decision, file_edit, tool_use, research)
  • Reasoning reconstruction from any point in time
  • Analytics on decision patterns

Learn more about Layer 1 โ†’


๐Ÿ’พ Layer 2: Memory Manager (Present) โ€‹

Answers: "HOW relevant is this context now?"

Manages the lifecycle and accessibility of contexts using memory tiers:

  • ACTIVE (< 1 hour): Hot, frequently accessed contexts
  • RECENT (1-24 hours): Warm, recently used contexts
  • ARCHIVED (1-30 days): Cold, aging contexts
  • EXPIRED (> 30 days): Candidates for pruning

Key Features:

  • Automatic tier classification based on access patterns
  • LRU (Least Recently Used) tracking
  • Memory pressure management
  • Intelligent pruning of expired contexts

Learn more about Layer 2 โ†’


๐Ÿ”ฎ Layer 3: Propagation Engine (Future) โ€‹

Answers: "WHAT contexts will be needed next?"

Predicts future context relevance using multi-factor scoring:

  • Temporal momentum (recent access patterns)
  • Causal chain position (root causes are more valuable)
  • Access frequency (popular contexts are more likely to be reused)

Key Features:

  • Prediction scoring (0.0 to 1.0)
  • Pre-fetching optimization
  • High-value context identification
  • Propagation reason tracking

Learn more about Layer 3 โ†’


๐Ÿ”„ Layer 4: Meta-Learning (Adaptive) โ€‹

Answers: "HOW WELL are predictions working for this project?"

Observes prediction accuracy and adjusts Layer 3 composite weights per project:

  • Records hit/miss outcomes for each prediction
  • Tunes temporal, causal, and frequency weights automatically
  • Weights clamped at [0.1, 0.6] to prevent over-fitting

Key Features:

  • Per-project weight storage in project_weights table
  • Outcome recording in prediction_outcomes table
  • Adaptive tuning after 20+ recorded outcomes
  • get_learning_stats for observability

Learn more about Layer 4 โ†’


๐ŸŽญ Layer 5: Personality Modes (Presentation) โ€‹

Answers: "HOW should context be retrieved and framed?"

Four temporal postures applied via personality_mode on load_context and search_context:

ModeFocusRetrieval OrderBest For
historianDecision historyBy recency (default)Resuming work, audit trail
prophetWhat comes nextBy prediction score (Layer 4)Planning next session
archaeologistDormant threadsBy dormancy (least-accessed first)Rediscovering forgotten context
minimalistRaw contextBy recency, no framingProgrammatic use, token savings

Key Features:

  • Applied at retrieval time โ€” no schema changes needed
  • prophet uses Layer 4 per-project prediction weights
  • archaeologist fetches pool of 50, re-sorts by lastAccessed ASC (null first)
  • minimalist strips all formatting, just the summaries

Learn more about Layer 5 โ†’


How the Layers Work Together โ€‹

Example: AI Agent Conversation Flow โ€‹

typescript
// User starts a new conversation
save_context({
  project: "user-123",
  content: "I want to refactor the authentication system",
  metadata: {
    actionType: "conversation",
    causedBy: null  // Root cause
  }
})
// โ†’ Layer 1: Records as root cause
// โ†’ Layer 2: Marks as ACTIVE tier
// โ†’ Layer 3: Initializes prediction score

// Agent researches the codebase
save_context({
  project: "user-123",
  content: "Authentication is in src/auth/*.ts with JWT tokens",
  metadata: {
    actionType: "research",
    causedBy: "<previous-context-id>"  // Causal link
  }
})
// โ†’ Layer 1: Links to parent context
// โ†’ Layer 2: Marks as ACTIVE tier
// โ†’ Layer 3: Scores high (recent + causal chain)

// Agent makes a decision
save_context({
  project: "user-123",
  content: "Decision: Use OAuth2 instead of JWT for better security",
  metadata: {
    actionType: "decision",
    causedBy: "<research-context-id>"
  }
})
// โ†’ Layer 1: Extends causal chain
// โ†’ Layer 2: ACTIVE tier, high access count
// โ†’ Layer 3: Very high score (decision nodes are valuable)

// Next day - Agent continues work
load_context({ project: "user-123" })
// โ†’ Layer 1: Reconstructs reasoning chain
// โ†’ Layer 2: Updates tiers (yesterday's contexts now RECENT)
// โ†’ Layer 3: Predicts high-value contexts to pre-fetch

update_predictions({ project: "user-123" })
// โ†’ Layer 3: Recalculates all prediction scores

get_high_value_contexts({ project: "user-123", minScore: 0.6 })
// โ†’ Returns: Decision context (0.85), Research context (0.72)
// โ†’ Pre-fetch these for faster access

Design Principles โ€‹

1. Temporal Separation of Concerns โ€‹

Each layer focuses on one dimension:

  • Layer 1: Historical causality (past)
  • Layer 2: Current relevance (present)
  • Layer 3: Predictive value (future)
  • Layer 4: Adaptive accuracy (self-improvement)
  • Layer 5: Presentation posture (personality)

2. Observable Operations โ€‹

All layer operations are:

  • Deterministic: Same input โ†’ same output
  • Traceable: Full audit trail
  • Testable: Unit tests for all components

3. Performance Optimization โ€‹

  • Layer 1: Lazy chain building (only when needed)
  • Layer 2: Efficient tier recalculation
  • Layer 3: Cached predictions with staleness tracking

4. Scalability โ€‹

  • Layers operate independently
  • Async operations for heavy computations
  • Efficient database queries with proper indexing

Architecture Patterns โ€‹

WakeIQX uses Hexagonal Architecture (Ports & Adapters) to maintain clean separation:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚           Presentation Layer                   โ”‚
โ”‚  (MCP Protocol, HTTP Endpoints)                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚           Application Layer                    โ”‚
โ”‚  (ToolExecutionHandler, MCPProtocolHandler)    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚             Domain Layer                       โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  ContextService (Orchestrator)          โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚     โ”‚        โ”‚        โ”‚        โ”‚               โ”‚
โ”‚  โ”Œโ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ” โ”Œโ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ” โ”Œโ–ผโ”€โ”€โ”€โ”€โ”€โ” โ”Œโ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚Layer 1โ”‚ โ”‚Layer 2โ”‚ โ”‚Layer3โ”‚ โ”‚Layers 4+5 โ”‚  โ”‚
โ”‚  โ”‚Causal โ”‚ โ”‚Memory โ”‚ โ”‚Prop. โ”‚ โ”‚Meta+Modes โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚        Infrastructure Layer                    โ”‚
โ”‚  (D1Repository, Workers AI, KV Store)          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Learn more about Hexagonal Architecture โ†’


Technology Stack โ€‹

  • Runtime: Cloudflare Workers (Edge computing)
  • Database: Cloudflare D1 (SQLite at the edge)
  • AI: Cloudflare Workers AI (llama-3.1-8b-instruct)
  • Protocol: Model Context Protocol (MCP)
  • Language: TypeScript with strict typing

Learn more about the Tech Stack โ†’


Database Schema โ€‹

Layers 1โ€“3 share a unified context_snapshots table. Layer 4 adds prediction_outcomes and project_weights tables. Layer 5 is presentation-only (no schema):

sql
CREATE TABLE context_snapshots (
  id TEXT PRIMARY KEY,
  project TEXT NOT NULL,

  -- Core data
  content TEXT NOT NULL,
  summary TEXT,
  tags TEXT,

  -- Layer 1: Causality columns
  action_type TEXT,
  caused_by TEXT,
  rationale TEXT,

  -- Layer 2: Memory columns
  memory_tier TEXT,
  last_accessed TEXT,
  access_count INTEGER DEFAULT 0,

  -- Layer 3: Propagation columns
  prediction_score REAL,
  prediction_reasons TEXT,
  last_predicted TEXT,

  -- Timestamps
  timestamp TEXT NOT NULL,
  created_at TEXT DEFAULT (datetime('now')),

  -- Indexes for performance
  INDEX idx_project ON context_snapshots(project),
  INDEX idx_memory_tier ON context_snapshots(memory_tier),
  INDEX idx_prediction_score ON context_snapshots(prediction_score DESC)
);

Learn more about Database Schema โ†’


Next Steps โ€‹