RFC: Multi-Scope Memory — personal/global/shared scopes with scope-aware retrieval
Motivation
Currently, SLM stores all memories in a flat namespace. When a user runs multiple AI agent profiles (e.g., a team of specialized agents), every agent sees every memory — no distinction between private memories and shared knowledge.
Our use case: a single human user managing multiple agent profiles. Each agent needs:
- Personal memories (shaping agent personality & behavior)
- Global memories (team-wide shared knowledge)
- Point-to-point sharing (visibility between specific agents)
Approach
We implemented a three-tier scope system, tested in production on a fork:
Data Layer
scopecolumn (personal/global) added to 8 core tables:memories,atomic_facts,canonical_entities,kg_nodes,graph_edges,memory_edges,temporal_events,audit_trailshared_withJSON column for point-to-point visibility- Migration M014 handles existing data (defaults to
personal)
Retrieval Layer
- All 7 retrieval channels accept
scopeparameter with scope-aware SQL WHERE clauses - Multi-scope RRF fusion: personal=1.0, global=0.5, shared_with=0.7 (configurable in later commits)
- Cross-agent global recall correctly filtered across all channels
External Interface
- CLI:
slm remember --scope global,slm remember --shared-with agent2 - MCP tools: all store/recall tools accept
scopeandshared_withparameters - Daemon & WorkerPool IPC propagate scope
Current State
- Fully implemented and tested on our fork (~11,000 LOC delta, ~2,000 new test LOC)
- Cleanly merged with upstream v3.4.39, zero conflicts
- Running in production for daily Hermes agent team usage
- Backward compatible: all memories default to
personalscope
Questions Before I Polish for PR
I'd like to check interest before spending time rebasing and splitting commits:
- Is this direction interesting to upstream? Is multi-scope memory anywhere on your roadmap?
- If a PR is welcome, what granularity do you prefer? E.g.:
- A) One comprehensive PR (schema + engine + retrieval + CLI + MCP)
- B) Split into 3 incremental PRs (schema layer → retrieval layer → external interface)
- Regarding Phase 2 & 3 directions (skill-domain tags, global entity resolution), is there overlap or different design preferences?
Totally understand if the timing isn't right or you have your own plans. Happy to keep maintaining on the fork.
Thanks for building SLM — it's a fantastic project!
Note: We followed existing architecture patterns (no breaking changes), full backward compatibility (defaults to personal), and matched the project's test style.
Thank you, @kenyonxu — and not a throwaway thanks. A three-tier scope model, 8 tables migrated, all 7 retrieval channels made scope-aware, scope-weighted RRF fusion, and it's been running in production on your Hermes agent team. That's a serious piece of work — and coming here to check interest before rebasing 11k LOC says a lot about how you operate.
Honest answers to your three questions:
1. Is this interesting / on the roadmap? Yes. Multi-scope memory is a direction I genuinely want SLM to go. The flat namespace is the right default for a single agent, but it breaks down exactly where you hit it: one human, many agent profiles, with a real distinction between "this shapes this agent" and "this is team knowledge." Personal / global / point-to-point shared is the model I'd want too. This isn't a "maybe someday" — it's something I'm actively thinking about implementing.
2. PR granularity. For a delta this size, please don't open it as one PR. Option B — split by layer — and I'd go even finer:
- Schema + migration M014 first, on its own (with the
personaldefault and a backward-compat proof). This is the part I'll scrutinize hardest — it touches everyone's existing DB. - Retrieval layer second (the 7 channels + scope-weighted fusion), on top of the schema.
- External interface last (CLI + MCP + daemon/WorkerPool IPC). A schema/migration PR I can reason about in isolation is worth ten times a 13k-line mega-diff.
3. Phase 2/3 (skill-domain tags, global entity resolution). There's overlap with entity/graph work in flight, so let's align on design before you build those — I'd hate for you to invest in global entity resolution and then collide with something landing upstream.
Here's the honest constraint: SLM moves fast, and I have specific opinions on the schema and the fusion weights. I don't want you to rebase 11k LOC and then have us disagree on shape in review. I'd rather connect with you directly first — walk through the scope model, the migration strategy, and how it sits next to the mesh / shared-memory work — then we scope the PR split together. I'll reach out to coordinate.
Keeping this issue open as the tracking thread for multi-scope memory. Thanks for building on SLM, and for wanting to upstream it rather than just keeping the fork — that's exactly the kind of contribution I want to support well. 🙏
Hey @varun369 thanks for replying!
I will do some homework and see what's best for both of us!
Hey @varun369 — really appreciate the detailed response, and the honesty about constraints. That's exactly the kind of clarity I was hoping for.
A few updates since the RFC, and a concrete proposal:
What's happened since
The scope model has been running in production on a multi-agent Hermes team for about a month now. ~89 commits total across four phases:
- Phase 1: Schema + migration (8 tables,
scope/group_idcolumns, backward-compat: existing data defaults topersonal) - Phase 2: 7-channel scope-aware retrieval + weighted RRF fusion (personal=1.0, shared=0.7, global=0.5)
- Phase 3: MCP tools (scope params on remember/recall, entity list/merge by scope), CLI, WorkerPool IPC
- Phase 2B: Global canonical entities, 48 domain-tag mappings, scope-e2e tests
While waiting to hear back, I launched MSLM (mslm-memory on PyPI/npm) as a downstream distribution — fully rebranded docs, bilingual (zh/en), focused on multi-scope team collaboration. Bottom of every page says "powered by SuperLocalMemory." I built it this way because whether the scope model lands upstream or not, users need a stable package today. If it lands upstream, MSLM becomes a thin distribution layer (branding + Hermes provider + docs). If not, it carries the full delta.
Also submitted two tiny bug-fix PRs from running in production: #24 (WAL busy_timeout order) and #25 (logger.exception for init failure traceback).
Concrete PR split (matching your request)
Your three-layer split is exactly right. Here's what each would contain, scoped to minimize review surface:
PR 1 — Schema + migration (target: ~300 LOC)
scope TEXT NOT NULL DEFAULT 'personal'+group_id TEXTon 8 core tables- Migration
M014_add_scope_support.pywith backward-compat proof - Model updates (
models.py: 15+ dataclasses, new fields with defaults) - Composite indexes:
(profile_id, scope),(scope, group_id) - No retrieval or interface changes — pure storage layer
PR 2 — Retrieval layer (target: ~400 LOC)
recall_pipeline.py: multi-scope parallel retrieval + weighted RRF fusion- 7 channels: scope-aware filtering in each (
semantic,bm25,entity,temporal,hopfield,profile,spreading_activation) DatabaseManager: 30+ query methods gain optionalscopes/group_idsparams (backward-compat: defaults preserve existing single-profile behavior)- Scope weights configurable via
config.json→scope_weights
PR 3 — External interface (target: ~300 LOC)
- MCP:
remembergetsscope+shared_withparams;recallgetsinclude_global+include_shared;entity list/mergegets--scope - CLI:
slm remember --scope global,slm entity list --scope shared - WorkerPool IPC: scope params passed through to embed workers
MemoryEngine:store()andrecall()signatures extended with backward-compat defaults
Total: ~1,000 LOC across three PRs, each independently reviewable and testable.
Phase 2/3 alignment
Absolutely — not building domain tags or global entity resolution until we sync. The 48 domain-tag mappings and global entity dedup logic are sitting in my fork as phase-2b, untested against whatever entity/graph work you have in flight. Happy to walk through the design whenever works for you.
The two bug-fix PRs
#24 and #25 are each 1-2 line changes with tests. If those could get a quick look, it unblocks me from rebasing the scope PRs on a clean base.
I would love to see the scope model in upstream. MSLM exists to give users a stable package today; it'd be healthier for everyone if the engine-level changes live here and MSLM becomes a thin distribution. Happy to do the PR work in whatever cadence and granularity works for you.
the prs are send~, check them out when you have time~ Cheers