agent-memory-engine 0.1.0__py3-none-any.whl

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 (39) hide show
  1. agent_memory/__init__.py +33 -0
  2. agent_memory/cli.py +142 -0
  3. agent_memory/client.py +355 -0
  4. agent_memory/config.py +28 -0
  5. agent_memory/controller/__init__.py +15 -0
  6. agent_memory/controller/conflict.py +95 -0
  7. agent_memory/controller/consolidation.py +136 -0
  8. agent_memory/controller/forgetting.py +29 -0
  9. agent_memory/controller/router.py +62 -0
  10. agent_memory/controller/trust.py +31 -0
  11. agent_memory/embedding/__init__.py +5 -0
  12. agent_memory/embedding/base.py +11 -0
  13. agent_memory/embedding/local_provider.py +38 -0
  14. agent_memory/embedding/openai_provider.py +11 -0
  15. agent_memory/extraction/__init__.py +5 -0
  16. agent_memory/extraction/entity_extractor.py +13 -0
  17. agent_memory/extraction/pipeline.py +123 -0
  18. agent_memory/extraction/prompts.py +40 -0
  19. agent_memory/governance/__init__.py +6 -0
  20. agent_memory/governance/audit.py +14 -0
  21. agent_memory/governance/export.py +72 -0
  22. agent_memory/governance/health.py +40 -0
  23. agent_memory/interfaces/__init__.py +14 -0
  24. agent_memory/interfaces/mcp_server.py +128 -0
  25. agent_memory/interfaces/rest_api.py +71 -0
  26. agent_memory/llm/__init__.py +5 -0
  27. agent_memory/llm/base.py +23 -0
  28. agent_memory/llm/ollama_client.py +64 -0
  29. agent_memory/llm/openai_client.py +94 -0
  30. agent_memory/models.py +149 -0
  31. agent_memory/storage/__init__.py +4 -0
  32. agent_memory/storage/base.py +59 -0
  33. agent_memory/storage/schema.sql +125 -0
  34. agent_memory/storage/sqlite_backend.py +762 -0
  35. agent_memory_engine-0.1.0.dist-info/METADATA +228 -0
  36. agent_memory_engine-0.1.0.dist-info/RECORD +39 -0
  37. agent_memory_engine-0.1.0.dist-info/WHEEL +4 -0
  38. agent_memory_engine-0.1.0.dist-info/entry_points.txt +2 -0
  39. agent_memory_engine-0.1.0.dist-info/licenses/LICENSE +22 -0
