supermemory-agent 0.2.3__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.
- supermemory_agent-0.2.3/.claude/skills/supermemory-agent-learning/SKILL.md +157 -0
- supermemory_agent-0.2.3/.claude/skills/supermemory-agent-learning/examples.md +84 -0
- supermemory_agent-0.2.3/.claude/skills/supermemory-agent-learning/reference.md +86 -0
- supermemory_agent-0.2.3/.cursor/skills/supermemory-agent-learning/SKILL.md +157 -0
- supermemory_agent-0.2.3/.cursor/skills/supermemory-agent-learning/examples.md +84 -0
- supermemory_agent-0.2.3/.cursor/skills/supermemory-agent-learning/reference.md +86 -0
- supermemory_agent-0.2.3/.env.example +7 -0
- supermemory_agent-0.2.3/.github/workflows/publish.yml +55 -0
- supermemory_agent-0.2.3/.gitignore +13 -0
- supermemory_agent-0.2.3/.mcp.json +11 -0
- supermemory_agent-0.2.3/LICENSE +21 -0
- supermemory_agent-0.2.3/PKG-INFO +170 -0
- supermemory_agent-0.2.3/README.md +132 -0
- supermemory_agent-0.2.3/api/openapi.yaml +41 -0
- supermemory_agent-0.2.3/docker-compose.yml +27 -0
- supermemory_agent-0.2.3/docs/PUBLISHING.md +167 -0
- supermemory_agent-0.2.3/examples/claude_desktop_config.json +19 -0
- supermemory_agent-0.2.3/examples/cursor.mcp.json +11 -0
- supermemory_agent-0.2.3/examples/cursor_mcp/mcp.json +13 -0
- supermemory_agent-0.2.3/examples/mcp_agents/agents/ocr_worker.md +17 -0
- supermemory_agent-0.2.3/examples/mcp_agents/agents/orchestrator.md +26 -0
- supermemory_agent-0.2.3/examples/mcp_agents/agents/planner.md +26 -0
- supermemory_agent-0.2.3/examples/mcp_agents/multi_agent_mcp.py +88 -0
- supermemory_agent-0.2.3/examples/mcp_agents/run_md_agents.py +149 -0
- supermemory_agent-0.2.3/examples/mcp_agents/single_agent_mcp.py +60 -0
- supermemory_agent-0.2.3/examples/mcp_agents/skill_guided_mcp.py +107 -0
- supermemory_agent-0.2.3/examples/multi_agent_orchestrator/demo.py +97 -0
- supermemory_agent-0.2.3/packages/uall/__init__.py +0 -0
- supermemory_agent-0.2.3/packages/uall/analytics/service.py +35 -0
- supermemory_agent-0.2.3/packages/uall/collector/__init__.py +0 -0
- supermemory_agent-0.2.3/packages/uall/collector/service.py +100 -0
- supermemory_agent-0.2.3/packages/uall/distillation/distiller.py +80 -0
- supermemory_agent-0.2.3/packages/uall/evaluation/engine.py +38 -0
- supermemory_agent-0.2.3/packages/uall/experiments/manager.py +83 -0
- supermemory_agent-0.2.3/packages/uall/memory/__init__.py +0 -0
- supermemory_agent-0.2.3/packages/uall/memory/confidence.py +36 -0
- supermemory_agent-0.2.3/packages/uall/memory/freshness.py +28 -0
- supermemory_agent-0.2.3/packages/uall/memory/graph.py +24 -0
- supermemory_agent-0.2.3/packages/uall/memory/namespaces.py +40 -0
- supermemory_agent-0.2.3/packages/uall/memory/policies.py +44 -0
- supermemory_agent-0.2.3/packages/uall/memory/provenance.py +23 -0
- supermemory_agent-0.2.3/packages/uall/memory/pruning.py +55 -0
- supermemory_agent-0.2.3/packages/uall/memory/retrieval.py +98 -0
- supermemory_agent-0.2.3/packages/uall/memory/ttl.py +22 -0
- supermemory_agent-0.2.3/packages/uall/memory/validator.py +144 -0
- supermemory_agent-0.2.3/packages/uall/optimization/optimizers.py +59 -0
- supermemory_agent-0.2.3/packages/uall/promotion/queue.py +107 -0
- supermemory_agent-0.2.3/packages/uall/recommendations/engine.py +66 -0
- supermemory_agent-0.2.3/packages/uall/reflection/engine.py +72 -0
- supermemory_agent-0.2.3/packages/uall/rollback/manager.py +49 -0
- supermemory_agent-0.2.3/packages/uall/service.py +572 -0
- supermemory_agent-0.2.3/packages/uall/skills/library.py +19 -0
- supermemory_agent-0.2.3/packages/uall/telemetry/retrieval.py +40 -0
- supermemory_agent-0.2.3/packages/uall_core/__init__.py +0 -0
- supermemory_agent-0.2.3/packages/uall_core/ports/storage.py +71 -0
- supermemory_agent-0.2.3/packages/uall_core/providers/heuristic.py +58 -0
- supermemory_agent-0.2.3/packages/uall_core/providers/llm.py +6 -0
- supermemory_agent-0.2.3/packages/uall_core/schemas/__init__.py +0 -0
- supermemory_agent-0.2.3/packages/uall_core/schemas/common.py +73 -0
- supermemory_agent-0.2.3/packages/uall_core/schemas/events.py +75 -0
- supermemory_agent-0.2.3/packages/uall_core/schemas/graph.py +32 -0
- supermemory_agent-0.2.3/packages/uall_core/schemas/lesson.py +109 -0
- supermemory_agent-0.2.3/packages/uall_core/schemas/namespace.py +76 -0
- supermemory_agent-0.2.3/packages/uall_python/__init__.py +3 -0
- supermemory_agent-0.2.3/packages/uall_python/client.py +337 -0
- supermemory_agent-0.2.3/packages/uall_server/__init__.py +0 -0
- supermemory_agent-0.2.3/packages/uall_server/main.py +284 -0
- supermemory_agent-0.2.3/pyproject.toml +67 -0
- supermemory_agent-0.2.3/scripts/sync_skills.py +38 -0
- supermemory_agent-0.2.3/server.json +36 -0
- supermemory_agent-0.2.3/skills/README.md +54 -0
- supermemory_agent-0.2.3/skills/supermemory-agent-learning/SKILL.md +157 -0
- supermemory_agent-0.2.3/skills/supermemory-agent-learning/examples.md +84 -0
- supermemory_agent-0.2.3/skills/supermemory-agent-learning/reference.md +86 -0
- supermemory_agent-0.2.3/src/supermemory_mcp/__init__.py +5 -0
- supermemory_agent-0.2.3/src/supermemory_mcp/bridge.py +35 -0
- supermemory_agent-0.2.3/src/supermemory_mcp/handlers.py +772 -0
- supermemory_agent-0.2.3/src/supermemory_mcp/server.py +522 -0
- supermemory_agent-0.2.3/src/supermemory_mcp/text.py +16 -0
- supermemory_agent-0.2.3/storage/adapters/__init__.py +0 -0
- supermemory_agent-0.2.3/storage/adapters/file.py +397 -0
- supermemory_agent-0.2.3/storage/adapters/postgres_qdrant_redis.py +32 -0
- supermemory_agent-0.2.3/storage/adapters/sqlite_chroma.py +95 -0
- supermemory_agent-0.2.3/tests/conftest.py +6 -0
- supermemory_agent-0.2.3/tests/run_all.py +45 -0
- supermemory_agent-0.2.3/tests/test_core.py +135 -0
- supermemory_agent-0.2.3/tests/test_mcp.py +169 -0
- supermemory_agent-0.2.3/tests/test_mcp_comprehensive.py +583 -0
- supermemory_agent-0.2.3/tests/test_mcp_rest_parity.py +192 -0
- supermemory_agent-0.2.3/tests/test_mcp_server.py +136 -0
- supermemory_agent-0.2.3/tests/test_registry.py +29 -0
- supermemory_agent-0.2.3/tests/test_uall.py +161 -0
- supermemory_agent-0.2.3/uall_mcp/__init__.py +0 -0
- supermemory_agent-0.2.3/uall_mcp/client.py +68 -0
- supermemory_agent-0.2.3/uall_mcp/handlers.py +25 -0
- supermemory_agent-0.2.3/uall_mcp/server.py +13 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: supermemory-agent-learning
|
|
3
|
+
description: >-
|
|
4
|
+
Build and integrate SuperMemory — MCP-first agent learning for Claude, Cursor,
|
|
5
|
+
and custom orchestrators. Use when implementing selective memory capture,
|
|
6
|
+
evidence-first reflection, lesson validation, promotion queues, retrieval
|
|
7
|
+
telemetry, experiments, rollback, or wiring SuperMemory via MCP, REST, or SDK.
|
|
8
|
+
Trigger on SuperMemory, agent learning layer, distilled lessons, or MCP memory.
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# SuperMemory — Agent Learning Layer
|
|
12
|
+
|
|
13
|
+
## Core principle (never violate)
|
|
14
|
+
|
|
15
|
+
SuperMemory is **not** full observability. Capture **workflow outcomes and distilled lessons only** — never full conversation transcripts.
|
|
16
|
+
|
|
17
|
+
| Capture | When |
|
|
18
|
+
|---------|------|
|
|
19
|
+
| Workflow snapshot | Run start/end |
|
|
20
|
+
| Failure / correction / suggestion | Significant events only |
|
|
21
|
+
| Distilled lesson | After reflect(event_ids) → validate → process_promotions |
|
|
22
|
+
|
|
23
|
+
**Token budget at retrieval:** default `max_tokens=800`. Store lessons, not histories.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Architecture (closed loop)
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
retrieve → record_failure → reflect(event_ids) → validate → process_promotions
|
|
31
|
+
→ retrieve again → report_outcome
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Critical gates:** Memory Validator (reject/merge/rewrite/approve) and Promotion Queue (no immediate store without validation).
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Project layout
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
src/supermemory_mcp/ # FastMCP server (13 core + 16 learn.* tools, MCP resources)
|
|
42
|
+
packages/uall/ # UALL engine (validator, promotion, retrieval, experiments)
|
|
43
|
+
packages/uall_server/ # FastAPI REST
|
|
44
|
+
packages/uall_python/ # Python SDK
|
|
45
|
+
storage/adapters/ # file (.supermemory/), sqlite, postgres
|
|
46
|
+
skills/ # canonical agent skills (this file)
|
|
47
|
+
examples/ # MCP configs + agent demos
|
|
48
|
+
tests/ # 69 tests incl. real stdio MCP transport
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Entry point: `packages/uall/service.py` (`UALLService`).
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## When to use which interface
|
|
56
|
+
|
|
57
|
+
| Context | Use |
|
|
58
|
+
|---------|-----|
|
|
59
|
+
| Claude / Cursor agents | MCP — `python -m supermemory_mcp.server` |
|
|
60
|
+
| Python agent in-process | `UALLClient` from `uall_python` |
|
|
61
|
+
| Remote / polyglot | REST — `python -m uall_server` (port 8000) |
|
|
62
|
+
| Tests | `python -m pytest tests/ -v` |
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Integration workflow (agent developer)
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
- [ ] 1. retrieve — policies + lessons before the step (stage-aware)
|
|
70
|
+
- [ ] 2. record_failure / record_correction — selective events only
|
|
71
|
+
- [ ] 3. reflect(event_ids) — evidence-first, never free-text-only
|
|
72
|
+
- [ ] 4. validate → process_promotions — explicit promotion step
|
|
73
|
+
- [ ] 5. retrieve again on next run
|
|
74
|
+
- [ ] 6. report_outcome — telemetry recalibrates confidence
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### MCP pattern (Claude / Cursor)
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
record_failure(summary="...", workflow="pdf-pipeline", step="planner")
|
|
81
|
+
reflect(event_ids=[...], suggestion="inspect text layer first")
|
|
82
|
+
validate(reflection_id=...)
|
|
83
|
+
process_promotions()
|
|
84
|
+
retrieve(query="PDF routing", step="planner")
|
|
85
|
+
report_outcome(lesson_id=..., used=true, accepted=true, improved=true)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### SDK pattern
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from uall_python import UALLClient
|
|
92
|
+
|
|
93
|
+
client = UALLClient(storage="file")
|
|
94
|
+
|
|
95
|
+
with client.run(workflow_id="pdf-pipeline", step="planner", namespace="team:eng") as run:
|
|
96
|
+
lessons = run.retrieve(step="planner", query="PDF routing", max_tokens=800)
|
|
97
|
+
run.record_failure(snippet="chose OCR for searchable PDF", tags=["routing"])
|
|
98
|
+
if lessons:
|
|
99
|
+
run.report_lesson_outcome(
|
|
100
|
+
lesson_id=lessons[0]["lesson_id"],
|
|
101
|
+
used=True, accepted=True, improved=True,
|
|
102
|
+
)
|
|
103
|
+
run.end(success=True)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## MCP tools (29 total)
|
|
109
|
+
|
|
110
|
+
**Core (13):** `retrieve`, `record_event`, `record_failure`, `record_correction`, `reflect`, `validate`, `process_promotions`, `report_outcome`, `get_policies`, `add_policy`, `add_skill`, `search_skills`, `get_skill`
|
|
111
|
+
|
|
112
|
+
**Extended (16):** `learn.run.start`, `learn.run.event`, `learn.run.end`, `learn.store`, `learn.retrieve`, `learn.reflect`, `learn.validate`, `learn.evaluate`, `learn.feedback`, `learn.improvements`, `learn.analytics`, `learn.policies`, `learn.experiment`, `learn.rollback`, `learn.skills`, `learn.telemetry`
|
|
113
|
+
|
|
114
|
+
**MCP resources:** `supermemory://policies/active`, `supermemory://lessons/{id}`, `supermemory://memory/{id}/provenance`, `supermemory://skills/{id}`
|
|
115
|
+
|
|
116
|
+
Config: `examples/cursor.mcp.json` or `examples/claude_desktop_config.json`
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Storage
|
|
121
|
+
|
|
122
|
+
| Tier | Env | Path |
|
|
123
|
+
|------|-----|------|
|
|
124
|
+
| File (default) | `SUPERMEMORY_STORAGE_PATH` | `.supermemory/` |
|
|
125
|
+
| SQLite | `UALL_STORAGE_BACKEND=sqlite` | local DB |
|
|
126
|
+
| Postgres | `UALL_STORAGE_BACKEND=postgres` | enterprise stub |
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Verification
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
pip install -e ".[dev]"
|
|
134
|
+
python -m pytest tests/ -q
|
|
135
|
+
python -m pytest tests/test_mcp_server.py -v
|
|
136
|
+
python examples/mcp_agents/run_md_agents.py
|
|
137
|
+
python -m supermemory_mcp.server --storage .supermemory --transport stdio
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Anti-patterns
|
|
143
|
+
|
|
144
|
+
- Recording every LLM turn or full transcripts
|
|
145
|
+
- reflect without event_ids (hallucinated lessons)
|
|
146
|
+
- Storing lessons without validate + process_promotions
|
|
147
|
+
- Skipping report_outcome (breaks confidence recalibration)
|
|
148
|
+
- Semantic-only retrieval (must filter by step/workflow/namespace)
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Additional resources
|
|
153
|
+
|
|
154
|
+
- Integration examples: [examples.md](examples.md)
|
|
155
|
+
- Module deep-dive: [reference.md](reference.md)
|
|
156
|
+
- API spec: [api/openapi.yaml](../../api/openapi.yaml)
|
|
157
|
+
- Skill install paths: [skills/README.md](../README.md)
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# SuperMemory Integration Examples
|
|
2
|
+
|
|
3
|
+
## Example 1: MCP closed loop (Claude / Cursor)
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
record_failure(summary="Planner skipped schema validation", workflow="sql-pipeline", step="planner")
|
|
7
|
+
reflect(event_ids=[...], suggestion="check schema constraints before SQL generation")
|
|
8
|
+
validate(reflection_id=...)
|
|
9
|
+
process_promotions()
|
|
10
|
+
retrieve(query="SQL planner schema", workflow="sql-pipeline", step="planner")
|
|
11
|
+
report_outcome(lesson_id=..., used=true, accepted=true, improved=true)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Example 2: Cursor MCP config
|
|
15
|
+
|
|
16
|
+
Copy `examples/cursor.mcp.json` to `.cursor/mcp.json`:
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"mcpServers": {
|
|
21
|
+
"supermemory": {
|
|
22
|
+
"command": "python",
|
|
23
|
+
"args": ["-m", "supermemory_mcp.server", "--storage", ".supermemory", "--transport", "stdio"],
|
|
24
|
+
"env": {
|
|
25
|
+
"PYTHONPATH": "${workspaceFolder}/src;${workspaceFolder}/packages;${workspaceFolder}",
|
|
26
|
+
"SUPERMEMORY_STORAGE_PATH": ".supermemory"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Example 3: Claude Desktop MCP config
|
|
34
|
+
|
|
35
|
+
Merge `examples/claude_desktop_config.json` into:
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
%APPDATA%\Claude\claude_desktop_config.json
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Restart Claude Desktop after editing.
|
|
42
|
+
|
|
43
|
+
## Example 4: Claude Code project skill
|
|
44
|
+
|
|
45
|
+
Skill is at `.claude/skills/supermemory-agent-learning/`.
|
|
46
|
+
Canonical source: `skills/supermemory-agent-learning/` (sync with `python scripts/sync_skills.py`).
|
|
47
|
+
|
|
48
|
+
## Example 5: SDK multi-step run
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from uall_python import UALLClient
|
|
52
|
+
|
|
53
|
+
client = UALLClient(storage="file")
|
|
54
|
+
|
|
55
|
+
with client.run(workflow_id="rag-pipeline", step="planner", namespace="team:ml") as run:
|
|
56
|
+
lessons = run.retrieve(step="planner", query=state["task"])
|
|
57
|
+
if state.get("failed"):
|
|
58
|
+
run.record_failure(snippet=state["error"], agent="planner")
|
|
59
|
+
run.end(success=not state.get("failed"))
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Example 6: Remote REST
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
import httpx
|
|
66
|
+
|
|
67
|
+
headers = {"X-UALL-Key": "dev-key-change-me"}
|
|
68
|
+
r = httpx.post("http://localhost:8000/memory/search", headers=headers, json={
|
|
69
|
+
"query": "SQL join errors",
|
|
70
|
+
"step": "generator",
|
|
71
|
+
"workflow": "sql-pipeline",
|
|
72
|
+
"max_tokens": 800,
|
|
73
|
+
})
|
|
74
|
+
lessons = r.json()
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Example 7: Org policy via MCP
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
add_policy(rule="Never expose secrets", namespace="organization:default")
|
|
81
|
+
get_policies()
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Policies are injected before lessons on every `retrieve` call.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# SuperMemory Module Reference
|
|
2
|
+
|
|
3
|
+
## Lesson schema (stored artifact)
|
|
4
|
+
|
|
5
|
+
```json
|
|
6
|
+
{
|
|
7
|
+
"lesson_id": "lesson_abc123",
|
|
8
|
+
"failure": "chose OCR for searchable PDF",
|
|
9
|
+
"root_cause": "did not inspect text layer",
|
|
10
|
+
"fix": "Inspect PDF text layer first; use OCR only for scanned documents",
|
|
11
|
+
"confidence": {
|
|
12
|
+
"evidence": 0.85,
|
|
13
|
+
"retrieval_success": 0.72,
|
|
14
|
+
"human_verified": false,
|
|
15
|
+
"overall": 0.78
|
|
16
|
+
},
|
|
17
|
+
"provenance": {
|
|
18
|
+
"run_id": "run_xyz",
|
|
19
|
+
"reflection_id": "reflection_91",
|
|
20
|
+
"event_ids": ["event_abc"],
|
|
21
|
+
"policy_version": "security_policy:v1"
|
|
22
|
+
},
|
|
23
|
+
"stage": {
|
|
24
|
+
"workflow": "pdf-pipeline",
|
|
25
|
+
"step": "planner"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Validator actions
|
|
31
|
+
|
|
32
|
+
| Action | Next step |
|
|
33
|
+
|--------|-----------|
|
|
34
|
+
| `reject` | Discard — never store |
|
|
35
|
+
| `merge` | Merge into existing lesson |
|
|
36
|
+
| `rewrite` | Tighten fix text, then approve |
|
|
37
|
+
| `approve` | Enqueue to promotion queue |
|
|
38
|
+
|
|
39
|
+
## Promotion flow
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
validate (approve) → pending queue → process_promotions → active lesson
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Never call `process_promotions` inside `reflect` — keep steps explicit for agents.
|
|
46
|
+
|
|
47
|
+
## Retrieval pipeline
|
|
48
|
+
|
|
49
|
+
1. Policies (injected first, not ranked)
|
|
50
|
+
2. Namespace + metadata filter
|
|
51
|
+
3. Vector similarity
|
|
52
|
+
4. Rerank by composite score
|
|
53
|
+
5. Freshness + confidence weighting
|
|
54
|
+
6. Token budget trim (default 800)
|
|
55
|
+
|
|
56
|
+
## File storage layout (`.supermemory/`)
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
.supermemory/
|
|
60
|
+
├── events/ # indexed evidence events
|
|
61
|
+
├── lessons/ # promoted lessons
|
|
62
|
+
├── pending/ # awaiting promotion
|
|
63
|
+
├── telemetry/ # retrieval outcomes
|
|
64
|
+
├── policies/ # versioned org policies
|
|
65
|
+
├── reflections/ # pre-validation candidates
|
|
66
|
+
└── skills/ # reusable workflow blocks
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Key modules
|
|
70
|
+
|
|
71
|
+
| Module | Path |
|
|
72
|
+
|--------|------|
|
|
73
|
+
| UALLService | `packages/uall/service.py` |
|
|
74
|
+
| MCP handlers | `src/supermemory_mcp/handlers.py` |
|
|
75
|
+
| FastMCP server | `src/supermemory_mcp/server.py` |
|
|
76
|
+
| Validator | `packages/uall/memory/validator.py` |
|
|
77
|
+
| Promotion queue | `packages/uall/promotion/queue.py` |
|
|
78
|
+
| Retrieval | `packages/uall/memory/retrieval.py` |
|
|
79
|
+
| Telemetry | `packages/uall/telemetry/retrieval.py` |
|
|
80
|
+
|
|
81
|
+
## Testing checklist
|
|
82
|
+
|
|
83
|
+
- [ ] `python -m pytest tests/test_core.py` — GitHub-compatible loop
|
|
84
|
+
- [ ] `python -m pytest tests/test_mcp_server.py` — real stdio MCP
|
|
85
|
+
- [ ] `python examples/mcp_agents/run_md_agents.py` — markdown agents
|
|
86
|
+
- [ ] Evidence-first: reflect rejects missing event_ids
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: supermemory-agent-learning
|
|
3
|
+
description: >-
|
|
4
|
+
Build and integrate SuperMemory — MCP-first agent learning for Claude, Cursor,
|
|
5
|
+
and custom orchestrators. Use when implementing selective memory capture,
|
|
6
|
+
evidence-first reflection, lesson validation, promotion queues, retrieval
|
|
7
|
+
telemetry, experiments, rollback, or wiring SuperMemory via MCP, REST, or SDK.
|
|
8
|
+
Trigger on SuperMemory, agent learning layer, distilled lessons, or MCP memory.
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# SuperMemory — Agent Learning Layer
|
|
12
|
+
|
|
13
|
+
## Core principle (never violate)
|
|
14
|
+
|
|
15
|
+
SuperMemory is **not** full observability. Capture **workflow outcomes and distilled lessons only** — never full conversation transcripts.
|
|
16
|
+
|
|
17
|
+
| Capture | When |
|
|
18
|
+
|---------|------|
|
|
19
|
+
| Workflow snapshot | Run start/end |
|
|
20
|
+
| Failure / correction / suggestion | Significant events only |
|
|
21
|
+
| Distilled lesson | After reflect(event_ids) → validate → process_promotions |
|
|
22
|
+
|
|
23
|
+
**Token budget at retrieval:** default `max_tokens=800`. Store lessons, not histories.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Architecture (closed loop)
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
retrieve → record_failure → reflect(event_ids) → validate → process_promotions
|
|
31
|
+
→ retrieve again → report_outcome
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Critical gates:** Memory Validator (reject/merge/rewrite/approve) and Promotion Queue (no immediate store without validation).
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Project layout
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
src/supermemory_mcp/ # FastMCP server (13 core + 16 learn.* tools, MCP resources)
|
|
42
|
+
packages/uall/ # UALL engine (validator, promotion, retrieval, experiments)
|
|
43
|
+
packages/uall_server/ # FastAPI REST
|
|
44
|
+
packages/uall_python/ # Python SDK
|
|
45
|
+
storage/adapters/ # file (.supermemory/), sqlite, postgres
|
|
46
|
+
skills/ # canonical agent skills (this file)
|
|
47
|
+
examples/ # MCP configs + agent demos
|
|
48
|
+
tests/ # 69 tests incl. real stdio MCP transport
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Entry point: `packages/uall/service.py` (`UALLService`).
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## When to use which interface
|
|
56
|
+
|
|
57
|
+
| Context | Use |
|
|
58
|
+
|---------|-----|
|
|
59
|
+
| Claude / Cursor agents | MCP — `python -m supermemory_mcp.server` |
|
|
60
|
+
| Python agent in-process | `UALLClient` from `uall_python` |
|
|
61
|
+
| Remote / polyglot | REST — `python -m uall_server` (port 8000) |
|
|
62
|
+
| Tests | `python -m pytest tests/ -v` |
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Integration workflow (agent developer)
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
- [ ] 1. retrieve — policies + lessons before the step (stage-aware)
|
|
70
|
+
- [ ] 2. record_failure / record_correction — selective events only
|
|
71
|
+
- [ ] 3. reflect(event_ids) — evidence-first, never free-text-only
|
|
72
|
+
- [ ] 4. validate → process_promotions — explicit promotion step
|
|
73
|
+
- [ ] 5. retrieve again on next run
|
|
74
|
+
- [ ] 6. report_outcome — telemetry recalibrates confidence
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### MCP pattern (Claude / Cursor)
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
record_failure(summary="...", workflow="pdf-pipeline", step="planner")
|
|
81
|
+
reflect(event_ids=[...], suggestion="inspect text layer first")
|
|
82
|
+
validate(reflection_id=...)
|
|
83
|
+
process_promotions()
|
|
84
|
+
retrieve(query="PDF routing", step="planner")
|
|
85
|
+
report_outcome(lesson_id=..., used=true, accepted=true, improved=true)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### SDK pattern
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from uall_python import UALLClient
|
|
92
|
+
|
|
93
|
+
client = UALLClient(storage="file")
|
|
94
|
+
|
|
95
|
+
with client.run(workflow_id="pdf-pipeline", step="planner", namespace="team:eng") as run:
|
|
96
|
+
lessons = run.retrieve(step="planner", query="PDF routing", max_tokens=800)
|
|
97
|
+
run.record_failure(snippet="chose OCR for searchable PDF", tags=["routing"])
|
|
98
|
+
if lessons:
|
|
99
|
+
run.report_lesson_outcome(
|
|
100
|
+
lesson_id=lessons[0]["lesson_id"],
|
|
101
|
+
used=True, accepted=True, improved=True,
|
|
102
|
+
)
|
|
103
|
+
run.end(success=True)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## MCP tools (29 total)
|
|
109
|
+
|
|
110
|
+
**Core (13):** `retrieve`, `record_event`, `record_failure`, `record_correction`, `reflect`, `validate`, `process_promotions`, `report_outcome`, `get_policies`, `add_policy`, `add_skill`, `search_skills`, `get_skill`
|
|
111
|
+
|
|
112
|
+
**Extended (16):** `learn.run.start`, `learn.run.event`, `learn.run.end`, `learn.store`, `learn.retrieve`, `learn.reflect`, `learn.validate`, `learn.evaluate`, `learn.feedback`, `learn.improvements`, `learn.analytics`, `learn.policies`, `learn.experiment`, `learn.rollback`, `learn.skills`, `learn.telemetry`
|
|
113
|
+
|
|
114
|
+
**MCP resources:** `supermemory://policies/active`, `supermemory://lessons/{id}`, `supermemory://memory/{id}/provenance`, `supermemory://skills/{id}`
|
|
115
|
+
|
|
116
|
+
Config: `examples/cursor.mcp.json` or `examples/claude_desktop_config.json`
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Storage
|
|
121
|
+
|
|
122
|
+
| Tier | Env | Path |
|
|
123
|
+
|------|-----|------|
|
|
124
|
+
| File (default) | `SUPERMEMORY_STORAGE_PATH` | `.supermemory/` |
|
|
125
|
+
| SQLite | `UALL_STORAGE_BACKEND=sqlite` | local DB |
|
|
126
|
+
| Postgres | `UALL_STORAGE_BACKEND=postgres` | enterprise stub |
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Verification
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
pip install -e ".[dev]"
|
|
134
|
+
python -m pytest tests/ -q
|
|
135
|
+
python -m pytest tests/test_mcp_server.py -v
|
|
136
|
+
python examples/mcp_agents/run_md_agents.py
|
|
137
|
+
python -m supermemory_mcp.server --storage .supermemory --transport stdio
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Anti-patterns
|
|
143
|
+
|
|
144
|
+
- Recording every LLM turn or full transcripts
|
|
145
|
+
- reflect without event_ids (hallucinated lessons)
|
|
146
|
+
- Storing lessons without validate + process_promotions
|
|
147
|
+
- Skipping report_outcome (breaks confidence recalibration)
|
|
148
|
+
- Semantic-only retrieval (must filter by step/workflow/namespace)
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Additional resources
|
|
153
|
+
|
|
154
|
+
- Integration examples: [examples.md](examples.md)
|
|
155
|
+
- Module deep-dive: [reference.md](reference.md)
|
|
156
|
+
- API spec: [api/openapi.yaml](../../api/openapi.yaml)
|
|
157
|
+
- Skill install paths: [skills/README.md](../README.md)
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# SuperMemory Integration Examples
|
|
2
|
+
|
|
3
|
+
## Example 1: MCP closed loop (Claude / Cursor)
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
record_failure(summary="Planner skipped schema validation", workflow="sql-pipeline", step="planner")
|
|
7
|
+
reflect(event_ids=[...], suggestion="check schema constraints before SQL generation")
|
|
8
|
+
validate(reflection_id=...)
|
|
9
|
+
process_promotions()
|
|
10
|
+
retrieve(query="SQL planner schema", workflow="sql-pipeline", step="planner")
|
|
11
|
+
report_outcome(lesson_id=..., used=true, accepted=true, improved=true)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Example 2: Cursor MCP config
|
|
15
|
+
|
|
16
|
+
Copy `examples/cursor.mcp.json` to `.cursor/mcp.json`:
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"mcpServers": {
|
|
21
|
+
"supermemory": {
|
|
22
|
+
"command": "python",
|
|
23
|
+
"args": ["-m", "supermemory_mcp.server", "--storage", ".supermemory", "--transport", "stdio"],
|
|
24
|
+
"env": {
|
|
25
|
+
"PYTHONPATH": "${workspaceFolder}/src;${workspaceFolder}/packages;${workspaceFolder}",
|
|
26
|
+
"SUPERMEMORY_STORAGE_PATH": ".supermemory"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Example 3: Claude Desktop MCP config
|
|
34
|
+
|
|
35
|
+
Merge `examples/claude_desktop_config.json` into:
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
%APPDATA%\Claude\claude_desktop_config.json
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Restart Claude Desktop after editing.
|
|
42
|
+
|
|
43
|
+
## Example 4: Claude Code project skill
|
|
44
|
+
|
|
45
|
+
Skill is at `.claude/skills/supermemory-agent-learning/`.
|
|
46
|
+
Canonical source: `skills/supermemory-agent-learning/` (sync with `python scripts/sync_skills.py`).
|
|
47
|
+
|
|
48
|
+
## Example 5: SDK multi-step run
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from uall_python import UALLClient
|
|
52
|
+
|
|
53
|
+
client = UALLClient(storage="file")
|
|
54
|
+
|
|
55
|
+
with client.run(workflow_id="rag-pipeline", step="planner", namespace="team:ml") as run:
|
|
56
|
+
lessons = run.retrieve(step="planner", query=state["task"])
|
|
57
|
+
if state.get("failed"):
|
|
58
|
+
run.record_failure(snippet=state["error"], agent="planner")
|
|
59
|
+
run.end(success=not state.get("failed"))
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Example 6: Remote REST
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
import httpx
|
|
66
|
+
|
|
67
|
+
headers = {"X-UALL-Key": "dev-key-change-me"}
|
|
68
|
+
r = httpx.post("http://localhost:8000/memory/search", headers=headers, json={
|
|
69
|
+
"query": "SQL join errors",
|
|
70
|
+
"step": "generator",
|
|
71
|
+
"workflow": "sql-pipeline",
|
|
72
|
+
"max_tokens": 800,
|
|
73
|
+
})
|
|
74
|
+
lessons = r.json()
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Example 7: Org policy via MCP
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
add_policy(rule="Never expose secrets", namespace="organization:default")
|
|
81
|
+
get_policies()
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Policies are injected before lessons on every `retrieve` call.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# SuperMemory Module Reference
|
|
2
|
+
|
|
3
|
+
## Lesson schema (stored artifact)
|
|
4
|
+
|
|
5
|
+
```json
|
|
6
|
+
{
|
|
7
|
+
"lesson_id": "lesson_abc123",
|
|
8
|
+
"failure": "chose OCR for searchable PDF",
|
|
9
|
+
"root_cause": "did not inspect text layer",
|
|
10
|
+
"fix": "Inspect PDF text layer first; use OCR only for scanned documents",
|
|
11
|
+
"confidence": {
|
|
12
|
+
"evidence": 0.85,
|
|
13
|
+
"retrieval_success": 0.72,
|
|
14
|
+
"human_verified": false,
|
|
15
|
+
"overall": 0.78
|
|
16
|
+
},
|
|
17
|
+
"provenance": {
|
|
18
|
+
"run_id": "run_xyz",
|
|
19
|
+
"reflection_id": "reflection_91",
|
|
20
|
+
"event_ids": ["event_abc"],
|
|
21
|
+
"policy_version": "security_policy:v1"
|
|
22
|
+
},
|
|
23
|
+
"stage": {
|
|
24
|
+
"workflow": "pdf-pipeline",
|
|
25
|
+
"step": "planner"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Validator actions
|
|
31
|
+
|
|
32
|
+
| Action | Next step |
|
|
33
|
+
|--------|-----------|
|
|
34
|
+
| `reject` | Discard — never store |
|
|
35
|
+
| `merge` | Merge into existing lesson |
|
|
36
|
+
| `rewrite` | Tighten fix text, then approve |
|
|
37
|
+
| `approve` | Enqueue to promotion queue |
|
|
38
|
+
|
|
39
|
+
## Promotion flow
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
validate (approve) → pending queue → process_promotions → active lesson
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Never call `process_promotions` inside `reflect` — keep steps explicit for agents.
|
|
46
|
+
|
|
47
|
+
## Retrieval pipeline
|
|
48
|
+
|
|
49
|
+
1. Policies (injected first, not ranked)
|
|
50
|
+
2. Namespace + metadata filter
|
|
51
|
+
3. Vector similarity
|
|
52
|
+
4. Rerank by composite score
|
|
53
|
+
5. Freshness + confidence weighting
|
|
54
|
+
6. Token budget trim (default 800)
|
|
55
|
+
|
|
56
|
+
## File storage layout (`.supermemory/`)
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
.supermemory/
|
|
60
|
+
├── events/ # indexed evidence events
|
|
61
|
+
├── lessons/ # promoted lessons
|
|
62
|
+
├── pending/ # awaiting promotion
|
|
63
|
+
├── telemetry/ # retrieval outcomes
|
|
64
|
+
├── policies/ # versioned org policies
|
|
65
|
+
├── reflections/ # pre-validation candidates
|
|
66
|
+
└── skills/ # reusable workflow blocks
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Key modules
|
|
70
|
+
|
|
71
|
+
| Module | Path |
|
|
72
|
+
|--------|------|
|
|
73
|
+
| UALLService | `packages/uall/service.py` |
|
|
74
|
+
| MCP handlers | `src/supermemory_mcp/handlers.py` |
|
|
75
|
+
| FastMCP server | `src/supermemory_mcp/server.py` |
|
|
76
|
+
| Validator | `packages/uall/memory/validator.py` |
|
|
77
|
+
| Promotion queue | `packages/uall/promotion/queue.py` |
|
|
78
|
+
| Retrieval | `packages/uall/memory/retrieval.py` |
|
|
79
|
+
| Telemetry | `packages/uall/telemetry/retrieval.py` |
|
|
80
|
+
|
|
81
|
+
## Testing checklist
|
|
82
|
+
|
|
83
|
+
- [ ] `python -m pytest tests/test_core.py` — GitHub-compatible loop
|
|
84
|
+
- [ ] `python -m pytest tests/test_mcp_server.py` — real stdio MCP
|
|
85
|
+
- [ ] `python examples/mcp_agents/run_md_agents.py` — markdown agents
|
|
86
|
+
- [ ] Evidence-first: reflect rejects missing event_ids
|