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
causedByrelationships - Action type classification (conversation, decision, file_edit, tool_use, research)
- Reasoning reconstruction from any point in time
- Analytics on decision patterns
๐พ 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
๐ฎ 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
๐ 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_weightstable - Outcome recording in
prediction_outcomestable - Adaptive tuning after 20+ recorded outcomes
get_learning_statsfor observability
๐ญ 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:
| Mode | Focus | Retrieval Order | Best For |
|---|---|---|---|
historian | Decision history | By recency (default) | Resuming work, audit trail |
prophet | What comes next | By prediction score (Layer 4) | Planning next session |
archaeologist | Dormant threads | By dormancy (least-accessed first) | Rediscovering forgotten context |
minimalist | Raw context | By recency, no framing | Programmatic use, token savings |
Key Features:
- Applied at retrieval time โ no schema changes needed
prophetuses Layer 4 per-project prediction weightsarchaeologistfetches pool of 50, re-sorts bylastAccessed ASC(null first)minimaliststrips all formatting, just the summaries
How the Layers Work Together โ
Example: AI Agent Conversation Flow โ
// 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 accessDesign 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):
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 โ