@@ -0,0 +1,228 @@
1
+ Metadata-Version: 2.4
2
+ Name: agent-memory-engine
3
+ Version: 0.1.0
4
+ Summary: Zero-config, traceable, MCP-native long-term memory for agents.
5
+ Project-URL: Homepage, https://github.com/xjf/agent-memory
6
+ Project-URL: Repository, https://github.com/xjf/agent-memory
7
+ Project-URL: Issues, https://github.com/xjf/agent-memory/issues
8
+ Project-URL: Documentation, https://github.com/xjf/agent-memory/tree/main/docs
9
+ Author: xjf
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: agent,llm,mcp,memory,rag,sqlite
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Database
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: sentence-transformers>=3.0.0
25
+ Requires-Dist: sqlite-vec>=0.1.0
26
+ Provides-Extra: api
27
+ Requires-Dist: fastapi>=0.115.0; extra == 'api'
28
+ Requires-Dist: uvicorn>=0.30.0; extra == 'api'
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
31
+ Provides-Extra: mcp
32
+ Requires-Dist: fastmcp>=2.0.0; extra == 'mcp'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # agent-memory
36
+
37
+ ![CI](https://github.com/xjf/agent-memory/actions/workflows/ci.yml/badge.svg)
38
+ ![Python](https://img.shields.io/badge/python-3.10%2B-blue)
39
+ ![License](https://img.shields.io/badge/license-MIT-green)
40
+
41
+ Zero-config, traceable, MCP-native long-term memory for agents.
42
+
43
+ `agent-memory` targets a gap in the current memory stack: a local-first engine that works with `pip install`, runs on pure SQLite, and makes memory evolution explainable instead of opaque.
44
+
45
+ PyPI distribution name: `agent-memory-engine`
46
+
47
+ ## Why this exists
48
+
49
+ - `Mem0` proves demand, but pulls in heavier infra such as Neo4j or Qdrant.
50
+ - Local agents and personal copilots need a memory layer that is easy to embed, debug, export, and ship.
51
+ - Interviews love this surface area: storage, retrieval, ranking, decay, provenance, conflict handling, MCP, and evaluation.
52
+
53
+ ## Current Status
54
+
55
+ - SQLite backend with WAL, FTS5, audit log, evolution log, entity index, and causal parent links
56
+ - Schema indexes for type, layer, recency, trust, source, relation, and audit hot paths
57
+ - Python SDK via `MemoryClient`
58
+ - Rule-based intent router with Reciprocal Rank Fusion
59
+ - Adaptive forgetting utilities with dual-threshold layer transitions
60
+ - Heuristic conflict detection with contradiction edges and trust-score adjustment
61
+ - Optional LLM-backed conflict adjudication for top semantic candidates
62
+ - Governance helpers for health reports, audit reads, and JSONL export/import
63
+ - Optional MCP server and REST API adapters with dependency-friendly fallbacks
64
+ - `sqlite-vec` integration with safe fallback to Python cosine scan when unavailable
65
+ - Deterministic local fallback embeddings for testability and zero-friction startup
66
+ - LLM-first conversation extraction with heuristic fallback
67
+ - Trace graph reports with ancestors, descendants, relations, and evolution history
68
+ - Idempotent maintenance cycle for decay, promotion/demotion, conflict upkeep, and consolidation
69
+ - Benchmark helpers and LOCOMO-Lite style starter data
70
+
71
+ ## Quickstart
72
+
73
+ ```bash
74
+ pip install -e .[dev]
75
+ .venv/bin/python -m pytest -q
76
+ ```
77
+
78
+ ```bash
79
+ agent-memory store "User prefers SQLite for local-first agents." --source-id demo
80
+ agent-memory search "Why SQLite?"
81
+ agent-memory health
82
+ ```
83
+
84
+ ```python
85
+ from agent_memory import MemoryClient
86
+
87
+ client = MemoryClient()
88
+ item = client.add(
89
+ "The user prefers SQLite for local-first agent projects.",
90
+ source_id="demo-session",
91
+ )
92
+
93
+ results = client.search("What database does the user prefer?")
94
+ print(results[0].item.content)
95
+
96
+ trace = client.trace_graph(item.id)
97
+ print(trace.descendants)
98
+
99
+ health = client.health()
100
+ print(health.suggestions)
101
+ ```
102
+
103
+ ## Architecture
104
+
105
+ ```mermaid
106
+ graph TD
107
+ A["Python SDK / CLI"] --> B["MemoryClient"]
108
+ C["MCP Server"] --> B
109
+ D["REST API"] --> B
110
+ B --> E["Intent Router"]
111
+ B --> F["Conflict Detector"]
112
+ B --> G["Trust Scorer"]
113
+ B --> H["Forgetting Engine"]
114
+ E --> I["SQLite Backend"]
115
+ F --> I
116
+ G --> I
117
+ H --> I
118
+ I --> J[("SQLite + FTS5 + sqlite-vec")]
119
+ ```
120
+
121
+ ### Core components
122
+
123
+ - `src/agent_memory/client.py` — high-level SDK entry point
124
+ - `src/agent_memory/storage/sqlite_backend.py` — SQLite persistence, FTS, vector fallback, trace queries
125
+ - `src/agent_memory/controller/router.py` — intent-aware retrieval routing and RRF fusion
126
+ - `src/agent_memory/controller/forgetting.py` — Ebbinghaus-inspired adaptive forgetting
127
+ - `src/agent_memory/controller/conflict.py` — contradiction detection and conflict records
128
+ - `src/agent_memory/controller/consolidation.py` — overlap grouping and merge-draft generation
129
+ - `src/agent_memory/controller/trust.py` — multi-factor trust scoring
130
+ - `src/agent_memory/governance/health.py` — stale/orphan/conflict monitoring
131
+ - `src/agent_memory/interfaces/mcp_server.py` — eight MCP tools
132
+ - `src/agent_memory/extraction/pipeline.py` — conversation-to-memory extraction
133
+ - `benchmarks/` — storage/retrieval microbenchmarks and synthetic eval seeds
134
+
135
+ ### Design choices
136
+
137
+ - **SQLite + WAL** keeps deployment zero-config while fitting agent workloads: many reads, occasional writes.
138
+ - **Rule routing over LLM routing** keeps routing latency predictable and testable.
139
+ - **RRF instead of score averaging** avoids calibration problems across lexical, entity, and semantic retrieval.
140
+ - **`sqlite-vec` plus fallback** gives C/SQL vector search when available while keeping the package runnable everywhere.
141
+ - **Soft delete** preserves provenance and causal trace integrity.
142
+ - **Hash fallback embeddings** make the package runnable even before a local embedding model is available.
143
+ - **Unique relation edges** keep maintenance idempotent and health metrics stable.
144
+
145
+ ## Project layout
146
+
147
+ ```text
148
+ agent-memory/
149
+ ├── docs/plans/
150
+ ├── examples/
151
+ ├── src/agent_memory/
152
+ │ ├── controller/
153
+ │ ├── embedding/
154
+ │ ├── extraction/
155
+ │ └── storage/
156
+ └── tests/
157
+ ```
158
+
159
+ ## Benchmarks
160
+
161
+ Synthetic LOCOMO-Lite run on the bundled starter dataset (`30` dialogues / `150` questions):
162
+
163
+ | Metric | `agent-memory` | Semantic-only baseline |
164
+ |--------|----------------|------------------------|
165
+ | Overall hit rate | 50.0% | 23.3% |
166
+ | Factual recall | 53.3% | 6.7% |
167
+ | Temporal recall | 36.7% | 3.3% |
168
+ | Causal recall | 53.3% | 6.7% |
169
+ | p95 retrieval latency | 16.64ms | 11.50ms |
170
+
171
+ - Full report: `docs/benchmark-results.md`
172
+ - Re-run locally: `python benchmarks/locomo_lite/evaluate.py`
173
+
174
+ ## MCP Usage
175
+
176
+ Install MCP support and launch the stdio server:
177
+
178
+ ```bash
179
+ pip install -e .[mcp]
180
+ python -m agent_memory.interfaces.mcp_server
181
+ ```
182
+
183
+ Claude Desktop configuration:
184
+
185
+ ```json
186
+ {
187
+ "mcpServers": {
188
+ "agent-memory": {
189
+ "command": "python",
190
+ "args": ["-m", "agent_memory.interfaces.mcp_server"],
191
+ "env": {
192
+ "AGENT_MEMORY_DB_PATH": "/absolute/path/to/default.db"
193
+ }
194
+ }
195
+ }
196
+ }
197
+ ```
198
+
199
+ Typical tools:
200
+
201
+ - `memory_store` — store a memory with provenance
202
+ - `memory_search` — run intent-aware retrieval
203
+ - `memory_trace` — inspect causal ancestry and evolution
204
+ - `memory_health` — inspect stale/conflict/orphan metrics
205
+
206
+ More details: `docs/mcp-integration.md`
207
+
208
+ ## Demos
209
+
210
+ - `python examples/demo_cross_session.py --db /tmp/agent-memory-demo.db`
211
+ - `python examples/interactive_chat.py --db chat_memory.db --provider none`
212
+ - `python examples/mcp_server.py`
213
+
214
+ ## Release Notes
215
+
216
+ - `benchmarks/locomo_lite/latest_results.json` is regenerated by the evaluation script
217
+ - `docs/screenshots/` is reserved for verified MCP client screenshots
218
+ - Update GitHub URLs if you publish under a different org/user
219
+ - Delivery record and full tutorial: `docs/project-delivery-and-tutorial.md`
220
+ - Expansion and optimization review: `docs/plans/2026-03-24-agent-memory-expansion-review.md`
221
+
222
+ ## Dev Notes
223
+
224
+ - Run all tests with `.venv/bin/python -m pytest -q`
225
+ - Use the built-in CLI with `agent-memory --help`
226
+ - `sqlite-vec` is installed as a package dependency; if the extension cannot be loaded at runtime, vector search safely falls back to Python cosine scan
227
+ - Try microbenchmarks with `python benchmarks/bench_storage.py` and `python benchmarks/bench_retrieval.py`
228
+ - Try the demo runner with `python examples/benchmark_runner.py`
@@ -0,0 +1,39 @@
1
+ agent_memory/__init__.py,sha256=HSRX66pMcisGFsAoue6Nzb_hrMxxzU9jQHUTt0d4_WU,628
2
+ agent_memory/cli.py,sha256=A2cAo3Iszuq3QHTwRMGBrIyTcVRkginWjfcVNZzZ0PI,4876
3
+ agent_memory/client.py,sha256=sYcmFpWTMwwE7WoEYZsqyysQR0O7EK2hp0urq6j1Ctc,15033
4
+ agent_memory/config.py,sha256=NfKljannY0E8aYnleQSGfLQbCJcnT4j7qgt4N7ozfkw,1087
5
+ agent_memory/models.py,sha256=K8mPuei4V0_IXV7Rmt9SP5B-FmEqI0j7C_Ko5FTeNE4,3589
6
+ agent_memory/controller/__init__.py,sha256=WHJ-LdBeHavDUUmTQkQX5LSuWfuC1yIXvoxneHC-VuY,492
7
+ agent_memory/controller/conflict.py,sha256=zlzHAkkL8_YYflEtZkG0zWoLkpm8v1rFztE-6d9hEmE,4407
8
+ agent_memory/controller/consolidation.py,sha256=38IYe47V9XjtG6SCTQv4S1MRKLR-TSRy70AajwhXkOs,5714
9
+ agent_memory/controller/forgetting.py,sha256=PXI10uWxhUPYJ0BhYHgWk8Jovx2tVgAs8UgqU0tslhc,1091
10
+ agent_memory/controller/router.py,sha256=h-zIkcAhj8jntGCIwq9JPgY1dz971CI5llH_O2STk0o,2641
11
+ agent_memory/controller/trust.py,sha256=2q9IjNpso50U3WHgOZeAjXJWKQJAPwuVWwDPRbM81tg,957
12
+ agent_memory/embedding/__init__.py,sha256=Y1GMnUPHmJk1QPm1c2NvBUO42D9ARYmOf8_2v9cfTpQ,214
13
+ agent_memory/embedding/base.py,sha256=jcBBce1tGvtzUjQHs9bo0amyOXQEsqoYch5leY2Eb2c,194
14
+ agent_memory/embedding/local_provider.py,sha256=L5UPrpsvWmbBscfysvDtM6qEC7o6vHuJLCgBYSmYIqk,1315
15
+ agent_memory/embedding/openai_provider.py,sha256=F49P0lNtluHnUpup4kFkyV4YSKgLau-Sve3mQcbumVU,396
16
+ agent_memory/extraction/__init__.py,sha256=eYdqLD6jlG0xvdYl-XoV3wCOrh4q9q9Z0SiQZSbOU-A,203
17
+ agent_memory/extraction/entity_extractor.py,sha256=p0fIt9_O3D4sU-z_QQeL66isTPbtnhc5J7fdy-hdHQU,419
18
+ agent_memory/extraction/pipeline.py,sha256=p4Ka16sxdgPOcM2Ri09YItlNqTA9SrdOC4GBitU9GUA,5390
19
+ agent_memory/extraction/prompts.py,sha256=1BvWGGtgjA6JazTHFy05-NCc7LWfNZ-hYzH68Q5E-E8,982
20
+ agent_memory/governance/__init__.py,sha256=xWEvh7SHKVVaX8r7Tbqnev3G75JhPAP7zQ9Oh6GMrto,284
21
+ agent_memory/governance/audit.py,sha256=jrzeGmHCU9O0qBv5DDwfmGTbi-vuYBEtOR4l0RH1r5o,333
22
+ agent_memory/governance/export.py,sha256=vZCnsX4o6VDNcT4QXkE4ZPSU8NJikULpYhTM9xG6-MA,3036
23
+ agent_memory/governance/health.py,sha256=uBSahLc_ETOn84-oN5lVh1STg0q4rwt5GMHEcl7Qeg0,1500
24
+ agent_memory/interfaces/__init__.py,sha256=NWqq_EEUk26Hp30TloUXoz5KhzpA1T55AE93vc9Qpug,495
25
+ agent_memory/interfaces/mcp_server.py,sha256=BC4msAyftAUa-qmSV6LXExlCrT2HiixNfT6WQPzOEHs,4370
26
+ agent_memory/interfaces/rest_api.py,sha256=FCDyG2QS_Zx0Ghz6PeoFNCqEQzJitUPPIaSdUv8oJU4,2626
27
+ agent_memory/llm/__init__.py,sha256=L5ZNMHgemLOmtToBu7SHXRRedC6wPyHYsI1U6UUrDWg,157
28
+ agent_memory/llm/base.py,sha256=PsjyJo_MMFoZLUALH3mjHi4-AkXFNHRHhbErJdgog_Q,460
29
+ agent_memory/llm/ollama_client.py,sha256=-jOcBz7TA5vC8GkOWr7cgdH1nxEXP-5Bbtg6OdPZPRU,2208
30
+ agent_memory/llm/openai_client.py,sha256=gSUC0tWkfTgrbmVDbiNcAWH6Sm3ZwcQsC8sKYSkgDR4,3479
31
+ agent_memory/storage/__init__.py,sha256=1XCHKO9y34HLHDaccq_9qOanGid88zOJe1JvFXBVuAA,92
32
+ agent_memory/storage/base.py,sha256=Nt4eUT2ji59bT0bAUxIdoQvafXrh0GtePA6muiwPPD0,1624
33
+ agent_memory/storage/schema.sql,sha256=cUCEh3kOrBWFEm3Xxblir8HOID4BymzznPxvFqzJuGA,4542
34
+ agent_memory/storage/sqlite_backend.py,sha256=lNPnhSNz19CSx-3vo00IMYn3X1sAQLSRRezoSvjRing,29565
35
+ agent_memory_engine-0.1.0.dist-info/METADATA,sha256=ttZd-4YS4YtBVNFzd0mr6D55McyZRv0zsk83-38iIE4,8509
36
+ agent_memory_engine-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
37
+ agent_memory_engine-0.1.0.dist-info/entry_points.txt,sha256=mG_BjBbd8UY1fAkTlcl2sByYvElm35FtvqUziRuI96Q,55
38
+ agent_memory_engine-0.1.0.dist-info/licenses/LICENSE,sha256=75nagrRO1dKma_9mUWD0yXjDVoDPTTYKduoP9kp_Ums,1061
39
+ agent_memory_engine-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ agent-memory = agent_memory.cli:main
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 xjf
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.
22
+