rootmemory 0.1.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.
- rootmemory-0.1.0/LICENSE +21 -0
- rootmemory-0.1.0/PKG-INFO +266 -0
- rootmemory-0.1.0/README.md +208 -0
- rootmemory-0.1.0/pyproject.toml +117 -0
- rootmemory-0.1.0/rootmemory/__init__.py +84 -0
- rootmemory-0.1.0/rootmemory/api/__init__.py +25 -0
- rootmemory-0.1.0/rootmemory/api/agents.py +38 -0
- rootmemory-0.1.0/rootmemory/api/beliefs.py +66 -0
- rootmemory-0.1.0/rootmemory/api/claims.py +87 -0
- rootmemory-0.1.0/rootmemory/api/deps.py +21 -0
- rootmemory-0.1.0/rootmemory/api/errors.py +36 -0
- rootmemory-0.1.0/rootmemory/api/graph.py +32 -0
- rootmemory-0.1.0/rootmemory/api/invalidation.py +47 -0
- rootmemory-0.1.0/rootmemory/api/observations.py +46 -0
- rootmemory-0.1.0/rootmemory/api/promotion.py +37 -0
- rootmemory-0.1.0/rootmemory/api/provenance.py +88 -0
- rootmemory-0.1.0/rootmemory/api/security.py +53 -0
- rootmemory-0.1.0/rootmemory/cli.py +96 -0
- rootmemory-0.1.0/rootmemory/client.py +219 -0
- rootmemory-0.1.0/rootmemory/config.py +64 -0
- rootmemory-0.1.0/rootmemory/db/__init__.py +0 -0
- rootmemory-0.1.0/rootmemory/db/base.py +42 -0
- rootmemory-0.1.0/rootmemory/db/migrations/env.py +59 -0
- rootmemory-0.1.0/rootmemory/db/migrations/script.py.mako +26 -0
- rootmemory-0.1.0/rootmemory/db/migrations/versions/d336d5cf7fb9_initial_schema.py +260 -0
- rootmemory-0.1.0/rootmemory/db/session.py +138 -0
- rootmemory-0.1.0/rootmemory/errors.py +27 -0
- rootmemory-0.1.0/rootmemory/integrations/__init__.py +16 -0
- rootmemory-0.1.0/rootmemory/integrations/async_client.py +268 -0
- rootmemory-0.1.0/rootmemory/integrations/langchain_tools.py +237 -0
- rootmemory-0.1.0/rootmemory/integrations/langgraph_memory.py +179 -0
- rootmemory-0.1.0/rootmemory/integrations/langgraph_store.py +402 -0
- rootmemory-0.1.0/rootmemory/logging_config.py +30 -0
- rootmemory-0.1.0/rootmemory/main.py +133 -0
- rootmemory-0.1.0/rootmemory/models/__init__.py +22 -0
- rootmemory-0.1.0/rootmemory/models/agent.py +30 -0
- rootmemory-0.1.0/rootmemory/models/audit.py +51 -0
- rootmemory-0.1.0/rootmemory/models/belief.py +39 -0
- rootmemory-0.1.0/rootmemory/models/claim.py +52 -0
- rootmemory-0.1.0/rootmemory/models/decision.py +38 -0
- rootmemory-0.1.0/rootmemory/models/edge.py +43 -0
- rootmemory-0.1.0/rootmemory/models/enums.py +104 -0
- rootmemory-0.1.0/rootmemory/models/node_ref.py +42 -0
- rootmemory-0.1.0/rootmemory/models/observation.py +51 -0
- rootmemory-0.1.0/rootmemory/py.typed +0 -0
- rootmemory-0.1.0/rootmemory/repositories/__init__.py +19 -0
- rootmemory-0.1.0/rootmemory/repositories/agent_repo.py +44 -0
- rootmemory-0.1.0/rootmemory/repositories/audit_repo.py +43 -0
- rootmemory-0.1.0/rootmemory/repositories/belief_repo.py +63 -0
- rootmemory-0.1.0/rootmemory/repositories/claim_repo.py +102 -0
- rootmemory-0.1.0/rootmemory/repositories/decision_repo.py +76 -0
- rootmemory-0.1.0/rootmemory/repositories/edge_repo.py +77 -0
- rootmemory-0.1.0/rootmemory/repositories/observation_repo.py +76 -0
- rootmemory-0.1.0/rootmemory/schemas/__init__.py +52 -0
- rootmemory-0.1.0/rootmemory/schemas/agent.py +26 -0
- rootmemory-0.1.0/rootmemory/schemas/belief.py +49 -0
- rootmemory-0.1.0/rootmemory/schemas/claim.py +54 -0
- rootmemory-0.1.0/rootmemory/schemas/common.py +27 -0
- rootmemory-0.1.0/rootmemory/schemas/observation.py +69 -0
- rootmemory-0.1.0/rootmemory/schemas/promotion.py +50 -0
- rootmemory-0.1.0/rootmemory/schemas/provenance.py +51 -0
- rootmemory-0.1.0/rootmemory/services/__init__.py +35 -0
- rootmemory-0.1.0/rootmemory/services/belief_service.py +161 -0
- rootmemory-0.1.0/rootmemory/services/contradiction_service.py +148 -0
- rootmemory-0.1.0/rootmemory/services/decision_service.py +65 -0
- rootmemory-0.1.0/rootmemory/services/graph_service.py +316 -0
- rootmemory-0.1.0/rootmemory/services/independence_service.py +159 -0
- rootmemory-0.1.0/rootmemory/services/invalidation_service.py +164 -0
- rootmemory-0.1.0/rootmemory/services/normalization_service.py +234 -0
- rootmemory-0.1.0/rootmemory/services/promotion_service.py +318 -0
- rootmemory-0.1.0/rootmemory/services/provenance_service.py +282 -0
- rootmemory-0.1.0/rootmemory/services/scoring_service.py +53 -0
- rootmemory-0.1.0/rootmemory/static/index.html +866 -0
- rootmemory-0.1.0/rootmemory.egg-info/PKG-INFO +266 -0
- rootmemory-0.1.0/rootmemory.egg-info/SOURCES.txt +90 -0
- rootmemory-0.1.0/rootmemory.egg-info/dependency_links.txt +1 -0
- rootmemory-0.1.0/rootmemory.egg-info/entry_points.txt +2 -0
- rootmemory-0.1.0/rootmemory.egg-info/requires.txt +40 -0
- rootmemory-0.1.0/rootmemory.egg-info/top_level.txt +1 -0
- rootmemory-0.1.0/setup.cfg +4 -0
- rootmemory-0.1.0/tests/test_api_flow.py +224 -0
- rootmemory-0.1.0/tests/test_beliefs.py +218 -0
- rootmemory-0.1.0/tests/test_contradictions.py +101 -0
- rootmemory-0.1.0/tests/test_graph_portal.py +207 -0
- rootmemory-0.1.0/tests/test_independence.py +161 -0
- rootmemory-0.1.0/tests/test_integrations.py +385 -0
- rootmemory-0.1.0/tests/test_invalidation.py +130 -0
- rootmemory-0.1.0/tests/test_langgraph_store.py +305 -0
- rootmemory-0.1.0/tests/test_observations.py +77 -0
- rootmemory-0.1.0/tests/test_production.py +345 -0
- rootmemory-0.1.0/tests/test_promotion.py +213 -0
- rootmemory-0.1.0/tests/test_scenarios.py +151 -0
rootmemory-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shubham Ambavane
|
|
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,266 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rootmemory
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Provenance-aware memory for multi-agent AI systems: tells corroboration apart from repetition
|
|
5
|
+
Author-email: Shubham Ambavane <ambavane26@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Shubs5758/RootMemory
|
|
8
|
+
Project-URL: Repository, https://github.com/Shubs5758/RootMemory
|
|
9
|
+
Project-URL: Issues, https://github.com/Shubs5758/RootMemory/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/Shubs5758/RootMemory#readme
|
|
11
|
+
Keywords: ai,agents,multi-agent,memory,provenance,langgraph,langchain,knowledge-graph,evidence
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Topic :: Database
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.12
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: sqlalchemy>=2.0
|
|
25
|
+
Requires-Dist: pydantic>=2.7
|
|
26
|
+
Requires-Dist: pydantic-settings>=2.3
|
|
27
|
+
Requires-Dist: structlog>=24.1
|
|
28
|
+
Provides-Extra: api
|
|
29
|
+
Requires-Dist: fastapi>=0.115; extra == "api"
|
|
30
|
+
Requires-Dist: uvicorn[standard]>=0.30; extra == "api"
|
|
31
|
+
Requires-Dist: alembic>=1.13; extra == "api"
|
|
32
|
+
Provides-Extra: postgres
|
|
33
|
+
Requires-Dist: psycopg[binary]>=3.1; extra == "postgres"
|
|
34
|
+
Provides-Extra: langchain
|
|
35
|
+
Requires-Dist: langchain-core>=0.3; extra == "langchain"
|
|
36
|
+
Provides-Extra: langgraph
|
|
37
|
+
Requires-Dist: langgraph>=0.2; extra == "langgraph"
|
|
38
|
+
Requires-Dist: langchain-core>=0.3; extra == "langgraph"
|
|
39
|
+
Provides-Extra: llm
|
|
40
|
+
Requires-Dist: openai>=1.30; extra == "llm"
|
|
41
|
+
Provides-Extra: all
|
|
42
|
+
Requires-Dist: fastapi>=0.115; extra == "all"
|
|
43
|
+
Requires-Dist: uvicorn[standard]>=0.30; extra == "all"
|
|
44
|
+
Requires-Dist: alembic>=1.13; extra == "all"
|
|
45
|
+
Requires-Dist: psycopg[binary]>=3.1; extra == "all"
|
|
46
|
+
Requires-Dist: langgraph>=0.2; extra == "all"
|
|
47
|
+
Requires-Dist: langchain-core>=0.3; extra == "all"
|
|
48
|
+
Requires-Dist: openai>=1.30; extra == "all"
|
|
49
|
+
Provides-Extra: dev
|
|
50
|
+
Requires-Dist: pytest>=8.2; extra == "dev"
|
|
51
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
52
|
+
Requires-Dist: httpx>=0.27; extra == "dev"
|
|
53
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
54
|
+
Requires-Dist: ruff>=0.5; extra == "dev"
|
|
55
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
56
|
+
Requires-Dist: twine>=5.1; extra == "dev"
|
|
57
|
+
Dynamic: license-file
|
|
58
|
+
|
|
59
|
+
# RootMemory
|
|
60
|
+
|
|
61
|
+
**Provenance-aware memory for multi-agent AI systems. It tells corroboration apart from repetition.**
|
|
62
|
+
|
|
63
|
+
[](https://pypi.org/project/rootmemory/)
|
|
64
|
+
[](https://pypi.org/project/rootmemory/)
|
|
65
|
+
[](LICENSE)
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install rootmemory
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## The problem
|
|
72
|
+
|
|
73
|
+
A customer writes *"we're targeting October, but the date isn't final."*
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
Agent A reads the email -> "the deadline is October 15"
|
|
77
|
+
Agent B reads Agent A -> "the deadline is October 15"
|
|
78
|
+
Agent C reads Agent B -> "the deadline is October 15"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Your shared memory now shows three agents agreeing. There is still only **one**
|
|
82
|
+
source, and it did not say that. Every belief traces back to the same email —
|
|
83
|
+
but a list of conclusions has forgotten that, so the system counts three votes
|
|
84
|
+
and acts.
|
|
85
|
+
|
|
86
|
+
RootMemory keeps those numbers apart:
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
agreeing agents 3
|
|
90
|
+
supporting beliefs 3
|
|
91
|
+
independent evidence roots 1 <- the only number that reflects reality
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Quick start
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from rootmemory import RootMemory, open_memory
|
|
98
|
+
|
|
99
|
+
with open_memory("sqlite+pysqlite:///memory.db") as session:
|
|
100
|
+
memory = RootMemory(session)
|
|
101
|
+
|
|
102
|
+
research = memory.register_agent("ResearchAgent")
|
|
103
|
+
risk = memory.register_agent("RiskAgent")
|
|
104
|
+
exec_ = memory.register_agent("DecisionAgent")
|
|
105
|
+
|
|
106
|
+
# evidence from the outside world
|
|
107
|
+
article = memory.create_observation("news", "Revenue may have slipped.")
|
|
108
|
+
|
|
109
|
+
# three agents, but only the first one read the article
|
|
110
|
+
b1 = memory.create_belief(research.id, "Supplier under pressure.", "risk", 0.6, [article])
|
|
111
|
+
b2 = memory.create_belief(risk.id, "Supplier is unstable.", "risk", 0.8, [b1])
|
|
112
|
+
b3 = memory.create_belief(exec_.id, "Significant risk.", "risk", 0.85, [b2])
|
|
113
|
+
|
|
114
|
+
claim = memory.get_or_create_claim("risk", "Supplier is in distress.")
|
|
115
|
+
for belief in (b1, b2, b3):
|
|
116
|
+
memory.support_claim(claim.id, belief.id)
|
|
117
|
+
|
|
118
|
+
verdict = memory.evaluate_claim(claim.id)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
agreeing agents 3
|
|
123
|
+
supporting beliefs 3
|
|
124
|
+
independent sources 1
|
|
125
|
+
decision REJECT
|
|
126
|
+
why 3 supporting beliefs descend from a single evidence source.
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Add a genuinely separate source and it promotes. That is the entire idea.
|
|
130
|
+
|
|
131
|
+
## How it works
|
|
132
|
+
|
|
133
|
+
Four objects, one rule.
|
|
134
|
+
|
|
135
|
+
| Object | What it is |
|
|
136
|
+
| --- | --- |
|
|
137
|
+
| **Observation** | evidence from outside. Immutable — only its validity can change. |
|
|
138
|
+
| **Belief** | what an agent concluded. Must cite what it came from. |
|
|
139
|
+
| **Claim** | a proposition beliefs support or contradict. |
|
|
140
|
+
| **Decision** | an action taken because of a claim. |
|
|
141
|
+
|
|
142
|
+
**The rule: every belief must say what it was derived from.** RootMemory refuses
|
|
143
|
+
to store one that cites nothing. That turns memory into a family tree, so any
|
|
144
|
+
belief can be walked back to the real-world evidence at the bottom.
|
|
145
|
+
|
|
146
|
+
A claim enters shared memory only through the **promotion gate**, which counts
|
|
147
|
+
independent evidence roots — never agreeing agents. Contradictions are
|
|
148
|
+
preserved rather than overwritten. And retracting a source walks *forward*
|
|
149
|
+
through everything built on it: beliefs are retracted, claims downgraded,
|
|
150
|
+
dependent decisions flagged `needs_review`.
|
|
151
|
+
|
|
152
|
+
## Plugging into a framework
|
|
153
|
+
|
|
154
|
+
The core imports no agent framework. Adapters are optional extras.
|
|
155
|
+
|
|
156
|
+
### LangChain / LangGraph long-term memory
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
pip install "rootmemory[langgraph]"
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from langchain.agents import create_agent
|
|
164
|
+
from rootmemory.integrations.langgraph_store import RootMemoryStore
|
|
165
|
+
|
|
166
|
+
agent = create_agent(model=..., tools=[...], store=RootMemoryStore(agent_id=risk_id))
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
`BaseStore.put` has nowhere to say *"here is what I read first"*, so the adapter
|
|
170
|
+
infers it: the store remembers what it served to that agent and cites it as the
|
|
171
|
+
parents of whatever it writes next. Provenance capture with no cooperation from
|
|
172
|
+
the model.
|
|
173
|
+
|
|
174
|
+
### Tools that force citation
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
from rootmemory.integrations.langchain_tools import build_tools
|
|
178
|
+
model = model.bind_tools(build_tools(memory, agent_id))
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
`derived_from` is a **required** field in the tool schema, so a model cannot
|
|
182
|
+
record an opinion without saying what it read.
|
|
183
|
+
|
|
184
|
+
### LangGraph nodes
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from rootmemory.integrations.langgraph_memory import MemoryState, remembering
|
|
188
|
+
|
|
189
|
+
graph.add_node("risk", remembering(memory, risk_id, claim_key="supplier_risk")(assess))
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
State carries belief ids, not just text — text has forgotten where it came from.
|
|
193
|
+
|
|
194
|
+
### Anything else
|
|
195
|
+
|
|
196
|
+
`AsyncRootMemory` is plain async Python with no framework types in its
|
|
197
|
+
signatures. Non-Python agents can use the REST API.
|
|
198
|
+
|
|
199
|
+
## Optional extras
|
|
200
|
+
|
|
201
|
+
| Extra | Adds |
|
|
202
|
+
| --- | --- |
|
|
203
|
+
| `rootmemory[api]` | FastAPI service, Alembic migrations, and the visual portal at `/ui` |
|
|
204
|
+
| `rootmemory[langgraph]` | LangGraph store, node wrapper, LangChain tools |
|
|
205
|
+
| `rootmemory[postgres]` | PostgreSQL driver |
|
|
206
|
+
| `rootmemory[llm]` | LLM-backed claim normalization |
|
|
207
|
+
| `rootmemory[all]` | everything |
|
|
208
|
+
|
|
209
|
+
The core depends only on SQLAlchemy, Pydantic and structlog. Importing the
|
|
210
|
+
memory engine will not drag in a web framework.
|
|
211
|
+
|
|
212
|
+
## The portal
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
pip install "rootmemory[api]"
|
|
216
|
+
rootmemory serve
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Open <http://localhost:8000/ui>. Observations form the floor and everything
|
|
220
|
+
built on them stacks above, so an echo chain renders as a tall thin tower on a
|
|
221
|
+
single foundation. Click any node to trace it back to the evidence it actually
|
|
222
|
+
came from; everything off that path dims.
|
|
223
|
+
|
|
224
|
+
## Design rules
|
|
225
|
+
|
|
226
|
+
* Every belief has at least one causal parent. No provenance, no shared memory.
|
|
227
|
+
* Observations are never edited or deleted, only marked invalid.
|
|
228
|
+
* Only the promotion service may confirm a claim.
|
|
229
|
+
* Contradictions are preserved, never overwritten.
|
|
230
|
+
* Graph cycles are refused.
|
|
231
|
+
* Agreement count and independent-evidence count are always reported separately.
|
|
232
|
+
* The core is deterministic. An LLM may write belief text; it never decides what
|
|
233
|
+
counts as evidence.
|
|
234
|
+
|
|
235
|
+
## Measured against a naive shared scratchpad
|
|
236
|
+
|
|
237
|
+
Same beliefs, same confidences, same thresholds — the baseline just has no
|
|
238
|
+
ancestry to consult.
|
|
239
|
+
|
|
240
|
+
| Metric | RootMemory | Shared scratchpad |
|
|
241
|
+
| --- | --- | --- |
|
|
242
|
+
| False corroboration rate | **0.0** | 0.25 |
|
|
243
|
+
| Wrong-action rate | **0.0** | 0.5 |
|
|
244
|
+
| Promotion precision | **1.0** | 0.5 |
|
|
245
|
+
| Repair completeness | **1.0** | 0.0 |
|
|
246
|
+
|
|
247
|
+
Cost: roughly 5–6x more rows, because the family tree is kept alongside the
|
|
248
|
+
conclusions.
|
|
249
|
+
|
|
250
|
+
## Documentation
|
|
251
|
+
|
|
252
|
+
* [Running it](docs/running.md) — step-by-step, including the demo and portal
|
|
253
|
+
* [Architecture](docs/architecture.md) — the four algorithms in detail
|
|
254
|
+
* [API reference](docs/api.md)
|
|
255
|
+
* [Deployment](docs/deployment.md) — config, auth, claim normalization, rollout
|
|
256
|
+
* [Evaluation](docs/evaluation.md) — generated benchmark results
|
|
257
|
+
|
|
258
|
+
## Status
|
|
259
|
+
|
|
260
|
+
Working, tested MVP: 144 tests, type-checked and linted. Runs on SQLite with no
|
|
261
|
+
server. PostgreSQL is supported and its migration renders correct DDL, but has
|
|
262
|
+
not yet been exercised against a live server.
|
|
263
|
+
|
|
264
|
+
## License
|
|
265
|
+
|
|
266
|
+
MIT
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# RootMemory
|
|
2
|
+
|
|
3
|
+
**Provenance-aware memory for multi-agent AI systems. It tells corroboration apart from repetition.**
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/rootmemory/)
|
|
6
|
+
[](https://pypi.org/project/rootmemory/)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install rootmemory
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## The problem
|
|
14
|
+
|
|
15
|
+
A customer writes *"we're targeting October, but the date isn't final."*
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
Agent A reads the email -> "the deadline is October 15"
|
|
19
|
+
Agent B reads Agent A -> "the deadline is October 15"
|
|
20
|
+
Agent C reads Agent B -> "the deadline is October 15"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Your shared memory now shows three agents agreeing. There is still only **one**
|
|
24
|
+
source, and it did not say that. Every belief traces back to the same email —
|
|
25
|
+
but a list of conclusions has forgotten that, so the system counts three votes
|
|
26
|
+
and acts.
|
|
27
|
+
|
|
28
|
+
RootMemory keeps those numbers apart:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
agreeing agents 3
|
|
32
|
+
supporting beliefs 3
|
|
33
|
+
independent evidence roots 1 <- the only number that reflects reality
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Quick start
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from rootmemory import RootMemory, open_memory
|
|
40
|
+
|
|
41
|
+
with open_memory("sqlite+pysqlite:///memory.db") as session:
|
|
42
|
+
memory = RootMemory(session)
|
|
43
|
+
|
|
44
|
+
research = memory.register_agent("ResearchAgent")
|
|
45
|
+
risk = memory.register_agent("RiskAgent")
|
|
46
|
+
exec_ = memory.register_agent("DecisionAgent")
|
|
47
|
+
|
|
48
|
+
# evidence from the outside world
|
|
49
|
+
article = memory.create_observation("news", "Revenue may have slipped.")
|
|
50
|
+
|
|
51
|
+
# three agents, but only the first one read the article
|
|
52
|
+
b1 = memory.create_belief(research.id, "Supplier under pressure.", "risk", 0.6, [article])
|
|
53
|
+
b2 = memory.create_belief(risk.id, "Supplier is unstable.", "risk", 0.8, [b1])
|
|
54
|
+
b3 = memory.create_belief(exec_.id, "Significant risk.", "risk", 0.85, [b2])
|
|
55
|
+
|
|
56
|
+
claim = memory.get_or_create_claim("risk", "Supplier is in distress.")
|
|
57
|
+
for belief in (b1, b2, b3):
|
|
58
|
+
memory.support_claim(claim.id, belief.id)
|
|
59
|
+
|
|
60
|
+
verdict = memory.evaluate_claim(claim.id)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
agreeing agents 3
|
|
65
|
+
supporting beliefs 3
|
|
66
|
+
independent sources 1
|
|
67
|
+
decision REJECT
|
|
68
|
+
why 3 supporting beliefs descend from a single evidence source.
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Add a genuinely separate source and it promotes. That is the entire idea.
|
|
72
|
+
|
|
73
|
+
## How it works
|
|
74
|
+
|
|
75
|
+
Four objects, one rule.
|
|
76
|
+
|
|
77
|
+
| Object | What it is |
|
|
78
|
+
| --- | --- |
|
|
79
|
+
| **Observation** | evidence from outside. Immutable — only its validity can change. |
|
|
80
|
+
| **Belief** | what an agent concluded. Must cite what it came from. |
|
|
81
|
+
| **Claim** | a proposition beliefs support or contradict. |
|
|
82
|
+
| **Decision** | an action taken because of a claim. |
|
|
83
|
+
|
|
84
|
+
**The rule: every belief must say what it was derived from.** RootMemory refuses
|
|
85
|
+
to store one that cites nothing. That turns memory into a family tree, so any
|
|
86
|
+
belief can be walked back to the real-world evidence at the bottom.
|
|
87
|
+
|
|
88
|
+
A claim enters shared memory only through the **promotion gate**, which counts
|
|
89
|
+
independent evidence roots — never agreeing agents. Contradictions are
|
|
90
|
+
preserved rather than overwritten. And retracting a source walks *forward*
|
|
91
|
+
through everything built on it: beliefs are retracted, claims downgraded,
|
|
92
|
+
dependent decisions flagged `needs_review`.
|
|
93
|
+
|
|
94
|
+
## Plugging into a framework
|
|
95
|
+
|
|
96
|
+
The core imports no agent framework. Adapters are optional extras.
|
|
97
|
+
|
|
98
|
+
### LangChain / LangGraph long-term memory
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
pip install "rootmemory[langgraph]"
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from langchain.agents import create_agent
|
|
106
|
+
from rootmemory.integrations.langgraph_store import RootMemoryStore
|
|
107
|
+
|
|
108
|
+
agent = create_agent(model=..., tools=[...], store=RootMemoryStore(agent_id=risk_id))
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`BaseStore.put` has nowhere to say *"here is what I read first"*, so the adapter
|
|
112
|
+
infers it: the store remembers what it served to that agent and cites it as the
|
|
113
|
+
parents of whatever it writes next. Provenance capture with no cooperation from
|
|
114
|
+
the model.
|
|
115
|
+
|
|
116
|
+
### Tools that force citation
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from rootmemory.integrations.langchain_tools import build_tools
|
|
120
|
+
model = model.bind_tools(build_tools(memory, agent_id))
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`derived_from` is a **required** field in the tool schema, so a model cannot
|
|
124
|
+
record an opinion without saying what it read.
|
|
125
|
+
|
|
126
|
+
### LangGraph nodes
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
from rootmemory.integrations.langgraph_memory import MemoryState, remembering
|
|
130
|
+
|
|
131
|
+
graph.add_node("risk", remembering(memory, risk_id, claim_key="supplier_risk")(assess))
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
State carries belief ids, not just text — text has forgotten where it came from.
|
|
135
|
+
|
|
136
|
+
### Anything else
|
|
137
|
+
|
|
138
|
+
`AsyncRootMemory` is plain async Python with no framework types in its
|
|
139
|
+
signatures. Non-Python agents can use the REST API.
|
|
140
|
+
|
|
141
|
+
## Optional extras
|
|
142
|
+
|
|
143
|
+
| Extra | Adds |
|
|
144
|
+
| --- | --- |
|
|
145
|
+
| `rootmemory[api]` | FastAPI service, Alembic migrations, and the visual portal at `/ui` |
|
|
146
|
+
| `rootmemory[langgraph]` | LangGraph store, node wrapper, LangChain tools |
|
|
147
|
+
| `rootmemory[postgres]` | PostgreSQL driver |
|
|
148
|
+
| `rootmemory[llm]` | LLM-backed claim normalization |
|
|
149
|
+
| `rootmemory[all]` | everything |
|
|
150
|
+
|
|
151
|
+
The core depends only on SQLAlchemy, Pydantic and structlog. Importing the
|
|
152
|
+
memory engine will not drag in a web framework.
|
|
153
|
+
|
|
154
|
+
## The portal
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
pip install "rootmemory[api]"
|
|
158
|
+
rootmemory serve
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Open <http://localhost:8000/ui>. Observations form the floor and everything
|
|
162
|
+
built on them stacks above, so an echo chain renders as a tall thin tower on a
|
|
163
|
+
single foundation. Click any node to trace it back to the evidence it actually
|
|
164
|
+
came from; everything off that path dims.
|
|
165
|
+
|
|
166
|
+
## Design rules
|
|
167
|
+
|
|
168
|
+
* Every belief has at least one causal parent. No provenance, no shared memory.
|
|
169
|
+
* Observations are never edited or deleted, only marked invalid.
|
|
170
|
+
* Only the promotion service may confirm a claim.
|
|
171
|
+
* Contradictions are preserved, never overwritten.
|
|
172
|
+
* Graph cycles are refused.
|
|
173
|
+
* Agreement count and independent-evidence count are always reported separately.
|
|
174
|
+
* The core is deterministic. An LLM may write belief text; it never decides what
|
|
175
|
+
counts as evidence.
|
|
176
|
+
|
|
177
|
+
## Measured against a naive shared scratchpad
|
|
178
|
+
|
|
179
|
+
Same beliefs, same confidences, same thresholds — the baseline just has no
|
|
180
|
+
ancestry to consult.
|
|
181
|
+
|
|
182
|
+
| Metric | RootMemory | Shared scratchpad |
|
|
183
|
+
| --- | --- | --- |
|
|
184
|
+
| False corroboration rate | **0.0** | 0.25 |
|
|
185
|
+
| Wrong-action rate | **0.0** | 0.5 |
|
|
186
|
+
| Promotion precision | **1.0** | 0.5 |
|
|
187
|
+
| Repair completeness | **1.0** | 0.0 |
|
|
188
|
+
|
|
189
|
+
Cost: roughly 5–6x more rows, because the family tree is kept alongside the
|
|
190
|
+
conclusions.
|
|
191
|
+
|
|
192
|
+
## Documentation
|
|
193
|
+
|
|
194
|
+
* [Running it](docs/running.md) — step-by-step, including the demo and portal
|
|
195
|
+
* [Architecture](docs/architecture.md) — the four algorithms in detail
|
|
196
|
+
* [API reference](docs/api.md)
|
|
197
|
+
* [Deployment](docs/deployment.md) — config, auth, claim normalization, rollout
|
|
198
|
+
* [Evaluation](docs/evaluation.md) — generated benchmark results
|
|
199
|
+
|
|
200
|
+
## Status
|
|
201
|
+
|
|
202
|
+
Working, tested MVP: 144 tests, type-checked and linted. Runs on SQLite with no
|
|
203
|
+
server. PostgreSQL is supported and its migration renders correct DDL, but has
|
|
204
|
+
not yet been exercised against a live server.
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
|
|
208
|
+
MIT
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rootmemory"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Provenance-aware memory for multi-agent AI systems: tells corroboration apart from repetition"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Shubham Ambavane", email = "ambavane26@gmail.com" }]
|
|
14
|
+
keywords = [
|
|
15
|
+
"ai",
|
|
16
|
+
"agents",
|
|
17
|
+
"multi-agent",
|
|
18
|
+
"memory",
|
|
19
|
+
"provenance",
|
|
20
|
+
"langgraph",
|
|
21
|
+
"langchain",
|
|
22
|
+
"knowledge-graph",
|
|
23
|
+
"evidence",
|
|
24
|
+
]
|
|
25
|
+
classifiers = [
|
|
26
|
+
"Development Status :: 4 - Beta",
|
|
27
|
+
"Intended Audience :: Developers",
|
|
28
|
+
"Programming Language :: Python :: 3",
|
|
29
|
+
"Programming Language :: Python :: 3.12",
|
|
30
|
+
"Programming Language :: Python :: 3.13",
|
|
31
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
32
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
33
|
+
"Topic :: Database",
|
|
34
|
+
"Typing :: Typed",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
# The core is deliberately small. FastAPI, LangGraph and PostgreSQL are all
|
|
38
|
+
# optional: importing the memory engine should not drag in a web framework.
|
|
39
|
+
dependencies = [
|
|
40
|
+
"sqlalchemy>=2.0",
|
|
41
|
+
"pydantic>=2.7",
|
|
42
|
+
"pydantic-settings>=2.3",
|
|
43
|
+
"structlog>=24.1",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
[project.optional-dependencies]
|
|
47
|
+
api = ["fastapi>=0.115", "uvicorn[standard]>=0.30", "alembic>=1.13"]
|
|
48
|
+
postgres = ["psycopg[binary]>=3.1"]
|
|
49
|
+
langchain = ["langchain-core>=0.3"]
|
|
50
|
+
langgraph = ["langgraph>=0.2", "langchain-core>=0.3"]
|
|
51
|
+
llm = ["openai>=1.30"]
|
|
52
|
+
all = [
|
|
53
|
+
"fastapi>=0.115",
|
|
54
|
+
"uvicorn[standard]>=0.30",
|
|
55
|
+
"alembic>=1.13",
|
|
56
|
+
"psycopg[binary]>=3.1",
|
|
57
|
+
"langgraph>=0.2",
|
|
58
|
+
"langchain-core>=0.3",
|
|
59
|
+
"openai>=1.30",
|
|
60
|
+
]
|
|
61
|
+
dev = [
|
|
62
|
+
"pytest>=8.2",
|
|
63
|
+
"pytest-asyncio>=0.23",
|
|
64
|
+
"httpx>=0.27",
|
|
65
|
+
"mypy>=1.10",
|
|
66
|
+
"ruff>=0.5",
|
|
67
|
+
"build>=1.2",
|
|
68
|
+
"twine>=5.1",
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
[project.urls]
|
|
72
|
+
Homepage = "https://github.com/Shubs5758/RootMemory"
|
|
73
|
+
Repository = "https://github.com/Shubs5758/RootMemory"
|
|
74
|
+
Issues = "https://github.com/Shubs5758/RootMemory/issues"
|
|
75
|
+
Documentation = "https://github.com/Shubs5758/RootMemory#readme"
|
|
76
|
+
|
|
77
|
+
[project.scripts]
|
|
78
|
+
rootmemory = "rootmemory.cli:main"
|
|
79
|
+
|
|
80
|
+
[tool.setuptools.packages.find]
|
|
81
|
+
include = ["rootmemory*"]
|
|
82
|
+
|
|
83
|
+
[tool.setuptools.package-data]
|
|
84
|
+
# The portal page and the migration scripts are loaded from disk at runtime.
|
|
85
|
+
rootmemory = ["static/*.html", "db/migrations/*.py", "db/migrations/*.mako", "db/migrations/versions/*.py", "py.typed"]
|
|
86
|
+
|
|
87
|
+
[tool.pytest.ini_options]
|
|
88
|
+
testpaths = ["tests"]
|
|
89
|
+
pythonpath = ["."]
|
|
90
|
+
addopts = "-q"
|
|
91
|
+
asyncio_mode = "auto"
|
|
92
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
93
|
+
|
|
94
|
+
[tool.mypy]
|
|
95
|
+
python_version = "3.12"
|
|
96
|
+
files = ["rootmemory", "agents", "experiments"]
|
|
97
|
+
ignore_missing_imports = true
|
|
98
|
+
warn_unused_ignores = true
|
|
99
|
+
warn_redundant_casts = true
|
|
100
|
+
disallow_untyped_defs = true
|
|
101
|
+
check_untyped_defs = true
|
|
102
|
+
|
|
103
|
+
[[tool.mypy.overrides]]
|
|
104
|
+
module = "rootmemory.db.migrations.*"
|
|
105
|
+
ignore_errors = true
|
|
106
|
+
|
|
107
|
+
[tool.ruff]
|
|
108
|
+
line-length = 100
|
|
109
|
+
target-version = "py312"
|
|
110
|
+
extend-exclude = ["rootmemory/db/migrations/versions"]
|
|
111
|
+
|
|
112
|
+
[tool.ruff.lint]
|
|
113
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
114
|
+
|
|
115
|
+
[tool.ruff.lint.per-file-ignores]
|
|
116
|
+
# Depends(...) / Query(...) in argument defaults is the FastAPI idiom.
|
|
117
|
+
"rootmemory/api/*" = ["B008"]
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""RootMemory - provenance-aware memory for multi-agent AI systems.
|
|
2
|
+
|
|
3
|
+
It tells corroboration apart from repetition. Every belief records what it was
|
|
4
|
+
derived from, so three agents echoing one document are counted as one piece of
|
|
5
|
+
evidence rather than three.
|
|
6
|
+
|
|
7
|
+
Quick start::
|
|
8
|
+
|
|
9
|
+
from rootmemory import RootMemory, open_memory
|
|
10
|
+
|
|
11
|
+
with open_memory("sqlite+pysqlite:///memory.db") as session:
|
|
12
|
+
memory = RootMemory(session)
|
|
13
|
+
agent = memory.register_agent("ResearchAgent")
|
|
14
|
+
|
|
15
|
+
article = memory.create_observation("news", "Revenue may have slipped.")
|
|
16
|
+
belief = memory.create_belief(
|
|
17
|
+
agent.id, "The supplier is struggling.", "supplier_risk", 0.6,
|
|
18
|
+
derived_from=[article], # required: cite what you read
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
claim = memory.get_or_create_claim("supplier_risk", "Supplier is struggling.")
|
|
22
|
+
memory.support_claim(claim.id, belief.id)
|
|
23
|
+
|
|
24
|
+
verdict = memory.evaluate_claim(claim.id)
|
|
25
|
+
print(verdict.independent_support_count) # 1, not 3
|
|
26
|
+
print(verdict.explanation)
|
|
27
|
+
|
|
28
|
+
The async client and the framework adapters live in ``rootmemory.integrations``
|
|
29
|
+
and are imported on demand, so nothing here pulls in FastAPI or LangGraph.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
from __future__ import annotations
|
|
33
|
+
|
|
34
|
+
from rootmemory.client import RootMemory
|
|
35
|
+
from rootmemory.db.session import create_isolated_session, open_memory, session_scope
|
|
36
|
+
from rootmemory.errors import (
|
|
37
|
+
ImmutableRecordError,
|
|
38
|
+
NodeNotFoundError,
|
|
39
|
+
PromotionForbiddenError,
|
|
40
|
+
ProvenanceCycleError,
|
|
41
|
+
ProvenanceRequiredError,
|
|
42
|
+
RootMemoryError,
|
|
43
|
+
)
|
|
44
|
+
from rootmemory.models.enums import (
|
|
45
|
+
ClaimStatus,
|
|
46
|
+
DecisionStatus,
|
|
47
|
+
EdgeType,
|
|
48
|
+
EpistemicStatus,
|
|
49
|
+
NodeType,
|
|
50
|
+
ValidityStatus,
|
|
51
|
+
Visibility,
|
|
52
|
+
)
|
|
53
|
+
from rootmemory.models.node_ref import NodeRef
|
|
54
|
+
from rootmemory.services.promotion_service import PromotionEvaluation, PromotionPolicy
|
|
55
|
+
|
|
56
|
+
__version__ = "0.1.0"
|
|
57
|
+
|
|
58
|
+
__all__ = [
|
|
59
|
+
# the client you will actually use
|
|
60
|
+
"RootMemory",
|
|
61
|
+
"open_memory",
|
|
62
|
+
"session_scope",
|
|
63
|
+
"create_isolated_session",
|
|
64
|
+
# the promotion policy and its verdict
|
|
65
|
+
"PromotionPolicy",
|
|
66
|
+
"PromotionEvaluation",
|
|
67
|
+
# errors worth catching
|
|
68
|
+
"RootMemoryError",
|
|
69
|
+
"NodeNotFoundError",
|
|
70
|
+
"ProvenanceRequiredError",
|
|
71
|
+
"ProvenanceCycleError",
|
|
72
|
+
"ImmutableRecordError",
|
|
73
|
+
"PromotionForbiddenError",
|
|
74
|
+
# vocabulary
|
|
75
|
+
"NodeRef",
|
|
76
|
+
"NodeType",
|
|
77
|
+
"EdgeType",
|
|
78
|
+
"ValidityStatus",
|
|
79
|
+
"EpistemicStatus",
|
|
80
|
+
"Visibility",
|
|
81
|
+
"ClaimStatus",
|
|
82
|
+
"DecisionStatus",
|
|
83
|
+
"__version__",
|
|
84
|
+
]
|