Architecture Overview

CortexPrism is a single-process agentic harness written in TypeScript/Deno. It exposes a CLI, a REST API + WebSocket server, and a web UI. All state is persisted in SQLite databases using WAL mode via @libsql/client.

High-Level Architecture

┌─────────────────────────────────────────────────────────────────┐
│                         CortexPrism                             │
│                                                                 │
│   CLI (cortex chat / run / serve / ...)                         │
│          │                                                      │
│          ▼                                                      │
│   ┌─────────────────────────────────────────────┐              │
│   │              agent/loop.ts                  │              │
│   │  userMessage → [memory inject] → LLM call   │              │
│   │  → [tool parse] → [validator] → [execute]   │              │
│   │  → [re-prompt loop] → response              │              │
│   │  → [episodic write] → [reflection]          │              │
│   └─────────────────────────────────────────────┘              │
│          │                                                      │
│   ┌──────┼──────────────────────────────────────┐              │
│   │      │         Subsystems                   │              │
│   │  memory/   tools/   sandbox/   security/    │              │
│   │  llm/      server/  scheduler/              │              │
│   └──────────────────────────────────────────────┘             │
│                                                                 │
│   SQLite databases (WAL mode)                                   │
│   cortex.db · memory.db · lens.db · vault.db · sess_*.db       │
└─────────────────────────────────────────────────────────────────┘

Core Components

ComponentDescription
Agent LoopCore reasoning + tool loop that orchestrates LLM calls, tool execution, memory operations, and reflection
Memory System5-tier memory with hybrid FTS5 keyword + vector embedding retrieval and exponential decay scoring
LLM Layer12+ provider implementations with unified LLMProvider interface and CascadeRouter
Tool SystemExtensible tool registry with built-in tools for file I/O, shell, web search, and code execution
Security (Parallax)3-stage policy validation gate with encrypted vault, regex deny rules, and full audit logging
SandboxDocker container sandbox (subprocess fallback) with resource limits and auto-fix loop
Daemon SupervisorBackground process manager for validator, executor, and scheduler daemons with auto-restart
HTTP ServerBuilt-in web server with REST API, WebSocket streaming, and web UI dashboard
SchedulerSQLite-persisted cron job scheduler with retry

Data Flow

  1. User input enters through CLI, Web UI, or API
  2. Agent loop processes input with context from memory
  3. LLM provider generates response via the model router
  4. Tool calls are executed through the Parallax security gate
  5. Results are stored in memory and returned to the user

Core subsystems