Dreamory: Memory Infrastructure for AI Companions
An async FastAPI backend that keeps a companion chatbot's emotional state and long-term memory outside the model: an LLM call classifies each message into discrete events, a code-only rule table updates a six-mode state machine, and the resulting state is compiled into the prompt every turn. Memory is a three-tier hierarchy on PostgreSQL + pgvector — two HNSW-indexed embeddings per message (content and emotion axes), a time-decayed hot zone of ids, and a token-budgeted context assembler. A bounded tool-calling loop (memory search, grep, timers, notes) forces an answer after 3 rounds and falls back to plain generation on failure, and every model output is schema-validated. Covered by 183 pytest tests that need no database or API key.