π δΈζηζ¬ β
EmoMem is a research prototype of a memory-augmented emotional companion agent. Unlike traditional chatbots that treat each conversation turn as independent, EmoMem builds a persistent, structured understanding of the user's emotional world β remembering past emotional episodes, learning what support strategies work for each individual, and tracking the user's long-term emotional recovery trajectory.
The system follows a Perception β Planning β Action β Memory (PPAM) architecture, where memory is not a passive log but the central engine that drives all other modules.
Most dialogue systems forget the user between sessions. EmoMem introduces a dedicated Affective Memory Tier that persists across conversations and stores:
| Component | What it tracks |
|---|---|
| Emotion Baseline | The user's typical emotional state (mean + variance per emotion dimension) |
| TriggerβEmotion Map | Which types of events (work, relationships, healthβ¦) are linked to which emotions for this user |
| Recovery Curve | How quickly this user typically bounces back from negative episodes |
| Strategy Effectiveness | Which support strategies (validation, advice, reframingβ¦) have worked well in the past |
This turns EmoMem from a stateless responder into an agent that knows the user β and adapts its behavior accordingly.
When retrieving past memories to inform a response, a naive system would always retrieve by recency or semantic similarity. EmoMem instead uses MAR, which dynamically adjusts retrieval weights based on the current emotional context and the planner's goal:
- Emotional validation goal β retrieve episodes where the user felt similar emotions (mood-congruent retrieval, grounded in Bower's 1981 mood-state-dependent memory theory)
- Recovery goal β retrieve episodes where the user successfully overcame similar difficulties (mood-incongruent / uplifting retrieval)
- Crisis assessment goal β retrieve behavioral pattern deviations from the affective baseline
The retrieval weight function:
where
EmoMem learns which support strategy works best for this specific user through a Contextual Bandit formulation:
- Action space: 9 support strategies drawn from Hill's (2009) Helping Skills Theory β Active Listening, Emotional Validation, Cognitive Reframing, Problem Solving, Psychoeducation, and more
- Context features: emotion type, urgency level, recovery phase, relationship depth, user intent
- Learning mechanism: Thompson Sampling with per-strategy Beta distributions, stratified by context cluster β balancing exploration (trying new strategies) with exploitation (using what has worked)
This moves EmoMem from generic empathy to personalized support β the same user asking "I'm feeling lost" on day 1 vs. day 30 will receive qualitatively different responses because the agent has learned their preferences.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β EmoMem PPAM Architecture β
β β
β User Input β
β β β
β βΌ β
β ββββββββββββ StateVector ββββββββββββββββββββββββββββ β
β βPERCEPTIONβ ββββββββββββββ β MEMORY β β
β β β MemoryQuery β ββββββββββββββββββββββ β β
β β β’ Emotionβ ββββββββββββββ β β Working Memory β β β
β β Radar β β β Episodic Memory β β β
β β β’ Intent β β β Affective Tier β
β β β
β β β’ Urgencyβ β β Semantic Memory β β β
β ββββββββββββ β ββββββββββββββββββββββ β β
β ββββββββββ¬ββββββββββββββββββ β
β RetrievedContextβ GroundingFacts β
β βΌ β
β ββββββββββββββββ β
β β PLANNING β β
β β β’ Trajectory β β
β β Modeling β β
β β β’ Thompson β β
β β Sampling β
β β
β ββββββββ¬ββββββββ β
β StrategyPlan β β
β βΌ β
β ββββββββββββββββ β
β β ACTION β β Response β
β ββββββββ¬ββββββββ β
β EpisodeRecordβ(async) β
β βΌ β
β Feedback β Memory Update β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β = core innovations unique to EmoMem
EmoMem uses the Plutchik 8-dimensional emotion model rather than simple positive/negative classification:
joy Β· trust Β· fear Β· surprise Β· sadness Β· disgust Β· anger Β· anticipation
Each turn produces an EmotionVector:
- e(t) β probability distribution over 8 emotions (sums to 1)
- ΞΉ(t) β overall intensity [0, 1]
- ΞΊ(t) β recognition confidence [0, 1] β when low, the agent asks clarifying questions instead of assuming the user's emotional state
Scalar valence is computed as a weighted sum, tracking the user's emotional trajectory over time.
EmoMem models the user's emotional arc across four phases:
Trough β Recovery β Consolidation β Stable
The planner selects different strategies depending on the current phase β in the Trough phase it prioritizes validation and safety; in the Consolidation phase it reinforces positive coping patterns.
emomem_v1/
βββ src/
β βββ main.py # EmoMemAgent β top-level orchestrator
β βββ perception.py # Emotion recognition, intent classification, urgency scoring
β βββ memory.py # 4-tier memory: working / episodic / affective / semantic
β βββ planning.py # Recovery trajectory + Thompson Sampling strategy selection
β βββ action.py # Response generation with memory grounding
β βββ adaptation.py # Feedback processing & online learning
β βββ models.py # Core data models (StateVector, EpisodeRecord, etc.)
β βββ llm_provider.py # Multi-backend LLM abstraction layer
β βββ mock_llm.py # Rule-based fallback (no API key required)
β βββ config.py # All system parameters in one place
βββ web/
β βββ index.html # Chat UI with real-time state visualization
β βββ server.py # Flask REST API server
βββ tests/
β βββ test_unit.py # Unit tests for individual modules
β βββ test_integration.py # End-to-end pipeline tests
β βββ test_emotion.py # Emotion model correctness
β βββ test_crisis.py # Crisis detection & safety protocol
β βββ llm_judge.py # LLM-as-judge evaluation framework
βββ docs/
βββ screenshot.png
pip install flask flask-cors anthropic openaiEmoMem supports multiple LLM backends. Set one of the following:
Option A β Volcengine ARK (Doubao Seed):
export OPENAI_API_KEY=your_ark_api_key
export OPENAI_BASE_URL=https://ark.cn-beijing.volces.com/api/v3/Option B β Anthropic Claude:
export ANTHROPIC_API_KEY=your_anthropic_keyOption C β No API key (Mock mode): The system automatically falls back to a rule-based mock provider. All features work; responses are template-based.
In
src/llm_provider.py, replace"please enter your token"in_ARK_API_KEYSwith your own key, or use environment variables instead.
cd emomem_v1
python -m web.server
# Open http://127.0.0.1:8080pytest tests/
# Or with verbose output:
pytest tests/ -vThe interface provides a real-time view of the agent's internal state:
| Panel | Description |
|---|---|
| Emotion Radar | Live 8-axis Plutchik visualization |
| Valence Index | Continuous emotional valence score (β1 to +1) |
| Urgency Gauge | Crisis risk score; triggers safety protocol at 0.9 |
| Intent Distribution | Top-3 detected user intents with probabilities |
| Recovery Timeline | Current phase in the 4-stage recovery model |
| Ablation Study | Toggle Affective Memory / MAR / Thompson Sampling on/off |
| LLM Shadow Mode | Compare LLM-assessed values vs. formula-computed values |
| Strategy History | Log of strategies selected over the session |
| Memory State | Episodic count, archived episodes, baseline confidence |
| Variable | Description | Default |
|---|---|---|
OPENAI_API_KEY |
ARK or OpenAI-compatible key | β |
ANTHROPIC_API_KEY |
Anthropic Claude key | β |
OPENAI_BASE_URL |
Base URL for OpenAI-compatible endpoints | https://ark.cn-beijing.volces.com/api/v3/ |
EMOMEM_LLM_PROVIDER |
anthropic / openai / mock |
auto-detect |
EMOMEM_LLM_MODEL |
Model name override | doubao-seed-2-0-lite-260215 |
EMOMEM_REASONING_EFFORT |
Reasoning depth: off / low / medium / high |
off |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/chat |
Send a message; returns agent response + full state |
| POST | /api/reset |
Reset the session (preserves LLM config) |
| GET | /api/state |
Get current agent state without sending a message |
| GET | /api/status |
System status (LLM mode, model, total turns) |
| GET/POST | /api/config |
Get or update LLM configuration |
| GET/POST | /api/reasoning |
Get or set reasoning effort level |
| POST | /api/demo |
Run a preset demo scenario (work_stress / crisis / recovery) |
| GET/POST | /api/ablation |
Get or toggle ablation study module switches |
EmoMem sits at the intersection of three active research areas:
- AI companion systems β long-term emotional support for loneliness and mental well-being
- Memory-augmented agents β persistent, structured user modeling beyond single-session context windows
- Personalized strategy learning β Bayesian online learning for individual-level support optimization
Key theoretical foundations: Plutchik's Emotion Wheel (2001), Hill's Helping Skills Theory (2009), Bower's Mood-State-Dependent Memory (1981), Gross's Emotion Regulation Process Model (1998), Thompson Sampling (Thompson, 1933), and the PPAM agent architecture (Wang et al., 2024).
MIT
