The companion codebase for the book Building Persistent AI: Designing an Assistant That Remembers, Learns and Belongs to You by Cleverson Santos.
| π Companion paper | Phoenix V2: A Cognitive Architecture for Persistent, Emotionally-Aware AI Assistants on Consumer Hardware β Zenodo, September 2026 | | π Book | Building Persistent AI: Designing an Assistant That Remembers, Learns and Belongs to You β Complete implementation guide, 26 chapters, 7 appendices | | π» Repository | This repository β MIT License |
The paper formally characterizes the amnesia problem, describes the full architecture with equations and a system diagram, and positions Phoenix V2 against Mem0, MemGPT/Letta, Zep, and Generative Agents. The book explains every design decision in detail, chapter by chapter, alongside this codebase.
Phoenix V2 is a local-first AI assistant with a persistent cognitive architecture. It does not rely on the LLM to maintain memory, identity, or emotional state β those live in a local SQLite database and survive any model swap, restart, or conversation reset.
This repository contains the complete, working source code described chapter by chapter in the book. Every file you see here is explained in detail in the text.
| Concept | What It Means in Phoenix |
|---|---|
| Persistent Memory | Conversations are stored in SQLite and retrieved by semantic similarity across sessions |
| Multi-Agent Pipeline | Five specialized agents (Memory β Planning β Action β Reflection β Personality) process each input in sequence |
| Blackboard Architecture | Agents communicate through a shared in-memory workspace β no direct coupling between them |
| Emotion Engine | PAD model (Pleasure-Arousal-Dominance) tracks emotional state continuously based on interaction history |
| Daydream Engine | Background process that generates reflective thoughts when Phoenix is idle |
| Subconscious Cycle | Runs during rest periods to consolidate memories and update beliefs |
| RLHF Feedback | User feedback (+/β) is captured and applied to an internal reinforcement scoring system |
User Input
β
βΌ
[ server.ts β Express API Gateway ]
β
βΌ
[ brain.ts β Central Orchestrator ]
β
ββββΆ [ MemoryAgent ] β retrieves relevant past context
ββββΆ [ PlanningAgent ] β generates a raw response draft
ββββΆ [ ActionAgent ] β decides if a real-world tool is needed
ββββΆ [ ReflectionAgent ] β reviews the draft for coherence and safety
ββββΆ [ PersonalityAgent ]β applies Phoenix's voice to the final output
β
βΌ
[ Blackboard ] ββββ shared working memory (volatile, per-request)
β
βΌ
[ EmotionEngine ] β updates PAD state after every interaction
β
βΌ
[ SQLite Database ] β persists memories, emotional state, self-model
β
βββββββββββ΄βββββββββββ
β β
[ DaydreamEngine ] [ SubconsciousEngine ]
(idle background) (rest-cycle processing)
Full architecture diagram with all connections: docs/architecture.md
phoenix-v2/
β
βββ server.ts β Express server + API routes
βββ src/
β βββ App.tsx β React frontend (chat UI)
β βββ main.tsx
β βββ server/
β βββ config/
β β βββ settings.ts β Environment variables
β βββ core/
β β βββ brain.ts β Central orchestrator (Ch. 5)
β β βββ blackboard.ts β Shared working memory (Ch. 4)
β β βββ consolidation.ts β Memory consolidation engine (Ch. 12)
β β βββ backup.ts β Data export
β β βββ agents/
β β β βββ base_agent.ts β Abstract base class (Ch. 6)
β β β βββ memory_agent.ts β Memory retrieval (Ch. 6)
β β β βββ planning_agent.ts β Response drafting (Ch. 7)
β β β βββ action_agent.ts β Tool routing (Ch. 8)
β β β βββ reflection_agent.ts β Draft validation (Ch. 9)
β β β βββ personality_agent.tsβ Voice and persona (Ch. 10)
β β βββ dreams/
β β β βββ daydream_engine.ts β Idle background process (Ch. 15)
β β βββ evolution/
β β βββ reinforcement.ts β RLHF scoring (Ch. 17)
β β βββ incremental_learn.tsβ Pattern learning (Ch. 18)
β βββ memory/
β β βββ memory_manager.ts β Retrieval with semantic + priority scoring (Ch. 11)
β β βββ storage.ts β SQLite persistence layer (Ch. 11)
β β βββ priority.ts β Recency Γ importance scoring (Ch. 11)
β βββ psychology/
β β βββ self_model.ts β Identity, traits, beliefs, goals (Ch. 16)
β β βββ emotion.ts β PAD emotion engine (Ch. 14)
β β βββ subconscious.ts β Rest-cycle processing (Ch. 15)
β βββ scheduler/
β β βββ cron_tasks.ts β Timed tasks (Ch. 21)
β β βββ background_jobs.ts β Batch processing (Ch. 21)
β βββ tools/
β β βββ tool_registry.ts β Tool definitions for ActionAgent (Ch. 8)
β βββ users/
β β βββ profile_manager.ts β Multi-user identity management (Ch. 23)
β βββ utils/
β βββ llm_client.ts β Gemini API wrapper (Ch. 19)
β βββ embeddings.ts β Vector embedding client (Ch. 11)
β βββ filters.ts β Output formatting helpers
β
βββ docs/
β βββ architecture.md β Full architecture diagram
β βββ chapter-map.md β Which file = which chapter
β βββ SETUP.md β Detailed setup guide (all OS)
β
βββ .env.example β Copy this to .env and add your API key
βββ .gitignore
βββ package.json
βββ tsconfig.json
βββ vite.config.ts
Prerequisites: Node.js 18 or higher Β· A free Gemini API key
git clone https://github.com/cleversonbrsantos-art/Phoenix.git
cd Phoenix
npm install
cp .env.example .env
npm run dev
For detailed setup instructions by operating system (Windows, Linux, macOS), see docs/SETUP.md.
- Go to https://aistudio.google.com/apikey
- Sign in with a Google account
- Click Create API key
- Copy the key into your
.envfile:
GEMINI_API_KEY="paste-your-key-here"
The free tier is sufficient to run Phoenix V2 for personal use.
The system starts four parallel processes:
- Express server on port 3000 β serves the React UI and handles API calls
- Vite dev server β compiles and hot-reloads the frontend
- SubconsciousEngine β starts a background loop that runs memory consolidation every 5 minutes
- DaydreamEngine β watches for idle periods and generates reflective thoughts after 2 minutes of inactivity
The SQLite database is created automatically at .data/vault/phoenix_neural_db.sqlite on first run. All memories, emotional state, and the self-model are persisted there across restarts.
This codebase maps directly to the book's structure:
| Book Part | Chapters | Primary Files |
|---|---|---|
| Foundations | 1β4 | blackboard.ts , project setup |
| Cognitive Core | 5β10 | brain.ts , all agents |
| Persistence | 11β13 | memory/ ,consolidation.ts |
| Psychology | 14β16 | emotion.ts ,subconscious.ts ,self_model.ts |
| Learning | 17β18 | reinforcement.ts ,incremental_learn.ts |
| Integration | 19β21 | server.ts ,App.tsx ,scheduler/ |
| Advanced | 22β25 | users/ , deployment, observability |
For the complete file-to-chapter mapping: docs/chapter-map.md
This is the book version of Phoenix β the version described in the text, built on modest hardware (Intel Core i3, 8 GB RAM), without a GPU or cloud infrastructure.
It is intentionally designed to run on any modern laptop. It is not production-hardened, does not include authentication, and is not intended for multi-user deployment as-is.
The architecture, however, is built to evolve. Chapters 23 and 25 discuss how to extend it.
MIT β see LICENSE for details.
Cleverson Santos β Commercial Manager, Sinop, Brazil.
Architect of Phoenix. No formal programming background. Built this iteratively using Claude as a cognitive collaborator.
- π Paper:doi.org/10.5281/zenodo.22645361
- π Book:Building Persistent AI on Leanpub
- πΌ LinkedIn:linkedin.com/in/cleverson-santos
"The LLM is an external consultant, never the cognitive engine. Identity, memory, and personality live locally β and survive any model swap."