- Chapter 0: Why Build This Yourself — p. 22
- Chapter 1: The Amnesia Problem in LLMs — p. 25
- 1.1: Finite Context Windows
- 1.2: High Token Costs
- 1.3: Loss of Identity Between Sessions
- 1.4: Implications and Why This Matters
- Chapter 2: Phoenix V2 - A Different Architecture — p. 36
- 2.1: Philosophy - "LLMs Are Consultancies, Not Brains"
- 2.2: Design Principles
- 2.3: Architectural Overview
- 2.4: What You'll Build in This Book
- Chapter 3: TypeScript Setup & Project Structure — p. 50
- 3.1: Environment Setup
- 3.2: Folder Structure Rationale
- 3.3: First Hello World
- 3.4: Logging System
- Chapter 4: The Blackboard Pattern — p. 67
- 4.1: Pattern Explanation
- 4.2: Implementation of blackboard.ts
- 4.3: Unit Tests
- 4.4: Decoupling and Extensibility
- Chapter 5: The Brain - Central Orchestrator — p. 87
- 5.1: State Machine Design
- 5.2: Agent Instantiation
- 5.3: Cognitive Pipeline (5-Agent)
- 5.4: System Initialization Flow
- 5.5: Error Handling and Recovery
- Chapter 6: Memory Agent - Retrieving the Past — p. 104
- 6.1: Semantic Search via Embeddings
- 6.2: Fact Extraction from User Input
- 6.3: Context Relevance Ranking
- 6.4: Testing Retrieval Accuracy
- Chapter 7: Planning Agent - Generating Ideas — p. 121
- 7.1: Structured LLM Calls
- 7.2: Filtering (Not Mixing Reflections with Plans)
- 7.3: Draft Response Generation
- 7.4: Error Handling and Fallbacks
- Chapter 8: Action Agent - Tools and Real World — p. 139
- 8.1: Tool Registry Architecture
- 8.2: LLM Decision Logic ("Do I Need a Tool?")
- 8.3: Safe Tool Execution
- 8.4: Result Integration
- 8.5: Building Custom Tools
- Chapter 9: Reflection Agent - Validation & Safety — p. 158
- 9.1: Safety Gates Explained
- 9.2: Coherence Checking
- 9.3: Prompt Leak Prevention
- 9.4: Draft Refinement
- Chapter 10: Personality Agent - The Voice of Phoenix — p. 175
- 10.1: Self-Model and Identity
- 10.2: Emotional Tone Application
- 10.3: Rigid Voice Rules (Explained)
- 10.4: Text Filtering (TTS, Thought Markers)
- 10.5: Creating Custom Voices
- Chapter 11: Memory System - Storage Architecture — p. 193
- 11.1: SQLite + JSON Hybrid Approach
- 11.2: Embedding Generation (ONNX)
- 11.3: Semantic Indexing
- 11.4: Top-K Retrieval Algorithms
- 11.5: Database Optimization
- Chapter 12: Consolidation Engine - Neural Night — p. 211
- 12.1: Memory Clustering
- 12.2: Semantic Compaction
- 12.3: Noise Reduction Techniques
- 12.4: Merge Algorithms
- 12.5: Scheduling Consolidation
- Chapter 13: Backup & Export Systems — p. 230
- 13.1: Resilient Persistence
- 13.2: Data Export Formats
- 13.3: Version Control for Memories
- 13.4: Recovery Procedures
- Chapter 14: Emotion Engine - PAD State Model — p. 250
- 14.1: Pleasure-Arousal-Dominance Model
- 14.2: Delta Calculation from Context
- 14.3: Decay and Baseline Mechanisms
- 14.4: Emotional State Persistence
- 14.5: Mapping PAD to Labels
- Chapter 15: Subconscious Engine - Dreams & Reflections — p. 270
- 15.1: Background Processing Explained
- 15.2: Sleep Cycle Scheduling
- 15.3: Insight Generation from Real Data
- 15.4: Self-Model Updates
- 15.5: Pattern Detection
- Chapter 16: Self-Model - "Who Do I Think I Am?" — p. 294
- 16.1: Beliefs and Traits Data Structure
- 16.2: Confidence Weights and Evolution
- 16.3: Continuous Self-Refinement
- 16.4: Prompt Context Generation
- 16.5: Self-Consistency Checking
- Chapter 17: Reinforcement Learning - Implicit Feedback — p. 316
- 17.1: Feedback Extraction from Inputs
- 17.2: RLHF Buttons and Scoring
- 17.3: Confidence Adjustment
- 17.4: Pattern Reinforcement
- Chapter 18: Incremental Learning - Emergent Patterns — p. 338
- 18.1: Interaction Analysis
- 18.2: Preference Detection
- 18.3: Dynamic Model Updates
- 18.4: Evolution Without Retraining
- Chapter 19: API Gateway - Express.js Server — p. 359
- 19.1: REST Endpoints Design
- 19.2: Multi-User Authentication
- 19.3: Rate Limiting
- 19.4: Request/Response Flow
- 19.5: Error Handling
- Chapter 20: Frontend - React Interactive Terminal — p. 384
- 20.1: Chat Terminal UI
- 20.2: Text-to-Speech Integration
- 20.3: Neural Vault (Memory Visualizer)
- 20.4: System Status Monitor
- 20.5: RLHF Feedback Buttons
- Chapter 21: Scheduler & Background Jobs — p. 407
- 21.1: Cron Tasks Architecture
- 21.2: Periodic Maintenance
- 21.3: Health Checks and Monitoring
- 21.4: Job Coordination
- Chapter 22: Debugging & Observability — p. 433
- 22.1: Structured Logging
- 22.2: Interaction Tracing
- 22.3: Performance Profiling
- 22.4: Alerting and Monitoring
- Chapter 23: Scalability & Multi-User Systems — p. 459
- 23.1: Context Isolation
- 23.2: Memory Sharding
- 23.3: Caching Strategies
- 23.4: Connection Pooling
- Chapter 24: Production Deployment — p. 479
- 24.1: Docker Containerization
- 24.2: Environment Configuration
- 24.3: Database Migration
- 24.4: Zero-Downtime Updates
- Chapter 25: Beyond Phoenix - Extensibility — p. 501
- 25.1: Building Custom Agents
- 25.2: Custom Embedding Models
- 25.3: Multi-LLM Routing
- 25.4: External System Integration
- 25.5: Community Contributions
- Appendix A: TypeScript Best Practices — p. 524
- A.1: Type Safety Patterns
- A.2: Async/Await Pitfalls
- A.3: Testing Strategies
- Appendix B: Complete Reference Architecture — p. 536
- B.1: System Architecture Overview
- B.2: Cognitive Pipeline Data Flow
- B.3: Memory System Data Flow
- B.4: Full Dependency Graph
- B.5: Deployment Architecture
- B.6: API Structure
- B.7: System Interactions
- Appendix C: Concepts Glossary — p. 549
- Appendix D: Troubleshooting Guide — p. 574
- D.1: Common Runtime Errors
- D.2: Performance Issues
- D.3: Memory Management
- D.4: Database Issues
- D.5: API & Network Issues
- D.6: Deployment Issues
- D.7: Data Consistency Issues
- D.8: Testing Issues
- Appendix E: Bibliography — p. 595
- Appendix F: Concept Map — Where Ideas Connect — p. 599
- Appendix G: Notes for Educators — p. 601
PHOENIX - BUILDING PERSISTENT AI
Your AI assistant forgets you every time the session ends. Building Persistent AI shows you how to fix that — by moving memory, personality, and identity out of the model and into a file you own and control.
Minimum price
$49.90
$59.90
You pay
Author earns
About
About the Book
Every conversation with a language model ends the same way: it forgets you. Not gradually, not partially — completely. This book builds a system that does not forget.
Building Persistent AI teaches you to design and implement Phoenix V2, a complete cognitive architecture that decouples persistent intelligence from the reasoning engine. Memory, affective state, and identity live in a local SQLite file you own — not in the model. When the provider updates, reprices, or retires a model, your assistant's memory and personality survive.
You will build five specialized agents coordinated by a Blackboard orchestrator, a semantic memory system with embedding-based retrieval, a Pleasure–Arousal–Dominance emotion engine that persists across sessions, a SubconsciousEngine that consolidates and reflects during idle cycles, and an incremental learning layer that adapts to you without retraining.
The stack is TypeScript on Node.js. No GPU required. The entire system was developed and runs on a 2008-era notebook. The companion paper is available open access at https://doi.org/10.5281/zenodo.22645361
Feedback
Author
About the Author
Cleverson Santos is a Commercial Manager based in Sinop, Brazil, transitioning into AI development without a formal computer science background. He built Phoenix V2 entirely on a 2008-era notebook with 6 GB of RAM — not because better hardware was unavailable, but because he believed that persistent, emotionally-aware AI assistance should be within reach of anyone with a personal computer.
He wrote this book for the same reason he built the system: because the documentation he needed did not exist. Every concept in these pages was earned through trial, failure, and iteration — not distilled from a research lab or a graduate program. The result is a practitioner's account of what it actually takes to build something that remembers you, learns from you, and belongs to you.
The companion technical paper is published open access at https://doi.org/10.5281/zenodo.22645361
Contents
Table of Contents
Get the free sample chapters
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Write and Publish on Leanpub
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.