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

BaseLayer: Open-Source Behavioral Compression Pipeline for AI Memory Systems
BaseLayer is an open-source pipeline that extracts beliefs, behaviors, tensions, and contradictions from conversations, journals, and published text, compressing them into an identity brief for AI models. It has been tested on datasets ranging from 8 personal journal entries to large corpora like Warren Buffett's shareholder letters (350k words) and Howard Marks' investment memos (600k words).

OpenClaw Smart Router Open-Sourced for Automatic Model Selection
A developer has open-sourced a Smart Router for OpenClaw that automatically classifies queries by complexity and routes them to optimal models, saving 60-80% on API costs compared to always using premium models like Claude or GPT-4o.

TOON MCP server reduces tool result tokens by 30-60% in OpenClaw
An MCP server that compresses structured JSON tool results into the TOON format can cut token usage by 30-60% for tabular data like database queries and API responses, helping delay context window compaction in OpenClaw sessions.

Skill Studio: Open-Source Desktop App for Managing Claude AI Agent Skills
Skill Studio is a free, open-source macOS desktop app that lets developers browse community skill repositories, preview documentation with markdown rendering, and install skills with one-click commands like npx skills add.