GAPMem: Boundary-First Graph-Constrained Memory for Personalized Agents

GAPMem (arXiv:2612.05422) is a boundary-first, graph-constrained memory framework that prevents personalized LLM agents from over-generalizing user preferences across unrelated contexts. By separating explicit dialogue preferences from inferred tendencies and gating activation via typed graph scope relations, scenario-aware retrieval reaches 0.8235 F1 (0.8163 paired F1) with 0.0000 contradiction and scene-contamination rates.
GAPMem: Boundary-First Graph-Constrained Memory for Personalized Agents: GAPMem (arXiv:2612.05422) is a boundary-first, graph-constrained memory framework that prevents personalized LLM agents from over-generalizing user preferences across unrelated contexts. By separating explicit dialogue preferences from inferred tendencies and gating activation via typed graph scope relations, scenario-aware retrieval reaches 0.8235 F1 (0.8163 paired F1) with 0.0000 contradiction and scene-contamination rates. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.
- Boundary-First Admission Filtering: Evaluates contextual applicability, exclusions, and evidence sufficiency before ranking or injecting preferences.
- Zero Scene Contamination in Exploratory Trials: Achieves 0.0000 contradiction rate and 0.0000 scene-contamination rate across CUPID diagnostic cases.
- 0.8235 Retrieval F1 vs 0.0000–0.4667 Baselines: Scenario-aware preference retrieval lifts paired F1 to 0.8163 (+0.8163 over raw vector memory).
- Distinguishes Explicit vs Implicit Memory: Separates direct user rules from consolidated behavioral inferences with traceable source edges.
import { createAgent } from '@smoke-monkey/harness';// Enforce scenario-bounded preference retrieval before prompt injectionconst agent = createAgent({agentId: 'gapmem-personalized-agent',provider: 'openai-compatible',baseUrl: 'http://127.0.0.1:8000/v1',model: 'Qwen/Qwen3-8B',workspacePath: process.cwd(),permissions: {read_file: 'allow',write_file: 'ask',run_command: 'ask',},});async function main() {const result = await agent.run('Resolve user formatting preferences only where scenario="typescript-cli" and exclude preferences bound to "markdown-blog", citing source evidence IDs.');console.log('Scoped Memory Output:', result.summary);}main().catch(console.error);
Watch: Related Video Guides
Agent Memory EXPLAINED - Complete Architecture
You Can Learn AI Agent Memory Layers | Graph RAG, Vector DB, SQLite, Hermes, Waku
What Is GAPMem and Why Do Vector Memories Leak Across Scenarios?
GAPMem (arXiv:2612.05422) is a boundary-first, graph-constrained preference memory framework designed for personalized LLM agents. Instead of storing flat text chunks in a vector database, GAPMem models each preference as a 9-tuple $p = (c, s, r, v, \tau, \pi, \sigma, o, E)$ capturing category, subject, relation, value, time validity, provenance, scenario scope, override priority, and source evidence.
Conventional RAG memory fails on personalization for three reasons: it treats one-off requests as permanent rules, blurs explicit instructions with weak guesses, and leaks preferences from one domain (such as casual travel chat) into an incompatible scenario (such as formal financial reporting). GAPMem enforces an evidence sufficiency gate $\operatorname{Suff}(p) = \mathbb{I}[\operatorname{Rep}(E_p) \ge \theta_r \land \operatorname{Cons}(E_p) \ge \theta_c \land \operatorname{Alt}(E_p) \le \theta_a]$ and filters graph boundaries before ranking. In exploratory CUPID evaluations:
| Retrieval Configuration | Diagnostic Strict Coverage | Paired Strict Coverage | Paired F1 | F1 Gain vs Raw Memory | Contradiction / Contamination Rate |
|---|---|---|---|---|---|
| Raw Memory | 0.3333 | 0.0000 | 0.0000 | +0.0000 | 0.0000 / 0.0000 |
| Raw Memory + Scenario-Aware | 0.5000 | 0.2500 | 0.2000 | +0.2000 | 0.0000 / 0.0000 |
| Evidence-Based Preference | 1.0000 | 1.0000 | 0.6667 | +0.6667 | 0.0000 / 0.0000 |
| Scenario-Aware Preference | 0.8889 | 0.8333 | 0.8163 (0.8235 overall) | +0.8163 | 0.0000 / 0.0000 |
Enforcing Boundary-First Preference Filtering in Agent Memory Stores
Notice an important nuance in the authors' findings: raw vector memory improved from 0.3333 to 0.4667 F1 when adding scenario-aware filtering, yet still trailed structured graph-constrained preference retrieval (0.8235 F1). Note that the paper explicitly scopes these results as an exploratory 3-case CUPID retrieval study with model-based judgments rather than an end-to-end production guarantee.
In a TypeScript or Python MCP memory server, you can enforce GAPMem's pre-activation boundary check before vector similarity ranking runs:
def filter_preferences(prefs: list[dict], active_scenario: str) -> list[dict]:
"""Apply GAPMem boundary-first filtering prior to similarity ranking."""
valid = []
for p in prefs:
if active_scenario in p.get("exclusions", []):
continue
if p.get("scope") and active_scenario not in p["scope"]:
continue
if p.get("evidence_count", 0) < 1 or p.get("superseded_by"):
continue
valid.append(p)
return sorted(valid, key=lambda x: (x["explicit"], x["confidence"]), reverse=True)Respect Exploratory Study Scope
GAPMem arXiv:2612.05422 reports descriptive metrics on 3 CUPID cases; treat its graph schema and boundary-first gating as an architectural blueprint and validate recall on your own agent telemetry.
Frequently Asked Questions
Q:What does boundary-first mean in GAPMem?
Boundary-first means checking scenario applicability, explicit exclusions, conflict edges, and source evidence sufficiency before activating or ranking a preference memory for prompt injection.
Q:How does GAPMem compare to raw vector memory retrieval?
In the CUPID retrieval study, scenario-aware preference retrieval achieved 0.8235 F1 overall (0.8163 paired F1) and evidence-based retrieval hit 1.0000 strict checklist coverage, compared to 0.0000 paired F1 for raw memory.
Q:How does GAPMem distinguish explicit from implicit preferences?
Explicit preferences come directly from user dialogue statements, whereas implicit preferences are consolidated from repeated behavioral evidence and require passing repetition, consistency, and alternative-explanation thresholds.
Q:Can I enforce GAPMem boundaries in an MCP memory server?
Yes. Filter out excluded scenarios, superseded nodes, and unverified memories in SQLite or Neo4j before executing cosine-similarity ranking over candidate entries.
Related Alternatives & Comparisons
Related Architecture Guides
View all guidesBest Open Source Coding Agents in 2026: Free, Local & Fully Hackable Harnesses
MCP Server Security Best Practices: Hardening Model Context Protocol Agents in 2026
Open Source Coding Agent Harness: Build a Forkable, Local AI Engineering Runtime
Build with Smoke Monkey Harness
Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.