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.
Files changed (96) hide show
  1. supermemory_agent-0.2.3/.claude/skills/supermemory-agent-learning/SKILL.md +157 -0
  2. supermemory_agent-0.2.3/.claude/skills/supermemory-agent-learning/examples.md +84 -0
  3. supermemory_agent-0.2.3/.claude/skills/supermemory-agent-learning/reference.md +86 -0
  4. supermemory_agent-0.2.3/.cursor/skills/supermemory-agent-learning/SKILL.md +157 -0
  5. supermemory_agent-0.2.3/.cursor/skills/supermemory-agent-learning/examples.md +84 -0
  6. supermemory_agent-0.2.3/.cursor/skills/supermemory-agent-learning/reference.md +86 -0
  7. supermemory_agent-0.2.3/.env.example +7 -0
  8. supermemory_agent-0.2.3/.github/workflows/publish.yml +55 -0
  9. supermemory_agent-0.2.3/.gitignore +13 -0
  10. supermemory_agent-0.2.3/.mcp.json +11 -0
  11. supermemory_agent-0.2.3/LICENSE +21 -0
  12. supermemory_agent-0.2.3/PKG-INFO +170 -0
  13. supermemory_agent-0.2.3/README.md +132 -0
  14. supermemory_agent-0.2.3/api/openapi.yaml +41 -0
  15. supermemory_agent-0.2.3/docker-compose.yml +27 -0
  16. supermemory_agent-0.2.3/docs/PUBLISHING.md +167 -0
  17. supermemory_agent-0.2.3/examples/claude_desktop_config.json +19 -0
  18. supermemory_agent-0.2.3/examples/cursor.mcp.json +11 -0
  19. supermemory_agent-0.2.3/examples/cursor_mcp/mcp.json +13 -0
  20. supermemory_agent-0.2.3/examples/mcp_agents/agents/ocr_worker.md +17 -0
  21. supermemory_agent-0.2.3/examples/mcp_agents/agents/orchestrator.md +26 -0
  22. supermemory_agent-0.2.3/examples/mcp_agents/agents/planner.md +26 -0
  23. supermemory_agent-0.2.3/examples/mcp_agents/multi_agent_mcp.py +88 -0
  24. supermemory_agent-0.2.3/examples/mcp_agents/run_md_agents.py +149 -0
  25. supermemory_agent-0.2.3/examples/mcp_agents/single_agent_mcp.py +60 -0
  26. supermemory_agent-0.2.3/examples/mcp_agents/skill_guided_mcp.py +107 -0
  27. supermemory_agent-0.2.3/examples/multi_agent_orchestrator/demo.py +97 -0
  28. supermemory_agent-0.2.3/packages/uall/__init__.py +0 -0
  29. supermemory_agent-0.2.3/packages/uall/analytics/service.py +35 -0
  30. supermemory_agent-0.2.3/packages/uall/collector/__init__.py +0 -0
  31. supermemory_agent-0.2.3/packages/uall/collector/service.py +100 -0
  32. supermemory_agent-0.2.3/packages/uall/distillation/distiller.py +80 -0
  33. supermemory_agent-0.2.3/packages/uall/evaluation/engine.py +38 -0
  34. supermemory_agent-0.2.3/packages/uall/experiments/manager.py +83 -0
  35. supermemory_agent-0.2.3/packages/uall/memory/__init__.py +0 -0
  36. supermemory_agent-0.2.3/packages/uall/memory/confidence.py +36 -0
  37. supermemory_agent-0.2.3/packages/uall/memory/freshness.py +28 -0
  38. supermemory_agent-0.2.3/packages/uall/memory/graph.py +24 -0
  39. supermemory_agent-0.2.3/packages/uall/memory/namespaces.py +40 -0
  40. supermemory_agent-0.2.3/packages/uall/memory/policies.py +44 -0
  41. supermemory_agent-0.2.3/packages/uall/memory/provenance.py +23 -0
  42. supermemory_agent-0.2.3/packages/uall/memory/pruning.py +55 -0
  43. supermemory_agent-0.2.3/packages/uall/memory/retrieval.py +98 -0
  44. supermemory_agent-0.2.3/packages/uall/memory/ttl.py +22 -0
  45. supermemory_agent-0.2.3/packages/uall/memory/validator.py +144 -0
  46. supermemory_agent-0.2.3/packages/uall/optimization/optimizers.py +59 -0
  47. supermemory_agent-0.2.3/packages/uall/promotion/queue.py +107 -0
  48. supermemory_agent-0.2.3/packages/uall/recommendations/engine.py +66 -0
  49. supermemory_agent-0.2.3/packages/uall/reflection/engine.py +72 -0
  50. supermemory_agent-0.2.3/packages/uall/rollback/manager.py +49 -0
  51. supermemory_agent-0.2.3/packages/uall/service.py +572 -0
  52. supermemory_agent-0.2.3/packages/uall/skills/library.py +19 -0
  53. supermemory_agent-0.2.3/packages/uall/telemetry/retrieval.py +40 -0
  54. supermemory_agent-0.2.3/packages/uall_core/__init__.py +0 -0
  55. supermemory_agent-0.2.3/packages/uall_core/ports/storage.py +71 -0
  56. supermemory_agent-0.2.3/packages/uall_core/providers/heuristic.py +58 -0
  57. supermemory_agent-0.2.3/packages/uall_core/providers/llm.py +6 -0
  58. supermemory_agent-0.2.3/packages/uall_core/schemas/__init__.py +0 -0
  59. supermemory_agent-0.2.3/packages/uall_core/schemas/common.py +73 -0
  60. supermemory_agent-0.2.3/packages/uall_core/schemas/events.py +75 -0
  61. supermemory_agent-0.2.3/packages/uall_core/schemas/graph.py +32 -0
  62. supermemory_agent-0.2.3/packages/uall_core/schemas/lesson.py +109 -0
  63. supermemory_agent-0.2.3/packages/uall_core/schemas/namespace.py +76 -0
  64. supermemory_agent-0.2.3/packages/uall_python/__init__.py +3 -0
  65. supermemory_agent-0.2.3/packages/uall_python/client.py +337 -0
  66. supermemory_agent-0.2.3/packages/uall_server/__init__.py +0 -0
  67. supermemory_agent-0.2.3/packages/uall_server/main.py +284 -0
  68. supermemory_agent-0.2.3/pyproject.toml +67 -0
  69. supermemory_agent-0.2.3/scripts/sync_skills.py +38 -0
  70. supermemory_agent-0.2.3/server.json +36 -0
  71. supermemory_agent-0.2.3/skills/README.md +54 -0
  72. supermemory_agent-0.2.3/skills/supermemory-agent-learning/SKILL.md +157 -0
  73. supermemory_agent-0.2.3/skills/supermemory-agent-learning/examples.md +84 -0
  74. supermemory_agent-0.2.3/skills/supermemory-agent-learning/reference.md +86 -0
  75. supermemory_agent-0.2.3/src/supermemory_mcp/__init__.py +5 -0
  76. supermemory_agent-0.2.3/src/supermemory_mcp/bridge.py +35 -0
  77. supermemory_agent-0.2.3/src/supermemory_mcp/handlers.py +772 -0
  78. supermemory_agent-0.2.3/src/supermemory_mcp/server.py +522 -0
  79. supermemory_agent-0.2.3/src/supermemory_mcp/text.py +16 -0
  80. supermemory_agent-0.2.3/storage/adapters/__init__.py +0 -0
  81. supermemory_agent-0.2.3/storage/adapters/file.py +397 -0
  82. supermemory_agent-0.2.3/storage/adapters/postgres_qdrant_redis.py +32 -0
  83. supermemory_agent-0.2.3/storage/adapters/sqlite_chroma.py +95 -0
  84. supermemory_agent-0.2.3/tests/conftest.py +6 -0
  85. supermemory_agent-0.2.3/tests/run_all.py +45 -0
  86. supermemory_agent-0.2.3/tests/test_core.py +135 -0
  87. supermemory_agent-0.2.3/tests/test_mcp.py +169 -0
  88. supermemory_agent-0.2.3/tests/test_mcp_comprehensive.py +583 -0
  89. supermemory_agent-0.2.3/tests/test_mcp_rest_parity.py +192 -0
  90. supermemory_agent-0.2.3/tests/test_mcp_server.py +136 -0
  91. supermemory_agent-0.2.3/tests/test_registry.py +29 -0
  92. supermemory_agent-0.2.3/tests/test_uall.py +161 -0
  93. supermemory_agent-0.2.3/uall_mcp/__init__.py +0 -0
  94. supermemory_agent-0.2.3/uall_mcp/client.py +68 -0
  95. supermemory_agent-0.2.3/uall_mcp/handlers.py +25 -0
  96. 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
@@ -0,0 +1,7 @@
1
+ UALL_STORAGE_BACKEND=file
2
+ UALL_DATA_DIR=.uall
3
+ UALL_API_KEY=dev-key-change-me
4
+ UALL_LLM_PROVIDER=heuristic
5
+ UALL_LLM_MODEL=
6
+ UALL_EMBEDDING_MODEL=
7
+ UALL_PROMOTION_DELAY_MINUTES=0