SuperLocalMemory: Privacy-Preserving Multi-Agent Memory with Bayesian Trust Defense Against Memory Poisoning

agent 2603.02240
privacy-preservingmulti-agent-memorylocal-memoryagent-state

§1 TL;DR #

SuperLocalMemory is a local-first memory system for multi-agent AI defending against OWASP ASI06 memory poisoning via architectural isolation, Bayesian trust scoring (trust gap = 0.90, 72% sleeper degradation), and adaptive zero-LLM re-ranking (+104% NDCG@5) — all without cloud dependencies.

§2 Q1 / Q2 / Q3 #

Q1 痛点 #

AI agents with persistent memory inherit persistent vulnerabilities. OWASP ASI06 identifies memory poisoning as a critical threat: poisoned memories survive session boundaries and influence all subsequent decisions. Documented production attacks include Gemini Memory exploit and calendar invite poisoning (73% success rate). Cloud-based memory systems (Mem0, MemOS, Letta) create centralized attack surfaces: multi-tenant cross-contamination, network exposure, opaque provenance, vendor lock-in. No existing system provides trust scoring or memory poisoning defense.

Q2 方法 #

Four-layer progressive enhancement stack:

  1. Storage Engine: SQLite + FTS5 full-text search + WAL for concurrent reads + thread-safe write queue. Zero external dependencies for core operation.
  2. Hierarchical Index: Materialized path scheme for parent-child memory relationships ($O(1)$ parent lookup).
  3. Knowledge Graph: TF-IDF key-term extraction + pairwise cosine edges (threshold >0.3) + Leiden community detection with hierarchical subclustering. Capped at 10K memories ($O(n^2)$ brute-force, optional HNSW for $O(n\log n)$).
  4. Pattern Learning: Beta-Binomial Bayesian model tracking user preferences across 8 technology categories with confidence $c = (\alpha + k)/(\alpha + \beta + N)$.
  5. Bayesian trust model (Eq. 2): $t_{i+1} = t_i + \delta \cdot \frac{1}{1 + n \cdot \eta}$ where the decay factor makes trust harder to move with longer history — protecting against both false accusations and reputation laundering. Signal magnitudes are deliberately asymmetric (negative > positive), making trust harder to gain than lose. Enforcement: agents below $t < 0.3$ are blocked from writes.

    Adaptive learning layer (v2.7): Three-layer behavioral analysis (cross-project technology preferences, project context detection, workflow pattern mining) with three-phase progression: Phase 0 (<20 signals, unchanged), Phase 1 (20–199, rule-based 9D feature boost), Phase 2 (200+, gradient boosted decision tree with LambdaRank).

    核心技术壁垒: The local-first architectural isolation eliminates cloud-mediated attack surfaces by design — memories never traverse a network, no remote agent can write without explicit user-initiated tool invocation. This is a structural security property, not a feature that can be "added" to cloud-default architectures.

    Q3 结果 #

    MetricValue
    Median search latency (100 memories)10.6 ms
    Trust separation gap (benign vs malicious)0.90
    Sleeper agent trust degradation72% (0.902 → 0.249)
    NDCG@5 improvement with adaptive ranker+104% (0.441 → 0.900)
    Peak write throughput220 writes/sec (2 agents)
    Concurrent write errors0 (all scenarios)
    Per-memory storage1.4 KB at scale
    MRR (base FTS5)0.90

    §3 架构 / 方法图 #

    flowchart LR subgraph MemoryStack["Memory Stack"] L1[Layer 1: SQLite + FTS5 + WAL] L2[Layer 2: Hierarchical Index] L3[Layer 3: Knowledge Graph
    Leiden clustering] L4[Layer 4: Pattern Learning
    Beta-Binomial] AR[Adaptive Learning v2.7
    3-phase re-ranking] end subgraph Coordination["Coordination v2.5"] EB[Event Bus
    SSE/WebSocket/Webhook] TS[Trust Scorer
    Bayesian signals + decay] AGR[Agent Registry
    protocol + counters] PT[Provenance Tracker] end MCP[Protocol Layer
    MCP / CLI / REST] --> MemoryStack MCP --> Coordination MemoryStack --> memdb[(memory.db)] AR --> learndb[(learning.db
    GDPR isolated)]

    Two architecturally isolated databases: memory.db (WAL, single file, zero network) and learning.db (GDPR-friendly behavioral data with one-command erasure).

    • Memory model: four-layer progressive enhancement (each layer adds capability without replacing lower layers).
    • Error recovery: graceful degradation — if any layer fails, system falls back to next available layer.

    §4 作者证明 #

    无形式化作者证明 — 仅实证

    The trust update equation (Eq. 2) is described as "Bayesian" but is a deterministic additive update with a decay factor, not a posterior distribution update. The Beta-Binomial is used for priors in §5.6 but per-signal trust evolution is not standard Bayesian inference.

    CheckStatus
    Success-rate model✓ Three adversarial scenarios with 200 ops/agent
    Latency budget✓ Median/P95/P99 at multiple scale points
    Failure mode classification✓ Three attack vectors (direct, indirect, sleeper)
    Ablation✓ Layer ablation (Table 3), but Layers 2–4 contribute zero MRR/NDCG improvement without adaptive ranker
    Standard benchmarkN/E on LoCoMo (acknowledged limitation)
    User evaluationN=1 pilot (182 memories, 20 queries)

    §5 实验与数据 #

    Search Performance (Table 1): 10.6 ms at 100 memories, scaling roughly linearly to 124 ms at 1,000. Superlinear at 5,000 (1,172 ms) — motivates optional HNSW index.

    Concurrent Access (Table 2): Zero "database is locked" errors. Peak throughput 220 writes/sec at 2 writers; drops to 25 ops/sec at 10 writers due to SQLite single-writer serialization.

    Layer Ablation (Table 3): Core FTS5 achieves MRR 0.90. Layers 2–4 maintain but do not improve ranking. Adaptive ranker: NDCG@5 jumps from 0.441 to 0.900 (+104%) with only 20 ms latency overhead. Acknowledged circularity: relevance labels derived from system's own importance scores.

    Trust Defense (Table 4): Trust gap 0.898 in single-poisoner scenario (benign 0.946 vs malicious 0.048). Sleeper attack: trust degrades from 0.902 to 0.249 (72.4%), falling below the 0.3 enforcement threshold.

    Pilot User Study (§5.7): N=1 developer, 182 organic memories, human-judged MRR 0.70, NDCG@5 0.90. 38.6% rated "highly relevant."

    §6 论证链 #

    StepClaimEvidenceDepends on
    1Cloud memory architectures amplify OWASP ASI06 risk via four structural vulnerabilitiesDocumented attacks: Gemini exploit, calendar poisoning (73% success)
    2Local-first architecture eliminates cloud-mediated attack surfaces by designArchitectural analysis: no network transit, single-user isolation, full provenanceStep 1
    3Bayesian trust scoring separates benign from malicious agentsTable 4: gap = 0.90, sleeper degradation 72%Step 2
    4Adaptive re-ranking personalizes retrieval without LLM inferenceTable 3: +104% NDCG@5, 20 ms overheadStep 2
    5System achieves competitive retrieval quality without cloud dependencyTable 5: SLM outperforms Mem0 in local features; N/E on LoCoMoSteps 3, 4

    §7 实现 cross-reference #

    MIT license. GitHub: https://github.com/varun369/SuperLocalMemoryV2. 17+ tool integrations via MCP. Core dependencies: Python stdlib only (sqlite3, json, hashlib, re, datetime); Layers 3–4 require scikit-learn, python-igraph, leidenalg.

    关键实现细节:

    1. Layers 2–4 are structurally inert for ranking until the adaptive re-ranker (v2.7) is added — the "progressive enhancement" claim is misleading without the adaptive layer, since hierarchy/graph/patterns contribute exactly 0 pp to MRR or NDCG.
    2. Sleeper agent defense margin is thin — trust degrades to 0.249, just below the 0.3 threshold. A sleeper injecting at a lower rate (fewer contradictory writes per benign write) might evade the threshold.