Relational Memory for LLMs: Three-Layer System Models User Relationships

Relational Memory is a 500-line Python prototype that adds relationship-aware memory to LLMs like Claude Opus and GPT-4o. Instead of storing facts about users, it models the relationship itself across seven psychological dimensions derived from established models.
How It Works
After each session, a secondary LLM (Claude Haiku) analyzes the full conversation and scores the relationship on seven dimensions: formality, warmth, humor, depth, trust, energy, and resilience. The system uses exponential moving average (EMA) for updates, giving more weight to recent sessions while maintaining historical context.
Three-Layer Memory Structure
Every five sessions, a "sleep-time agent" consolidates memory into three narrative layers:
- Base Tone: A portrait of who the user is (lifespan: months)
- Patterns: Behavioral if-then rules like "when AI gets shallow, user pushes back with sharper questions" (lifespan: weeks)
- Anchors: Turning points that shaped the relationship (long-term retention)
Memory files are stored as plain markdown that users can read directly. The system intentionally forgets patterns not supported by recent data to prevent illusion of perfect recall.
Key Feature: Resilience Dimension
Resilience tracks how much honest friction the relationship can handle. With high resilience, the AI pushes back when it disagrees. With low resilience, it frames challenges as questions. This allows the AI to know not just user preferences, but whether they can handle being told they're wrong.
Practical Implementation
Installation and setup:
pip install git+https://github.com/spectator81-png/relational-memory.git
export ANTHROPIC_API_KEY=sk-ant-...
relational-memory --mode flat # for A/B comparison
relational-memory --provider openai # for GPT-4o
The tool supports both Anthropic and OpenAI APIs with no dependencies beyond their respective SDKs. It's been tested with one person over seven sessions, showing noticeable differences in AI responses between memory-enabled and memory-disabled modes.
Example Responses
Without relational memory, when a user says "I feel lost. Lots of ideas, don't know which is worth pursuing," the AI responds with generic advice about writing ideas down and picking the one with least resistance.
With relational memory enabled, the AI responds: "I know that about you. You don't think in small categories. But 'which one is worth it' might be the wrong question. Which idea won't leave you alone at night?"
The seven relationship dimensions were derived from six established psychological models: Interpersonal Circumplex, PRQC, Russell Circumplex, and others. Four dimensions come directly from existing literature, one was adapted for human-AI context, and two are novel.
📖 Read the full source: r/ClaudeAI
👀 See Also

0Latency: A Persistent Memory Layer for AI Agents via MCP
0Latency is an MCP server that adds persistent memory to Claude and other AI agents, storing memories across sessions to prevent context loss. It works natively with Claude Desktop, Claude Code, claude.ai, GPT, Gemini, Cursor, and any MCP-compatible agent.

Chapper: Native iOS Client for LM Studio, Ollama, and OpenAI-Compatible Local Models
Chapper is a native SwiftUI iOS app that connects to LM Studio, Ollama, and OpenAI-compatible local models without cloud services or accounts. It offers real-time token streaming, full sampling controls, reasoning model support with <think> tags, and export in 7 formats.

Quell Proxy Fixes Claude Code Scroll-Jumping on Windows
Quell is a Rust proxy that sits between your terminal and Claude Code, stripping clear-screen sequences that cause scroll position resets during long responses. It also adds Shift+Enter for newlines, security filtering, and full Unicode support.

ClearSpec: A Spec Generator to Reduce Hallucination in Claude Code
ClearSpec is a tool that generates structured specifications from plain English descriptions, connecting to GitHub repos to reference real file paths and dependencies, then uses those specs as prompts for Claude Code to provide better context.