plug-play-memory 0.2.0__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.
Files changed (29) hide show
  1. plug_play_memory-0.2.0/LICENSE +201 -0
  2. plug_play_memory-0.2.0/PKG-INFO +487 -0
  3. plug_play_memory-0.2.0/README.md +466 -0
  4. plug_play_memory-0.2.0/plug_play_memory/__init__.py +23 -0
  5. plug_play_memory-0.2.0/plug_play_memory/audit.py +209 -0
  6. plug_play_memory-0.2.0/plug_play_memory/auth.py +155 -0
  7. plug_play_memory-0.2.0/plug_play_memory/cli.py +413 -0
  8. plug_play_memory-0.2.0/plug_play_memory/consolidation.py +172 -0
  9. plug_play_memory-0.2.0/plug_play_memory/emitter.py +337 -0
  10. plug_play_memory-0.2.0/plug_play_memory/events.py +36 -0
  11. plug_play_memory-0.2.0/plug_play_memory/judge.py +461 -0
  12. plug_play_memory-0.2.0/plug_play_memory/policies/builtin/_base.yaml +18 -0
  13. plug_play_memory-0.2.0/plug_play_memory/policies/builtin/coding.yaml +53 -0
  14. plug_play_memory-0.2.0/plug_play_memory/policies/builtin/financial.yaml +50 -0
  15. plug_play_memory-0.2.0/plug_play_memory/policies/builtin/study.yaml +50 -0
  16. plug_play_memory-0.2.0/plug_play_memory/policy.py +353 -0
  17. plug_play_memory-0.2.0/plug_play_memory/server.py +374 -0
  18. plug_play_memory-0.2.0/plug_play_memory/storage.py +495 -0
  19. plug_play_memory-0.2.0/plug_play_memory.egg-info/PKG-INFO +487 -0
  20. plug_play_memory-0.2.0/plug_play_memory.egg-info/SOURCES.txt +27 -0
  21. plug_play_memory-0.2.0/plug_play_memory.egg-info/dependency_links.txt +1 -0
  22. plug_play_memory-0.2.0/plug_play_memory.egg-info/entry_points.txt +2 -0
  23. plug_play_memory-0.2.0/plug_play_memory.egg-info/requires.txt +12 -0
  24. plug_play_memory-0.2.0/plug_play_memory.egg-info/top_level.txt +1 -0
  25. plug_play_memory-0.2.0/pyproject.toml +32 -0
  26. plug_play_memory-0.2.0/setup.cfg +4 -0
  27. plug_play_memory-0.2.0/tests/test_mcp_server.py +215 -0
  28. plug_play_memory-0.2.0/tests/test_plug_play_memory.py +634 -0
  29. plug_play_memory-0.2.0/tests/test_three_agents.py +371 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Tathagat
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,487 @@
1
+ Metadata-Version: 2.4
2
+ Name: plug-play-memory
3
+ Version: 0.2.0
4
+ Summary: Self-hosted, brain-inspired memory + permissions for AI agents. MCP-native. One SQLite file.
5
+ Author: Tathagat
6
+ License: Apache-2.0
7
+ Keywords: mcp,ai-agents,memory,permissions,llm,opa,self-hosted,neuroscience
8
+ Requires-Python: >=3.10
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: pyyaml>=6.0
12
+ Requires-Dist: mcp<2.0.0,>=1.20.0
13
+ Requires-Dist: sse-starlette<3.0.0
14
+ Provides-Extra: dev
15
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
16
+ Provides-Extra: vector
17
+ Requires-Dist: sqlite-vec>=0.1.9; extra == "vector"
18
+ Provides-Extra: embeddings-local
19
+ Requires-Dist: sentence-transformers>=3.0.0; extra == "embeddings-local"
20
+ Dynamic: license-file
21
+
22
+ # plug-play-memory
23
+
24
+ > Self-hosted, brain-inspired memory + permissions for AI agents. MCP-native. One SQLite file.
25
+
26
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
27
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
28
+ [![MCP-compatible](https://img.shields.io/badge/MCP-compatible-green.svg)](https://modelcontextprotocol.io)
29
+ [![Stars](https://img.shields.io/github/stars/tathagat-git/plug-play-memory.svg)](https://github.com/tathagat-git/plug-play-memory/stargazers)
30
+
31
+ Most agent memory systems (Mem0, Zep, Letta) try to extract facts from chat. plug-play-memory agents **emit structured events** about what they did, a **judge decides what's worth saving**, and a **layered policy engine** enforces what they're allowed to do.
32
+
33
+ Your coding agent remembers the bug it fixed last week, not the small talk around it. Your study agent remembers your misconceptions, not every question you asked. Runs on your laptop. Costs $0. No data leaves your machine.
34
+
35
+ ---
36
+
37
+ ## Why this exists
38
+
39
+ Agent memory today has three problems:
40
+
41
+ 1. **Memory is decoupled from permissions.** Mem0/Zep/Letta store facts; Lasso/Pillar enforce security. Nobody does both. So an LLM can self-write malicious facts, or a fine-tuned model can be talked out of prompt-based "permissions."
42
+ 2. **Chat-based extraction is fragile.** Regex on conversation text false-positives on code (`for x in m` looks like a fact). LLM-judge-on-every-message is expensive and noisy.
43
+ 3. **Memory grows forever.** No active forgetting. No consolidation. No concept of "this fact stopped being useful."
44
+
45
+ plug-play-memory fixes all three:
46
+
47
+ | Problem | Fix |
48
+ |---|---|
49
+ | Memory without permissions | **Layered policy engine** with OPA/YAML backends, default-deny, defense-in-depth |
50
+ | Chat-based extraction | **Event-based memory** — agents emit structured events, not raw chat |
51
+ | Infinite memory | **Brain-inspired consolidation** — tag at encode, sleep-consolidate, actively forget unused |
52
+
53
+ ---
54
+
55
+ ## How it works
56
+
57
+ ```
58
+ Agent (any kind: coding, study, financial, support)
59
+ │
60
+ │ emits structured events
61
+ ▼
62
+ ┌─────────────────────────────────────────┐
63
+ │ EventEmitter (SDK) │
64
+ │ - file_edited(path, lines_changed) │
65
+ │ - git_pushed(branch, sha) │
66
+ │ - decision_made(topic, choice) │
67
+ │ - answer_attempted(topic, correct) │
68
+ │ - make_payment(amount, recipient) │
69
+ └────────────────┬────────────────────────┘
70
+ │
71
+ ▼
72
+ ┌─────────────────────────────────────────┐
73
+ │ Judge (no LLM required) │
74
+ │ 1. Rules — deterministic per-action │
75
+ │ 2. Heuristics — regex on raw field │
76
+ │ 3. Salience — 4-factor brain score │
77
+ └────────────────┬────────────────────────┘
78
+ │ should_save, salience, tagged
79
+ ▼
80
+ ┌─────────────────────────────────────────┐
81
+ │ Policy Gate (layered) │
82
+ │ builtin/_base → builtin/{type} │
83
+ │ → custom/{type} → custom/{agent_id} │
84
+ │ Deny rules in _base are absolute │
85
+ └────────────────┬────────────────────────┘
86
+ │ allowed?
87
+ ▼
88
+ ┌─────────────────────────────────────────┐
89
+ │ MemoryStore (one SQLite file) │
90
+ │ + Audit Log (append-only, hash-chain) │
91
+ └─────────────────────────────────────────┘
92
+ │
93
+ │ runs nightly
94
+ ▼
95
+ ┌─────────────────────────────────────────┐
96
+ │ Consolidator (the "sleep" phase) │
97
+ │ - Promote tagged facts that got recalled│
98
+ │ - Decay tagged facts that didn't │
99
+ │ - Forget low-importance facts unused 30d│
100
+ └─────────────────────────────────────────┘
101
+ ```
102
+
103
+ ---
104
+
105
+ ## 30-second quickstart
106
+
107
+ ```bash
108
+ pip install plug-play-memory
109
+
110
+ # Initialize a project
111
+ agentmemory init my-agent --type coding
112
+ cd my-agent
113
+
114
+ # Run the MCP server (for Claude Desktop / Cursor)
115
+ agentmemory serve
116
+ ```
117
+
118
+ Or use it as a Python library:
119
+
120
+ ```python
121
+ from plug_play_memory import (
122
+ MemoryStore, PolicyEngine, EventEmitter, Judge, Consolidator,
123
+ )
124
+
125
+ store = MemoryStore("memory.db")
126
+ policy = PolicyEngine()
127
+ policy.set_agent_type("coder-1", "coding")
128
+ judge = Judge()
129
+ emitter = EventEmitter(store, policy, judge, agent_id="coder-1", agent_type="coding")
130
+
131
+ # Emit structured events — the judge + policy handle the rest
132
+ emitter.decision_made(
133
+ topic="auth",
134
+ choice="use JWT",
135
+ reason="simpler than sessions",
136
+ )
137
+ # → saved to archival, importance=high, salience=0.30
138
+
139
+ emitter.test_run(suite="tests/", passed=10, failed=0)
140
+ # → discarded by judge (passing tests aren't memorable)
141
+
142
+ emitter.test_run(
143
+ suite="tests/auth/", passed=11, failed=1,
144
+ failures=["test_rate_limit: expected 429, got 200"],
145
+ )
146
+ # → saved to archival as error, importance=high
147
+
148
+ # Recall
149
+ results = store.recall_semantic("coder-1", "auth rate limiting", k=3)
150
+ for f in results:
151
+ print(f.value)
152
+ ```
153
+
154
+ ---
155
+
156
+ ## Use with Claude Desktop / Cursor
157
+
158
+ Add to your `claude_desktop_config.json`:
159
+
160
+ ```json
161
+ {
162
+ "mcpServers": {
163
+ "plug-play-memory": {
164
+ "command": "agentmemory",
165
+ "args": [
166
+ "serve",
167
+ "--db", "/absolute/path/to/memory.db",
168
+ "--config", "/absolute/path/to/config.yaml"
169
+ ]
170
+ }
171
+ }
172
+ }
173
+ ```
174
+
175
+ Claude now has these 8 tools:
176
+
177
+ | Tool | What it does |
178
+ |---|---|
179
+ | `remember_event` | Emit a structured event; judge + policy + storage handle it |
180
+ | `recall` | Retrieve memory (core / recall / archival tiers) |
181
+ | `check_permission` | Hard enforcement gate before side-effecting actions |
182
+ | `forget` | Soft-delete a fact (preserves audit trail) |
183
+ | `audit_recent` | Recent audit log entries for this agent |
184
+ | `coverage_manifest` | What's actually been governed (not a safety claim) |
185
+ | `consolidate` | Run sleep + active forgetting sweep |
186
+ | `list_policies` | Show loaded policy layers |
187
+
188
+ ---
189
+
190
+ ## Brain-inspired memory design
191
+
192
+ Seven mechanisms, each mapped to a real biological principle:
193
+
194
+ | Brain mechanism | plug-play-memory equivalent |
195
+ |---|---|
196
+ | Attention filter (thalamus) | EventEmitter only emits meaningful events |
197
+ | Emotional salience (amygdala) | `outcome` field + salience scoring |
198
+ | Prediction error (dopamine) | Salience score boosts on surprising outcomes |
199
+ | Two-stage memory (hippocampus → neocortex) | `recall` tier (fast) → `archival` tier (durable) |
200
+ | Synaptic tagging (STC) | `tagged` flag — fragile until consolidated |
201
+ | Sleep consolidation | Background job promotes reinforced tagged facts |
202
+ | Active forgetting | Decay + prune unused low-importance facts |
203
+ | Spacing effect | `recall_count` strengthens frequently-recalled facts |
204
+
205
+ **Self-tuning:** memories the agent actually uses get stronger. Memories it never recalls fade. No LLM required.
206
+
207
+ ---
208
+
209
+ ## Layered policy system
210
+
211
+ Four built-in packs ship with the package:
212
+
213
+ ```
214
+ policies/builtin/
215
+ ├── _base.yaml # deny-all baseline, defense-in-depth absolute denies
216
+ ├── coding.yaml # coding agent rules (file_edited, git_pushed, deploy, etc.)
217
+ ├── study.yaml # study agent rules (question_asked, answer_attempted, etc.)
218
+ └── financial.yaml # financial agent rules (tiered payment authorization)
219
+ ```
220
+
221
+ Custom overrides live in `policies/custom/` and **extend (not replace)** built-ins:
222
+
223
+ ```yaml
224
+ # policies/custom/study.yaml
225
+ name: study
226
+ default: deny
227
+ rules:
228
+ # Allow a new action
229
+ - action: contact_teacher
230
+ allow: true
231
+ requires: [approved_by_student]
232
+
233
+ # Tighten: students at this school can't sync to external apps
234
+ - action: sync_to_flashcard_app
235
+ allow: false
236
+ ```
237
+
238
+ **Deny rules in `builtin/_base.yaml` are absolute** — custom policies cannot weaken them. This is the safety floor.
239
+
240
+ ### Tiered authorization example
241
+
242
+ The financial pack supports amount-based rules:
243
+
244
+ ```yaml
245
+ - action: make_payment
246
+ allow: true
247
+ requires: [approved_by_user]
248
+ when:
249
+ amount_le: 1000 # up to ₹1000 — just user approval
250
+
251
+ - action: make_payment
252
+ allow: true
253
+ requires: [approved_by_user, second_factor_verified]
254
+ when:
255
+ amount_le: 10000 # up to ₹10,000 — approval + 2FA
256
+
257
+ # Implicit: payments > ₹10,000 always denied by default
258
+ ```
259
+
260
+ ---
261
+
262
+ ## Comparison vs other agent memory systems
263
+
264
+ | | Mem0 | Zep | Letta (MemGPT) | Lasso / Pillar | **plug-play-memory** |
265
+ |---|---|---|---|---|---|
266
+ | Tiered memory | Partial | Yes | Yes | — | ✅ core/recall/archival |
267
+ | Framework-agnostic | Yes | Yes | No (LangChain) | — | ✅ MCP-native |
268
+ | Hard-enforced permissions | — | — | — | Yes (separate product) | ✅ built-in |
269
+ | Audit + coverage manifest | — | — | — | Partial | ✅ append-only, HMAC-signed |
270
+ | Self-hosted, zero infra | Depends | No (Postgres) | No (Docker) | Cloud + on-prem | ✅ one SQLite file |
271
+ | Brain-inspired consolidation | — | — | — | — | ✅ tagging + sleep + forgetting |
272
+ | Event-based capture | — | — | — | — | ✅ structured events, not chat |
273
+ | Default-deny, fail-closed | — | — | — | Partial | ✅ defense-in-depth + whitelist |
274
+ | **Cost** | Free + paid cloud | Free + paid cloud | Free + paid | Free tier + paid | **Free, runs on laptop** |
275
+
276
+ The differentiation isn't "better memory" — Letta's memory tiering is more mature. It's **memory and permissions treated as one governed system, brain-inspired consolidation, and event-based capture instead of chat extraction.**
277
+
278
+ ---
279
+
280
+ ## CLI reference
281
+
282
+ ```bash
283
+ # Initialize a project with a specific agent type
284
+ agentmemory init my-tutor --type study
285
+ agentmemory init my-coder --type coding
286
+ agentmemory init my-finance --type financial
287
+
288
+ # Run the MCP server (stdio transport)
289
+ agentmemory serve --db memory.db --config config.yaml
290
+
291
+ # Policy management
292
+ agentmemory policy list # show loaded layers
293
+ agentmemory policy show --agent-id priya --agent-type study
294
+ agentmemory policy customize study # scaffold custom override
295
+ agentmemory policy validate # validate YAML syntax
296
+
297
+ # Health check
298
+ agentmemory doctor
299
+ ```
300
+
301
+ ---
302
+
303
+ ## MCP server tools (full reference)
304
+
305
+ ### `remember_event(action, inputs, outputs, outcome, raw)`
306
+
307
+ Emit a structured event. The judge decides whether to save it.
308
+
309
+ ```python
310
+ # Examples
311
+ remember_event(
312
+ action="decision_made",
313
+ inputs={"topic": "auth"},
314
+ outputs={"choice": "JWT", "reason": "simpler"},
315
+ outcome="success",
316
+ )
317
+ ```
318
+
319
+ ### `recall(query, tier, limit)`
320
+
321
+ Retrieve memory. Returns core memory plus tier-specific results.
322
+
323
+ ```python
324
+ recall(query="auth rate limiting", tier="archival", limit=5)
325
+ recall(tier="core") # just always-injected facts
326
+ recall(tier="recall", limit=20) # recent context
327
+ ```
328
+
329
+ ### `check_permission(action, context)`
330
+
331
+ Hard enforcement gate. **Always call this before any side-effecting action.**
332
+
333
+ ```python
334
+ check_permission(action="make_payment",
335
+ context={"approved_by_user": True, "amount": 1000})
336
+ # → {allowed: True, reason: "matched rule in builtin:financial", ...}
337
+
338
+ check_permission(action="access_credentials")
339
+ # → {allowed: False, reason: "absolute deny in builtin:_base", ...}
340
+ ```
341
+
342
+ ### `forget(fact_id, hard=False)`
343
+
344
+ Soft-delete by default (preserves audit trail). Hard delete requires admin scope.
345
+
346
+ ### `audit_recent(limit)` / `coverage_manifest()`
347
+
348
+ Compliance and debugging tools.
349
+
350
+ ### `consolidate()`
351
+
352
+ Run the brain's "sleep" phase: promote reinforced tagged facts, decay the rest, prune unused.
353
+
354
+ ### `list_policies()`
355
+
356
+ Show which policy layers are loaded for the current agent.
357
+
358
+ ---
359
+
360
+ ## Security design
361
+
362
+ **`agent_id` is NEVER a tool parameter.** It comes from `AuthContext` at connection time, established from:
363
+ - Environment variables (`AGENTMEMORY_AGENT_ID`, `AGENTMEMORY_AGENT_TYPE`) for local stdio
364
+ - Auth config file with token → agent_id mapping for multi-tenant
365
+ - (Future) Bearer token from HTTP headers for remote MCP
366
+
367
+ A prompt-injected LLM **cannot** call `remember_event(agent_id="admin", ...)` because there is no `agent_id` parameter. The agent identity is established once at connection time and used for every subsequent call.
368
+
369
+ ### Audit log integrity
370
+
371
+ - **Append-only** enforced by SQLite triggers (`UPDATE` and `DELETE` both fail)
372
+ - **Hash-chained** — each entry references the previous entry's hash (tamper-evident)
373
+ - Every operation logged: `remember`, `recall`, `forget`, `permission_check`, `consolidation`, `active_forgetting`
374
+
375
+ ### Coverage manifest (not a safety claim)
376
+
377
+ `coverage_manifest()` reports **what was actually checked**, not a safety score:
378
+
379
+ ```json
380
+ {
381
+ "agent_id": "coder-1",
382
+ "actions_checked": ["write_memory", "read_memory", "access_credentials"],
383
+ "counts_by_action": {
384
+ "write_memory": {"allowed": 7, "denied": 0},
385
+ "access_credentials": {"allowed": 0, "denied": 1}
386
+ },
387
+ "total_permission_checks": 8,
388
+ "note": "Reflects only actions actually attempted — not a safety claim."
389
+ }
390
+ ```
391
+
392
+ ---
393
+
394
+ ## Self-hosted by design
395
+
396
+ Your agent's memory stays on your machine in v0.1's default configuration.
397
+
398
+ - One portable SQLite file. Back up with `cp memory.db backup.db`.
399
+ - No external database server required.
400
+ - No cloud dependency for the core system.
401
+ - **For production / regulated industries:** enable encryption at rest with `--encryption-key` (SQLCipher) and audit log signing with `--audit-key` (HMAC). See [Security](#security) below.
402
+ - Optional: cloud LLM for richer summaries (you provide your own API key, we never see it). When this lands in v0.2, only the `raw` field of events you explicitly send will be processed — core storage never leaves your machine.
403
+
404
+ **Honest scope of v0.1:** the default config is "trust the local user" — fine for OSS dev. For enterprise/regulated deployment, you must enable encryption + audit signing + use the multi-tenant token config. See `SECURITY_AUDIT_v0.1.md` for what was fixed and what's still on the roadmap.
405
+
406
+ ---
407
+
408
+ ## Roadmap
409
+
410
+ ### v0.1 (current)
411
+ - ✅ Three-tier memory (core/recall/archival)
412
+ - ✅ Layered policy engine with 4 built-in packs
413
+ - ✅ Rules + heuristics + salience judge (no LLM required)
414
+ - ✅ Brain-inspired consolidation (tagging, sleep, active forgetting)
415
+ - ✅ Append-only hash-chained audit log
416
+ - ✅ MCP server with 8 tools
417
+ - ✅ CLI with init/serve/policy/doctor commands
418
+
419
+ ### v0.2 (next)
420
+ - 🔲 Optional Ollama integration for richer summaries
421
+ - 🔲 Real sqlite-vec semantic search (currently keyword-based for zero-dependency)
422
+ - 🔲 OPA/Rego backend (currently YAML-only)
423
+ - 🔲 HTTP transport for remote MCP (currently stdio-only)
424
+ - 🔲 Web dashboard for audit log + coverage manifest
425
+
426
+ ### v0.3
427
+ - 🔲 LangGraph integration (auto-emit on state transitions)
428
+ - 🔲 CrewAI integration
429
+ - 🔲 Aider-style coding agent example
430
+ - 🔲 Benchmark suite vs Mem0/Zep/Letta
431
+
432
+ ### v1.0
433
+ - 🔲 Enterprise tier: signed policy packs, SIEM integration, SSO
434
+ - 🔲 Multi-region sync for self-hosted enterprise
435
+ - 🔲 Policy marketplace (curated, audited policy bundles)
436
+
437
+ ---
438
+
439
+ ## Limitations (honest)
440
+
441
+ - **Embeddings:** v1 uses BLAKE2b hashing as a dependency-free placeholder embedder. Swap in a real embedder via `MemoryStore(embed_fn=...)` for genuine semantic recall.
442
+ - **Vector search:** v1 uses keyword matching for archival recall. sqlite-vec integration is on the v0.2 roadmap.
443
+ - **Judge:** Rules + heuristics handle ~90% of cases correctly. The 10% it misses are saved with a `tagged` flag for review during consolidation. Optional LLM enrichment coming in v0.2.
444
+ - **Passive capture:** v1 requires explicit event emission (no automatic capture from chat). This is by design — automatic capture introduces cost and prompt-injection surface.
445
+ - **TTL:** `ttl_seconds` is stored per-fact but not yet actively swept. Active forgetting handles the equivalent cleanup.
446
+
447
+ ---
448
+
449
+ ## Contributing
450
+
451
+ PRs welcome. Especially valuable:
452
+
453
+ - More built-in policy packs (legal, healthcare, devops, customer-support)
454
+ - Integration examples (LangGraph, CrewAI, AutoGen, Aider)
455
+ - Benchmarks against Mem0/Zep/Letta
456
+ - Bug reports + reproducible test cases
457
+
458
+ See `tests/` for the existing test suite (26 unit tests + 3-agent end-to-end demo + MCP server test).
459
+
460
+ ---
461
+
462
+ ## License
463
+
464
+ Apache-2.0. Use it commercially, fork it, sell it. Just don't blame us if your agent remembers things you didn't want it to.
465
+
466
+ ---
467
+
468
+ ## Author
469
+
470
+ **Tathagat** — AI/ML engineer building systems end-to-end.
471
+
472
+ - GitHub: [@tathagat-git](https://github.com/tathagat-git)
473
+ - Twitter: [@tathagat_](https://twitter.com/tathagat_)
474
+ - LinkedIn: [tathagat-tathagat3460](https://linkedin.com/in/tathagat-tathagat3460)
475
+ - Portfolio: [tathagat-git.github.io](https://tathagat-git.github.io/)
476
+
477
+ Built while studying how the brain decides what to remember. The neuroscience parallels are real; the implementation is pragmatic Python.
478
+
479
+ ---
480
+
481
+ ## Star history
482
+
483
+ [![Star History Chart](https://api.star-history.com/svg?repos=tathagat-git/plug-play-memory&type=Date)](https://star-history.com/#tathagat-git/plug-play-memory&Date)
484
+
485
+ ---
486
+
487
+ **If this project saves you time, [star the repo](https://github.com/tathagat-git/plug-play-memory).** It's the only metric that tells me to keep building.