m3-memory 2026.4.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- m3_memory-2026.4.6/ARCHITECTURE.md +222 -0
- m3_memory-2026.4.6/LICENSE +21 -0
- m3_memory-2026.4.6/PKG-INFO +336 -0
- m3_memory-2026.4.6/README.md +312 -0
- m3_memory-2026.4.6/bin/auth_utils.py +260 -0
- m3_memory-2026.4.6/bin/custom_tool_bridge.py +449 -0
- m3_memory-2026.4.6/bin/debug_agent_bridge.py +307 -0
- m3_memory-2026.4.6/bin/embedding_utils.py +160 -0
- m3_memory-2026.4.6/bin/grok_bridge.py +105 -0
- m3_memory-2026.4.6/bin/llm_failover.py +217 -0
- m3_memory-2026.4.6/bin/mcp_proxy.py +984 -0
- m3_memory-2026.4.6/bin/memory_bridge.py +239 -0
- m3_memory-2026.4.6/bin/web_research_bridge.py +165 -0
- m3_memory-2026.4.6/m3_memory.egg-info/PKG-INFO +336 -0
- m3_memory-2026.4.6/m3_memory.egg-info/SOURCES.txt +28 -0
- m3_memory-2026.4.6/m3_memory.egg-info/dependency_links.txt +1 -0
- m3_memory-2026.4.6/m3_memory.egg-info/top_level.txt +1 -0
- m3_memory-2026.4.6/mcp-server.json +23 -0
- m3_memory-2026.4.6/mcp.json.example +24 -0
- m3_memory-2026.4.6/memory/migrations/001_initial_schema.sql +153 -0
- m3_memory-2026.4.6/memory/migrations/002_enforce_relationships.sql +32 -0
- m3_memory-2026.4.6/memory/migrations/003_encrypted_secrets.sql +7 -0
- m3_memory-2026.4.6/memory/migrations/004_archive_db.sql +6 -0
- m3_memory-2026.4.6/memory/migrations/005_perf_and_wal.sql +37 -0
- m3_memory-2026.4.6/pyproject.toml +89 -0
- m3_memory-2026.4.6/requirements.txt +52 -0
- m3_memory-2026.4.6/setup.cfg +4 -0
- m3_memory-2026.4.6/tests/test_auth_utils.py +32 -0
- m3_memory-2026.4.6/tests/test_embedding_utils.py +48 -0
- m3_memory-2026.4.6/tests/test_llm_failover.py +61 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# π οΈ <img src="docs/icon.svg" height="60" style="vertical-align: baseline; margin-bottom: -15px;"> Memory β Agent Instructions
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
> **`M3_MEMORY_ROOT`** β the root of the `m3-memory` repository checkout.
|
|
5
|
+
|
|
6
|
+
> **Local overrides:** If `LOCAL_RULES.md` exists at `$M3_MEMORY_ROOT/LOCAL_RULES.md`, read it before proceeding. It contains machine-specific failover rules (embedding endpoints, LLM endpoints, internal IPs). It is git-ignored and never committed.
|
|
7
|
+
|
|
8
|
+
> All paths are relative to `$M3_MEMORY_ROOT` unless otherwise noted.
|
|
9
|
+
>
|
|
10
|
+
> This file is symlinked to `~/.claude/CLAUDE.md` and `~/.gemini/GEMINI.md`.
|
|
11
|
+
> Follow these instructions exactly. For technical implementation details, see [TECHNICAL_DETAILS.md](./TECHNICAL_DETAILS.md).
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## π οΈ Memory Tools β When and How to Use
|
|
16
|
+
|
|
17
|
+
### βοΈ Writing Memories
|
|
18
|
+
|
|
19
|
+
**Tool:** `memory β memory_write`
|
|
20
|
+
|
|
21
|
+
Call `memory_write` to persist any fact, decision, preference, observation, or knowledge that should survive beyond the current conversation.
|
|
22
|
+
|
|
23
|
+
| Parameter | Required | Notes |
|
|
24
|
+
|-----------|----------|-------|
|
|
25
|
+
| `type` | Yes | One of: `note`, `fact`, `decision`, `preference`, `task`, `code`, `config`, `observation`, `plan`, `summary`, `snippet`, `reference`, `log`, `home`, `user_fact`, `scratchpad`, `auto` |
|
|
26
|
+
| `content` | Yes | The memory content (max 50,000 chars) |
|
|
27
|
+
| `title` | No | Short descriptive title β used for contradiction matching |
|
|
28
|
+
| `importance` | No | 0.0β1.0 (default 0.5). Higher = slower decay, higher search ranking |
|
|
29
|
+
| `agent_id` | No | Your agent identifier |
|
|
30
|
+
| `user_id` | No | User identifier for multi-user isolation |
|
|
31
|
+
| `scope` | No | `user`, `session`, `agent` (default), or `org` |
|
|
32
|
+
| `valid_from` | No | When this fact became true (ISO 8601). Defaults to now. |
|
|
33
|
+
| `valid_to` | No | When this fact stopped being true (ISO 8601). Empty = still valid. |
|
|
34
|
+
| `embed` | No | Generate embedding for semantic search (default true) |
|
|
35
|
+
| `metadata` | No | JSON string with tags, categories, or custom fields |
|
|
36
|
+
|
|
37
|
+
**Type selection guide:**
|
|
38
|
+
- `fact` β objective truths about the world or system ("PostgreSQL 15 is the warehouse version")
|
|
39
|
+
- `decision` β choices made by the user or system ("We chose SQLite over DuckDB for local storage")
|
|
40
|
+
- `preference` β user preferences ("User prefers dark mode", "User wants terse responses")
|
|
41
|
+
- `observation` β things noticed but not yet confirmed ("Build times seem slower after the migration")
|
|
42
|
+
- `note` β general-purpose when no specific type fits
|
|
43
|
+
- `auto` β let the local LLM classify the type automatically
|
|
44
|
+
|
|
45
|
+
**Automatic behaviors on write:**
|
|
46
|
+
|
|
47
|
+
```mermaid
|
|
48
|
+
graph TD
|
|
49
|
+
W[memory_write] --> S[Safety Check]
|
|
50
|
+
S -->|Pass| E[Generate Embedding]
|
|
51
|
+
E --> C[Contradiction Detection]
|
|
52
|
+
E --> L[Auto-Linking]
|
|
53
|
+
C -->|New| DB[(SQLite)]
|
|
54
|
+
C -->|Conflict| SUP[Supersede Old]
|
|
55
|
+
SUP --> DB
|
|
56
|
+
L --> DB
|
|
57
|
+
W --> H[SHA-256 Hash]
|
|
58
|
+
H --> DB
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
- Contradiction detection runs automatically β if a same-type, same-title memory exists with different content (cosine > 0.85), the old one is superseded
|
|
62
|
+
- Auto-linking connects the new memory to the most related existing memory (cosine > 0.7)
|
|
63
|
+
- Content safety check rejects XSS, SQL injection, Python injection, and prompt injection
|
|
64
|
+
- SHA-256 content hash is computed and stored for tamper detection
|
|
65
|
+
- Session-scoped memories auto-expire after 24 hours
|
|
66
|
+
|
|
67
|
+
### π Searching Memories
|
|
68
|
+
|
|
69
|
+
**Tool:** `memory β memory_search`
|
|
70
|
+
|
|
71
|
+
Always search before writing to avoid duplicates. Search before starting any new task (Protocol #4).
|
|
72
|
+
|
|
73
|
+
```mermaid
|
|
74
|
+
graph LR
|
|
75
|
+
Q[Query] --> FTS[Stage 1: FTS5 Keywords]
|
|
76
|
+
Q --> VEC[Stage 2: Vector Similarity]
|
|
77
|
+
FTS --> COMB[Combined Score]
|
|
78
|
+
VEC --> COMB
|
|
79
|
+
COMB --> MMR[Stage 3: MMR Re-Ranking]
|
|
80
|
+
MMR --> R[Final Top-K Results]
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
| Parameter | Required | Notes |
|
|
84
|
+
|-----------|----------|-------|
|
|
85
|
+
| `query` | Yes | Natural language query (max 2,000 chars) |
|
|
86
|
+
| `k` | No | Number of results (default 8, max 100) |
|
|
87
|
+
| `type_filter` | No | Filter by type. Quote for exact match: `"fact"` |
|
|
88
|
+
| `agent_filter` | No | Filter by agent_id |
|
|
89
|
+
| `user_id` | No | Filter by user |
|
|
90
|
+
| `scope` | No | Filter by scope |
|
|
91
|
+
| `as_of` | No | Point-in-time query: "what was true as of this date?" (ISO 8601) |
|
|
92
|
+
| `search_mode` | No | `hybrid` (default) or `semantic` |
|
|
93
|
+
|
|
94
|
+
**How search works:** FTS5 keyword matching β vector similarity β MMR diversity re-ranking. Results are scored as `0.7 Γ vector + 0.3 Γ BM25`. If FTS returns nothing, falls back to pure semantic search automatically.
|
|
95
|
+
|
|
96
|
+
**Tool:** `memory β memory_suggest`
|
|
97
|
+
|
|
98
|
+
Use `memory_suggest` instead of `memory_search` when you need to explain WHY results were retrieved. Returns score breakdowns (vector, BM25, MMR penalty) per result.
|
|
99
|
+
|
|
100
|
+
### π Retrieving and Modifying
|
|
101
|
+
|
|
102
|
+
| Tool | When to Use |
|
|
103
|
+
|------|-------------|
|
|
104
|
+
| `memory_get(id)` | Retrieve full memory by UUID |
|
|
105
|
+
| `memory_update(id, ...)` | Update content, title, metadata, or importance. Records audit trail. |
|
|
106
|
+
| `memory_delete(id)` | Soft-delete (default, recoverable) or `hard=True` (cascade deletes embeddings, relationships, history) |
|
|
107
|
+
| `memory_verify(id)` | Check content integrity β re-computes SHA-256 and compares to stored hash |
|
|
108
|
+
|
|
109
|
+
### πΈοΈ Knowledge Graph
|
|
110
|
+
|
|
111
|
+
| Tool | When to Use |
|
|
112
|
+
|------|-------------|
|
|
113
|
+
| `memory_link(from_id, to_id, type)` | Create a relationship. Types: `related`, `supports`, `contradicts`, `extends`, `supersedes`, `references`, `consolidates` |
|
|
114
|
+
| `memory_graph(id, depth)` | Explore connected memories up to 3 hops. Use when context around a memory matters. |
|
|
115
|
+
| `memory_history(id)` | View the full audit trail for a memory β every create, update, delete, supersede event |
|
|
116
|
+
|
|
117
|
+
### π¬ Conversations
|
|
118
|
+
|
|
119
|
+
| Tool | When to Use |
|
|
120
|
+
|------|-------------|
|
|
121
|
+
| `conversation_start(title, ...)` | Begin a new conversation thread |
|
|
122
|
+
| `conversation_append(conversation_id, role, content)` | Add a message to a conversation |
|
|
123
|
+
| `conversation_search(query)` | Search across all conversation messages |
|
|
124
|
+
| `conversation_summarize(conversation_id, threshold)` | Generate an LLM summary when a conversation has many messages |
|
|
125
|
+
|
|
126
|
+
### β»οΈ Lifecycle and Maintenance
|
|
127
|
+
|
|
128
|
+
| Tool | When to Use |
|
|
129
|
+
|------|-------------|
|
|
130
|
+
| `memory_maintenance()` | Run decay, expiry purge, orphan pruning, auto-archival, retention enforcement. Call periodically or when system feels sluggish. |
|
|
131
|
+
| `memory_dedup(threshold, dry_run)` | Find near-duplicate memories. Use `dry_run=True` first to preview. |
|
|
132
|
+
| `memory_consolidate(type_filter, agent_filter, threshold)` | Merge old memories of the same type into LLM-generated summaries. Use when a category has too many items. |
|
|
133
|
+
| `memory_set_retention(agent_id, max_memories, ttl_days)` | Set per-agent retention limits. Enforced automatically by `memory_maintenance`. |
|
|
134
|
+
| `memory_feedback(memory_id, feedback)` | Mark a memory as `useful` (boosts importance +0.1) or `wrong` (soft-deletes). |
|
|
135
|
+
|
|
136
|
+
### βοΈ Data Governance
|
|
137
|
+
|
|
138
|
+
| Tool | When to Use |
|
|
139
|
+
|------|-------------|
|
|
140
|
+
| `gdpr_export(user_id)` | User requests their data β returns all memories as JSON |
|
|
141
|
+
| `gdpr_forget(user_id)` | User requests deletion β hard-deletes everything (memories, embeddings, relationships, history) |
|
|
142
|
+
| `memory_export(agent_filter, type_filter, since)` | Export memories as portable JSON for backup or migration |
|
|
143
|
+
| `memory_import(data)` | Import from a previous export. UPSERT semantics β safe to re-run. |
|
|
144
|
+
|
|
145
|
+
### βοΈ Operations
|
|
146
|
+
|
|
147
|
+
| Tool | When to Use |
|
|
148
|
+
|------|-------------|
|
|
149
|
+
| `memory_cost_report()` | Check session operation counts (embed calls, tokens, searches, writes) |
|
|
150
|
+
| `chroma_sync(direction)` | Manual sync with ChromaDB. Use `push`, `pull`, or `both`. |
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## MCP Bridge Infrastructure
|
|
155
|
+
|
|
156
|
+
| Server | Script | Tools |
|
|
157
|
+
|--------|--------|-------|
|
|
158
|
+
| `custom_pc_tool` | `bin/custom_tool_bridge.py` | `log_activity`, `update_focus`, `query_decisions`, `retire_focus`, `check_thermal_load`, `query_local_model`, `web_search`, `grok_ask` |
|
|
159
|
+
| `memory` | `bin/memory_bridge.py` | 25 memory tools (see above) |
|
|
160
|
+
| `grok_intel` | `bin/grok_bridge.py` | `grok_ask` β real-time X/Twitter data via Grok 3 |
|
|
161
|
+
| `web_research` | `bin/web_research_bridge.py` | `web_search` β Perplexity sonar-pro (auto-fallback to Grok on failure) |
|
|
162
|
+
| `mcp_proxy` | `bin/mcp_proxy.py` | SSE streaming proxy for non-MCP-native clients |
|
|
163
|
+
| `debug_agent` | `bin/debug_agent_bridge.py` | `debug_analyze`, `debug_bisect`, `debug_trace`, `debug_correlate`, `debug_history`, `debug_report` |
|
|
164
|
+
|
|
165
|
+
**Local model calls:** Use `custom_pc_tool β query_local_model(prompt=...)` to invoke the local LLM directly.
|
|
166
|
+
|
|
167
|
+
**LLM Engine:** `bin/llm_failover.py` auto-selects the largest available model. Default: `localhost:1234`. For multi-machine setups, set `LLM_ENDPOINTS_CSV` env var with comma-separated endpoints.
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## π Operational Protocols β MANDATORY, NO EXCEPTIONS
|
|
172
|
+
|
|
173
|
+
Every protocol specifies the **exact MCP server and tool** to call. Do not batch; fire immediately.
|
|
174
|
+
|
|
175
|
+
### π§ Protocol #1 β The Reasoning Rule
|
|
176
|
+
**Trigger:** `query_local_model` returns `reasoning_content` (>200 chars).
|
|
177
|
+
**Action:** Automatically archived to `activity_logs` by `query_local_model`. For manual complex reasoning, call `custom_pc_tool β log_activity(category="thought", ...)`.
|
|
178
|
+
|
|
179
|
+
### π‘οΈ Protocol #2 β The Hardware Rule
|
|
180
|
+
**Trigger:** Suspected pressure or after heavy inference.
|
|
181
|
+
**Action:** 1. `custom_pc_tool β check_thermal_load()`. 2. If status β Nominal, `log_activity(category="hardware", ...)`.
|
|
182
|
+
|
|
183
|
+
### βοΈ Protocol #3 β The Decision Rule
|
|
184
|
+
**Trigger:** User agrees to ANY change (code, file move, diagnosis).
|
|
185
|
+
**Action:** Call `custom_pc_tool β log_activity(category="decision", ...)` immediately.
|
|
186
|
+
|
|
187
|
+
### π Protocol #4 β The Search Rule
|
|
188
|
+
**Trigger:** Before starting any new task.
|
|
189
|
+
**Action:** Call `custom_pc_tool β query_decisions(...)` **AND** `memory β memory_search(...)`. Check what's already known before proceeding.
|
|
190
|
+
|
|
191
|
+
### π― Protocol #5 β The Focus Protocol
|
|
192
|
+
**Trigger:** Every 3 turns of a technical conversation.
|
|
193
|
+
**Action:** `custom_pc_tool β update_focus(summary="...")`. Call `retire_focus()` on task completion.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Auth Model
|
|
198
|
+
|
|
199
|
+
All bridges resolve API keys using `$M3_MEMORY_ROOT/bin/auth_utils.py`:
|
|
200
|
+
1. Environment variables
|
|
201
|
+
2. `keyring` (Keychain / Credential Manager)
|
|
202
|
+
3. **Synchronized Encrypted Vault** (AES-256 via Fernet/PBKDF2-HMAC-SHA256, 600K iterations, synced to PG Warehouse)
|
|
203
|
+
|
|
204
|
+
**Security:** `AGENT_OS_MASTER_KEY` must be in native OS keyring. API keys are NEVER stored in plaintext. Legacy 100K-iteration encrypted secrets are auto-migrated to 600K on first decryption.
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Sandbox Environment
|
|
209
|
+
|
|
210
|
+
**OpenClaw** β containerized agent sandbox (node:22-slim) on `localhost:8000`.
|
|
211
|
+
- Tools: `claw-grok`, `claw-claude`, `claw-gemini`, `claw-perplexity`, `claw-local`
|
|
212
|
+
- Full LAN access via OrbStack (can reach ChromaDB/Postgres)
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## Health Check
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
bin/mcp_check.sh # MCP bridge connectivity
|
|
220
|
+
python bin/test_memory_bridge.py # 41 end-to-end tests
|
|
221
|
+
python bin/benchmark_memory.py # Retrieval quality benchmarks
|
|
222
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 skynetcmd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: m3-memory
|
|
3
|
+
Version: 2026.4.6
|
|
4
|
+
Summary: Local-first agentic memory layer for MCP agents β 25 tools, hybrid search, GDPR, no cloud
|
|
5
|
+
Author: skynetcmd
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/skynetcmd/m3-memory
|
|
8
|
+
Project-URL: Repository, https://github.com/skynetcmd/m3-memory
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/skynetcmd/m3-memory/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/skynetcmd/m3-memory/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: mcp,model-context-protocol,agentic-memory,local-llm,claude,gemini,rag,vector-search,sqlite,gdpr,ai-agents,ollama
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# π§ M3 Memory β Local-First Agentic Memory for MCP Agents
|
|
26
|
+
|
|
27
|
+
<p align="center">
|
|
28
|
+
<img src="docs/logo.svg" alt="M3 Memory Logo" width="600">
|
|
29
|
+
</p>
|
|
30
|
+
|
|
31
|
+
<p align="center">
|
|
32
|
+
<a href="https://github.com/skynetcmd/m3-memory/stargazers"><img alt="GitHub Stars" src="https://img.shields.io/github/stars/skynetcmd/m3-memory?style=social"></a>
|
|
33
|
+
<a href="https://github.com/skynetcmd/m3-memory/network/members"><img alt="GitHub Forks" src="https://img.shields.io/github/forks/skynetcmd/m3-memory?style=social"></a>
|
|
34
|
+
<a href="https://discord.gg/ZcJ3EGC99B"><img alt="Discord" src="https://img.shields.io/badge/Discord-M3--Memory%20Community-5865F2?logo=discord&logoColor=white"></a>
|
|
35
|
+
</p>
|
|
36
|
+
|
|
37
|
+
<p align="center">
|
|
38
|
+
<a href="https://pypi.org/project/m3-memory/"><img alt="PyPI version" src="https://img.shields.io/pypi/v/m3-memory.svg"></a>
|
|
39
|
+
<a href="https://pypi.org/project/m3-memory/"><img alt="PyPI downloads" src="https://img.shields.io/pypi/dm/m3-memory.svg"></a>
|
|
40
|
+
<a href="https://www.python.org"><img alt="Python 3.11+" src="https://img.shields.io/badge/Python-3.11+-blue.svg"></a>
|
|
41
|
+
<a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-green.svg"></a>
|
|
42
|
+
<a href="https://modelcontextprotocol.io"><img alt="MCP 25 tools" src="https://img.shields.io/badge/MCP-25_tools-orange.svg"></a>
|
|
43
|
+
<a href=".github/workflows/ci.yml"><img alt="CI" src="https://img.shields.io/badge/CI-lint%20%7C%20typecheck%20%7C%20test-brightgreen.svg"></a>
|
|
44
|
+
<img alt="Platform" src="https://img.shields.io/badge/platform-macOS%20%7C%20Windows%20%7C%20Linux-lightgrey.svg">
|
|
45
|
+
</p>
|
|
46
|
+
|
|
47
|
+
> Give your MCP agents persistent, private memory that actually works. No cloud. No forgetting.
|
|
48
|
+
|
|
49
|
+
**Industrial-strength memory layer that just works.** M3 Memory gives AI agents persistent, private, intelligent memory β running 100% on your hardware, with no cloud APIs and no subscriptions.
|
|
50
|
+
|
|
51
|
+
- π οΈ **25 MCP tools** β write, search, link, graph, verify, sync, export, and more
|
|
52
|
+
- π **Hybrid search** β FTS5 keywords + vector similarity + MMR diversity re-ranking
|
|
53
|
+
- π« **Contradiction detection** β stale facts are superseded automatically
|
|
54
|
+
- π **Cross-device sync** β SQLite β PostgreSQL β ChromaDB, bi-directional
|
|
55
|
+
- π‘οΈ **GDPR-ready** β Article 17 (forget) and Article 20 (export) built in
|
|
56
|
+
- π **Fully local** β your embeddings, your hardware, your data
|
|
57
|
+
|
|
58
|
+
Works with **Claude Code, Gemini CLI, Aider, OpenClaw**, or any MCP-compatible agent.
|
|
59
|
+
|
|
60
|
+
β **Star if you want local agents that remember** β feedback & issues very welcome!
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Table of Contents
|
|
65
|
+
|
|
66
|
+
- [Why M3 Memory](#why-m3-memory)
|
|
67
|
+
- [Architecture](#architecture)
|
|
68
|
+
- [Quick Start](#quick-start)
|
|
69
|
+
- [Features](#features)
|
|
70
|
+
- [25 MCP Tools](#25-mcp-tools)
|
|
71
|
+
- [Documentation](#documentation)
|
|
72
|
+
- [Contributing](#contributing)
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Why M3 Memory
|
|
77
|
+
|
|
78
|
+
Most agent memory solutions require you to pick one: local speed, or cloud persistence, or multi-agent sharing. M3 Memory gives you all three, with zero data leaving your machine by default.
|
|
79
|
+
|
|
80
|
+
**Example:** You're debugging a deployment issue on your MacBook at a coffee shop. Claude Code recalls the architecture decisions from last week, the server configs from yesterday, and the troubleshooting steps that worked before β all from local SQLite, no internet required. Later, at your Windows desktop at home, Gemini CLI picks up exactly where you left off. Same memories, same context, same knowledge graph β synced in the background the moment your laptop hit the local network.
|
|
81
|
+
|
|
82
|
+
> β **Your AI's memory belongs to you, lives on your hardware, and follows you across every device and every agent.**
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Architecture
|
|
87
|
+
|
|
88
|
+
```mermaid
|
|
89
|
+
graph TD
|
|
90
|
+
subgraph "π€ AI Agents"
|
|
91
|
+
C[Claude Code]
|
|
92
|
+
G[Gemini CLI]
|
|
93
|
+
A[Aider / OpenClaw]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
subgraph "π MCP Bridge"
|
|
97
|
+
MB[memory_bridge.py β 25 MCP tools]
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
subgraph "πΎ Storage Layers"
|
|
101
|
+
SQ[(SQLite β Local L1)]
|
|
102
|
+
PG[(PostgreSQL β Sync L2)]
|
|
103
|
+
CH[(ChromaDB β Federated L3)]
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
C & G & A <--> MB
|
|
107
|
+
MB <--> SQ
|
|
108
|
+
SQ <-->|Bi-directional Delta Sync| PG
|
|
109
|
+
SQ <-->|Push/Pull| CH
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### The Memory Write Pipeline
|
|
113
|
+
|
|
114
|
+
```mermaid
|
|
115
|
+
sequenceDiagram
|
|
116
|
+
participant A as Agent
|
|
117
|
+
participant M as M3 Memory
|
|
118
|
+
participant L as Local LLM
|
|
119
|
+
participant S as SQLite
|
|
120
|
+
|
|
121
|
+
A->>M: memory_write(content)
|
|
122
|
+
M->>M: Safety Check (XSS / injection / poisoning)
|
|
123
|
+
M->>L: Generate Embedding
|
|
124
|
+
L-->>M: Vector [0.12, -0.05, ...]
|
|
125
|
+
M->>M: Contradiction Detection
|
|
126
|
+
M->>M: Auto-Link Related Memories
|
|
127
|
+
M->>M: SHA-256 Content Hash
|
|
128
|
+
M->>S: Store Memory + Vector
|
|
129
|
+
S-->>M: Success
|
|
130
|
+
M-->>A: Created: <uuid>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Quick Start
|
|
136
|
+
|
|
137
|
+
### Prerequisites
|
|
138
|
+
|
|
139
|
+
- Python 3.11+
|
|
140
|
+
- Any OpenAI-compatible local LLM server: [LM Studio](https://lmstudio.ai), [Ollama](https://ollama.com), vLLM, LocalAI, llama.cpp
|
|
141
|
+
- *(Optional)* PostgreSQL + ChromaDB for full cross-device federation
|
|
142
|
+
|
|
143
|
+
### Install
|
|
144
|
+
|
|
145
|
+
**Option A β pip (quickest):**
|
|
146
|
+
```bash
|
|
147
|
+
pip install m3-memory
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Option B β clone (for development or full feature set):**
|
|
151
|
+
```bash
|
|
152
|
+
git clone https://github.com/skynetcmd/m3-memory.git
|
|
153
|
+
cd m3-memory
|
|
154
|
+
|
|
155
|
+
python -m venv .venv
|
|
156
|
+
source .venv/bin/activate # macOS/Linux
|
|
157
|
+
# .\.venv\Scripts\Activate.ps1 # Windows PowerShell
|
|
158
|
+
|
|
159
|
+
pip install -r requirements.txt
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Validate & Test
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
python validate_env.py # Check all dependencies and LLM connectivity
|
|
166
|
+
python run_tests.py # Run the end-to-end test suite
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Connect Your Agent
|
|
170
|
+
|
|
171
|
+
Copy [`mcp.json.example`](./mcp.json.example) to your agent's MCP config location and update the `cwd` path:
|
|
172
|
+
|
|
173
|
+
```json
|
|
174
|
+
{
|
|
175
|
+
"mcpServers": {
|
|
176
|
+
"memory": {
|
|
177
|
+
"command": "python",
|
|
178
|
+
"args": ["bin/memory_bridge.py"],
|
|
179
|
+
"cwd": "/path/to/m3-memory"
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
| Agent | Config location |
|
|
186
|
+
|-------|----------------|
|
|
187
|
+
| Claude Code | `~/.claude/claude_desktop_config.json` or `.mcp.json` in project root |
|
|
188
|
+
| Gemini CLI | `~/.gemini/settings.json` |
|
|
189
|
+
| Aider | `.aider.conf.yml` (via `--mcp-server` flag) |
|
|
190
|
+
|
|
191
|
+
For OS-specific setup: [macOS](./docs/install_macos.md) | [Linux](./docs/install_linux.md) | [Windows](./docs/install_windows-powershell.md)
|
|
192
|
+
|
|
193
|
+
> M3 Memory can also be discovered automatically in Claude Code and other MCP clients via the [MCP Registry](https://github.com/modelcontextprotocol/registry). See [`mcp-server.json`](./mcp-server.json) for the registry manifest.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Features
|
|
198
|
+
|
|
199
|
+
### π Hybrid Search That Actually Works
|
|
200
|
+
|
|
201
|
+
Three-stage pipeline consistently outperforms pure vector search:
|
|
202
|
+
|
|
203
|
+
1. **FTS5 keyword** β BM25-ranked full-text with injection-safe sanitization
|
|
204
|
+
2. **Semantic vector** β cosine similarity on 1024-dim embeddings via numpy
|
|
205
|
+
3. **MMR re-ranking** β Maximal Marginal Relevance ensures diverse results β no more five near-identical memories
|
|
206
|
+
|
|
207
|
+
Every result can return a full score breakdown (vector, BM25, MMR penalty) via `memory_suggest`.
|
|
208
|
+
|
|
209
|
+
### π« Contradiction Detection
|
|
210
|
+
|
|
211
|
+
Write a fact that conflicts with an existing one β M3 detects it automatically. The old memory is soft-deleted, a `supersedes` relationship is recorded, and the full history is preserved. No stale data, no manual cleanup.
|
|
212
|
+
|
|
213
|
+
### πΈοΈ Knowledge Graph
|
|
214
|
+
|
|
215
|
+
Memories form a web. M3 auto-links related memories on write (cosine > 0.7) and supports 7 relationship types: `related`, `supports`, `contradicts`, `extends`, `supersedes`, `references`, `consolidates`. Traverse up to 3 hops with a single `memory_graph` call.
|
|
216
|
+
|
|
217
|
+
### π§Ή Self-Maintaining
|
|
218
|
+
|
|
219
|
+
- **Importance decay** β memories fade 0.5%/day after 7 days unless reinforced
|
|
220
|
+
- **Auto-archival** β low-importance items (< 0.05) older than 30 days move to cold storage
|
|
221
|
+
- **Per-agent retention** β set max memory count and TTL per agent
|
|
222
|
+
- **Consolidation** β local LLM merges old memories into summaries when groups grow large
|
|
223
|
+
- **Deduplication** β configurable cosine threshold catches near-duplicates
|
|
224
|
+
|
|
225
|
+
### β³ Bitemporal History
|
|
226
|
+
|
|
227
|
+
Track not just *when a fact was stored*, but *when it was actually true*. Query with `as_of="2026-01-15"` to see the world as your agent knew it on that date β essential for compliance and debugging.
|
|
228
|
+
|
|
229
|
+
### π€ LLM-Powered Intelligence (Local)
|
|
230
|
+
|
|
231
|
+
Any OpenAI-compatible server works (LM Studio, Ollama, vLLM, LocalAI):
|
|
232
|
+
|
|
233
|
+
- **Auto-classification** β pass `type="auto"` and the LLM categorizes into 18 types
|
|
234
|
+
- **Conversation summarization** β compress long threads into 3-5 key points
|
|
235
|
+
- **Multi-layered consolidation** β merge related memory groups into summaries
|
|
236
|
+
|
|
237
|
+
Zero API costs. Zero data exfiltration.
|
|
238
|
+
|
|
239
|
+
### π‘οΈ Security & Compliance
|
|
240
|
+
|
|
241
|
+
| Layer | Protection |
|
|
242
|
+
|-------|------------|
|
|
243
|
+
| **Credentials** | AES-256 encrypted vault (PBKDF2, 600K iterations). OS keyring integration. Zero plaintext storage. |
|
|
244
|
+
| **Content** | SHA-256 signing on every write. `memory_verify` detects post-write tampering. |
|
|
245
|
+
| **Input** | Poisoning prevention rejects XSS, SQL injection, Python injection, and prompt injection at write boundary. |
|
|
246
|
+
| **Search** | FTS5 operator sanitization prevents query injection. |
|
|
247
|
+
| **Network** | Circuit breaker (3-failure threshold). Strict timeouts. Tokens never logged. |
|
|
248
|
+
|
|
249
|
+
**GDPR-Ready:**
|
|
250
|
+
- `gdpr_forget` β hard-deletes all data for a user (Article 17)
|
|
251
|
+
- `gdpr_export` β returns all memories as portable JSON (Article 20)
|
|
252
|
+
|
|
253
|
+
### π Cross-Device Sync
|
|
254
|
+
|
|
255
|
+
- Bi-directional delta sync: SQLite β PostgreSQL via UUID-based UPSERT
|
|
256
|
+
- Crash-resistant β watermark-based tracking, at-least-once delivery
|
|
257
|
+
- ChromaDB federation for distributed vector search across LAN
|
|
258
|
+
- Hourly automated sync; manual sync via `chroma_sync` tool
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## 25 MCP Tools
|
|
263
|
+
|
|
264
|
+
| Category | Tools |
|
|
265
|
+
|----------|-------|
|
|
266
|
+
| **Memory Ops** | `memory_write`, `memory_search`, `memory_suggest`, `memory_get`, `memory_update`, `memory_delete`, `memory_verify` |
|
|
267
|
+
| **Knowledge Graph** | `memory_link`, `memory_graph`, `memory_history` |
|
|
268
|
+
| **Conversations** | `conversation_start`, `conversation_append`, `conversation_search`, `conversation_summarize` |
|
|
269
|
+
| **Lifecycle** | `memory_maintenance`, `memory_dedup`, `memory_consolidate`, `memory_set_retention`, `memory_feedback` |
|
|
270
|
+
| **Data Governance** | `gdpr_export`, `gdpr_forget`, `memory_export`, `memory_import` |
|
|
271
|
+
| **Operations** | `memory_cost_report`, `chroma_sync` |
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## Documentation
|
|
276
|
+
|
|
277
|
+
| File | Purpose |
|
|
278
|
+
|------|---------|
|
|
279
|
+
| [CORE_FEATURES.md](./CORE_FEATURES.md) | Feature overview β start here |
|
|
280
|
+
| [ARCHITECTURE.md](./ARCHITECTURE.md) | Agent instruction manual: all 25 MCP tools, protocols, usage rules |
|
|
281
|
+
| [TECHNICAL_DETAILS.md](./TECHNICAL_DETAILS.md) | Deep-dive: storage internals, search pipeline, schema, sync, security |
|
|
282
|
+
| [ENVIRONMENT_VARIABLES.md](./ENVIRONMENT_VARIABLES.md) | Security configuration and credential setup |
|
|
283
|
+
| [CHANGELOG.md](./CHANGELOG.md) | Release history and what changed |
|
|
284
|
+
| [CONTRIBUTING.md](./CONTRIBUTING.md) | How to contribute, run tests, and fix issues |
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## Community
|
|
289
|
+
|
|
290
|
+
Join the M3-Memory Discord server to get help, share your setup, discuss ideas, and follow development.
|
|
291
|
+
|
|
292
|
+
[](https://discord.gg/ZcJ3EGC99B)
|
|
293
|
+
|
|
294
|
+
| Channel | Purpose |
|
|
295
|
+
|---------|---------|
|
|
296
|
+
| `#start-here` | New? Start here β overview & quick links |
|
|
297
|
+
| `#ask-anything` | Setup help, config questions, how-tos |
|
|
298
|
+
| `#bug-reports` | Report issues with steps to reproduce |
|
|
299
|
+
| `#showcase` | Share your M3-Memory setups and demos |
|
|
300
|
+
| `#search-quality` | Hybrid search tuning & benchmarks |
|
|
301
|
+
| `#sync-federation` | Multi-device sync & ChromaDB federation |
|
|
302
|
+
| `#memory-design` | Architecture discussions & research |
|
|
303
|
+
|
|
304
|
+
**M3_Bot** is live in the server β mention `@M3_Bot` or use `!ask <question>` in any channel to get answers straight from the documentation.
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
## Contributing
|
|
309
|
+
|
|
310
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md) for how to get started, run the test suite, and submit changes.
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
314
|
+
## Project Structure
|
|
315
|
+
|
|
316
|
+
```
|
|
317
|
+
bin/ Core MCP bridges, SDK, and automation scripts
|
|
318
|
+
memory/ SQLite database and migration logic
|
|
319
|
+
config/ Configuration templates for agents and shell
|
|
320
|
+
docs/ Architecture diagrams, API reference, and OS install guides
|
|
321
|
+
scripts/ Maintenance and utility scripts (fix_bugs, fix_db, fix_lint, etc.)
|
|
322
|
+
logs/ Centralized audit and debug logs
|
|
323
|
+
tests/ End-to-end test suite
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
**Status:** Production Release β v2026.04 Β· [MIT License](LICENSE) Β· [Changelog](CHANGELOG.md)
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
[](https://star-history.com/#skynetcmd/m3-memory&Date)
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
*M3 Memory: the industrial-strength foundation for agents that remember.*
|