dhee 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. dhee-1.0.0/LICENSE +21 -0
  2. dhee-1.0.0/PKG-INFO +342 -0
  3. dhee-1.0.0/README.md +272 -0
  4. dhee-1.0.0/dhee/__init__.py +64 -0
  5. dhee-1.0.0/dhee/api/__init__.py +6 -0
  6. dhee-1.0.0/dhee/api/app.py +195 -0
  7. dhee-1.0.0/dhee/api/server.py +34 -0
  8. dhee-1.0.0/dhee/benchmarks/__init__.py +2 -0
  9. dhee-1.0.0/dhee/benchmarks/arc_agi.py +383 -0
  10. dhee-1.0.0/dhee/benchmarks/longmemeval.py +2177 -0
  11. dhee-1.0.0/dhee/cli.py +424 -0
  12. dhee-1.0.0/dhee/cli_config.py +139 -0
  13. dhee-1.0.0/dhee/cli_mcp.py +189 -0
  14. dhee-1.0.0/dhee/cli_setup.py +75 -0
  15. dhee-1.0.0/dhee/configs/__init__.py +19 -0
  16. dhee-1.0.0/dhee/configs/active.py +65 -0
  17. dhee-1.0.0/dhee/configs/base.py +686 -0
  18. dhee-1.0.0/dhee/configs/presets.py +152 -0
  19. dhee-1.0.0/dhee/core/__init__.py +22 -0
  20. dhee-1.0.0/dhee/core/agi_loop.py +212 -0
  21. dhee-1.0.0/dhee/core/alaya.py +330 -0
  22. dhee-1.0.0/dhee/core/answer_orchestration.py +942 -0
  23. dhee-1.0.0/dhee/core/buddhi.py +934 -0
  24. dhee-1.0.0/dhee/core/category.py +796 -0
  25. dhee-1.0.0/dhee/core/code_exec_counter.py +266 -0
  26. dhee-1.0.0/dhee/core/cognition.py +481 -0
  27. dhee-1.0.0/dhee/core/conflict.py +60 -0
  28. dhee-1.0.0/dhee/core/consolidation.py +112 -0
  29. dhee-1.0.0/dhee/core/decay.py +52 -0
  30. dhee-1.0.0/dhee/core/distillation.py +232 -0
  31. dhee-1.0.0/dhee/core/echo.py +634 -0
  32. dhee-1.0.0/dhee/core/engram.py +431 -0
  33. dhee-1.0.0/dhee/core/engram_extractor.py +609 -0
  34. dhee-1.0.0/dhee/core/enrichment.py +631 -0
  35. dhee-1.0.0/dhee/core/episodic_index.py +979 -0
  36. dhee-1.0.0/dhee/core/evolution.py +356 -0
  37. dhee-1.0.0/dhee/core/forgetting.py +391 -0
  38. dhee-1.0.0/dhee/core/fusion.py +68 -0
  39. dhee-1.0.0/dhee/core/graph.py +566 -0
  40. dhee-1.0.0/dhee/core/intent.py +93 -0
  41. dhee-1.0.0/dhee/core/kernel.py +142 -0
  42. dhee-1.0.0/dhee/core/log_parser.py +197 -0
  43. dhee-1.0.0/dhee/core/metrics.py +207 -0
  44. dhee-1.0.0/dhee/core/profile.py +504 -0
  45. dhee-1.0.0/dhee/core/proposition_context.py +144 -0
  46. dhee-1.0.0/dhee/core/resolvers.py +949 -0
  47. dhee-1.0.0/dhee/core/retrieval.py +171 -0
  48. dhee-1.0.0/dhee/core/salience.py +113 -0
  49. dhee-1.0.0/dhee/core/samskara.py +510 -0
  50. dhee-1.0.0/dhee/core/scene.py +381 -0
  51. dhee-1.0.0/dhee/core/traces.py +120 -0
  52. dhee-1.0.0/dhee/core/viveka.py +708 -0
  53. dhee-1.0.0/dhee/db/__init__.py +0 -0
  54. dhee-1.0.0/dhee/db/sqlite.py +2845 -0
  55. dhee-1.0.0/dhee/db/sqlite_backup.py +2070 -0
  56. dhee-1.0.0/dhee/decay/__init__.py +5 -0
  57. dhee-1.0.0/dhee/embeddings/__init__.py +0 -0
  58. dhee-1.0.0/dhee/embeddings/base.py +21 -0
  59. dhee-1.0.0/dhee/embeddings/gemini.py +83 -0
  60. dhee-1.0.0/dhee/embeddings/nvidia.py +116 -0
  61. dhee-1.0.0/dhee/embeddings/ollama.py +66 -0
  62. dhee-1.0.0/dhee/embeddings/openai.py +47 -0
  63. dhee-1.0.0/dhee/embeddings/qwen.py +139 -0
  64. dhee-1.0.0/dhee/embeddings/simple.py +65 -0
  65. dhee-1.0.0/dhee/exceptions.py +19 -0
  66. dhee-1.0.0/dhee/integrations/__init__.py +1 -0
  67. dhee-1.0.0/dhee/llms/__init__.py +0 -0
  68. dhee-1.0.0/dhee/llms/base.py +56 -0
  69. dhee-1.0.0/dhee/llms/dhee.py +295 -0
  70. dhee-1.0.0/dhee/llms/gemini.py +60 -0
  71. dhee-1.0.0/dhee/llms/mock.py +35 -0
  72. dhee-1.0.0/dhee/llms/nvidia.py +136 -0
  73. dhee-1.0.0/dhee/llms/ollama.py +58 -0
  74. dhee-1.0.0/dhee/llms/openai.py +35 -0
  75. dhee-1.0.0/dhee/llms/teacher_logger.py +243 -0
  76. dhee-1.0.0/dhee/mcp_server.py +1025 -0
  77. dhee-1.0.0/dhee/mcp_slim.py +442 -0
  78. dhee-1.0.0/dhee/memory/__init__.py +14 -0
  79. dhee-1.0.0/dhee/memory/base.py +23 -0
  80. dhee-1.0.0/dhee/memory/core.py +440 -0
  81. dhee-1.0.0/dhee/memory/main.py +6103 -0
  82. dhee-1.0.0/dhee/memory/parallel.py +60 -0
  83. dhee-1.0.0/dhee/memory/projects.py +395 -0
  84. dhee-1.0.0/dhee/memory/smart.py +507 -0
  85. dhee-1.0.0/dhee/memory/tasks.py +683 -0
  86. dhee-1.0.0/dhee/memory/utils.py +173 -0
  87. dhee-1.0.0/dhee/observability.py +49 -0
  88. dhee-1.0.0/dhee/retrieval/__init__.py +10 -0
  89. dhee-1.0.0/dhee/retrieval/reranker.py +252 -0
  90. dhee-1.0.0/dhee/simple.py +362 -0
  91. dhee-1.0.0/dhee/skills/__init__.py +7 -0
  92. dhee-1.0.0/dhee/skills/discovery.py +59 -0
  93. dhee-1.0.0/dhee/skills/executor.py +262 -0
  94. dhee-1.0.0/dhee/skills/hashing.py +81 -0
  95. dhee-1.0.0/dhee/skills/miner.py +374 -0
  96. dhee-1.0.0/dhee/skills/outcomes.py +151 -0
  97. dhee-1.0.0/dhee/skills/schema.py +241 -0
  98. dhee-1.0.0/dhee/skills/store.py +282 -0
  99. dhee-1.0.0/dhee/skills/structure.py +498 -0
  100. dhee-1.0.0/dhee/skills/trajectory.py +260 -0
  101. dhee-1.0.0/dhee/teaching/__init__.py +17 -0
  102. dhee-1.0.0/dhee/teaching/concepts.py +307 -0
  103. dhee-1.0.0/dhee/teaching/config.py +27 -0
  104. dhee-1.0.0/dhee/teaching/student_model.py +372 -0
  105. dhee-1.0.0/dhee/teaching/teaching_memory.py +255 -0
  106. dhee-1.0.0/dhee/utils/__init__.py +0 -0
  107. dhee-1.0.0/dhee/utils/factory.py +169 -0
  108. dhee-1.0.0/dhee/utils/math.py +25 -0
  109. dhee-1.0.0/dhee/utils/prompts.py +382 -0
  110. dhee-1.0.0/dhee/utils/repo_identity.py +72 -0
  111. dhee-1.0.0/dhee/vector_stores/__init__.py +0 -0
  112. dhee-1.0.0/dhee/vector_stores/base.py +61 -0
  113. dhee-1.0.0/dhee/vector_stores/memory.py +106 -0
  114. dhee-1.0.0/dhee/vector_stores/sqlite_vec.py +391 -0
  115. dhee-1.0.0/dhee/vector_stores/zvec_store.py +402 -0
  116. dhee-1.0.0/dhee.egg-info/PKG-INFO +342 -0
  117. dhee-1.0.0/dhee.egg-info/SOURCES.txt +173 -0
  118. dhee-1.0.0/dhee.egg-info/dependency_links.txt +1 -0
  119. dhee-1.0.0/dhee.egg-info/entry_points.txt +4 -0
  120. dhee-1.0.0/dhee.egg-info/requires.txt +59 -0
  121. dhee-1.0.0/dhee.egg-info/top_level.txt +4 -0
  122. dhee-1.0.0/dheeModel/__init__.py +18 -0
  123. dhee-1.0.0/dheeModel/client.py +385 -0
  124. dhee-1.0.0/dheeModel/model/__init__.py +1 -0
  125. dhee-1.0.0/dheeModel/model/dhee_model.py +167 -0
  126. dhee-1.0.0/dheeModel/training/__init__.py +1 -0
  127. dhee-1.0.0/dheeModel/training/data_formatter.py +155 -0
  128. dhee-1.0.0/dheeModel/training/karma.py +272 -0
  129. dhee-1.0.0/dheeModel/training/nididhyasana.py +660 -0
  130. dhee-1.0.0/dheeModel/training/smrti.py +411 -0
  131. dhee-1.0.0/dheeModel/training/train.py +321 -0
  132. dhee-1.0.0/dhee_shared/__init__.py +1 -0
  133. dhee-1.0.0/dhee_shared/model_paths.py +63 -0
  134. dhee-1.0.0/pyproject.toml +82 -0
  135. dhee-1.0.0/setup.cfg +4 -0
  136. dhee-1.0.0/tests/test_accel.py +192 -0
  137. dhee-1.0.0/tests/test_accel_benchmark.py +58 -0
  138. dhee-1.0.0/tests/test_backward_compat.py +162 -0
  139. dhee-1.0.0/tests/test_batch.py +254 -0
  140. dhee-1.0.0/tests/test_core_memory.py +200 -0
  141. dhee-1.0.0/tests/test_cosine_similarity.py +54 -0
  142. dhee-1.0.0/tests/test_dedup.py +74 -0
  143. dhee-1.0.0/tests/test_deferred_enrichment.py +529 -0
  144. dhee-1.0.0/tests/test_dhee_model_paths.py +43 -0
  145. dhee-1.0.0/tests/test_distillation.py +192 -0
  146. dhee-1.0.0/tests/test_e2e_all_features.py +913 -0
  147. dhee-1.0.0/tests/test_forgetting.py +154 -0
  148. dhee-1.0.0/tests/test_hashing.py +135 -0
  149. dhee-1.0.0/tests/test_intent.py +90 -0
  150. dhee-1.0.0/tests/test_locomo_plus_runner.py +119 -0
  151. dhee-1.0.0/tests/test_log_parser.py +350 -0
  152. dhee-1.0.0/tests/test_mcp_tools_slim.py +44 -0
  153. dhee-1.0.0/tests/test_memory_types.py +201 -0
  154. dhee-1.0.0/tests/test_migration.py +109 -0
  155. dhee-1.0.0/tests/test_miner.py +253 -0
  156. dhee-1.0.0/tests/test_openclaw.py +235 -0
  157. dhee-1.0.0/tests/test_orchestration_core.py +279 -0
  158. dhee-1.0.0/tests/test_parallel.py +208 -0
  159. dhee-1.0.0/tests/test_power_packages.py +2034 -0
  160. dhee-1.0.0/tests/test_presets.py +48 -0
  161. dhee-1.0.0/tests/test_profile.py +205 -0
  162. dhee-1.0.0/tests/test_projects.py +247 -0
  163. dhee-1.0.0/tests/test_query_cache.py +42 -0
  164. dhee-1.0.0/tests/test_scene.py +217 -0
  165. dhee-1.0.0/tests/test_skills.py +319 -0
  166. dhee-1.0.0/tests/test_smart_memory.py +144 -0
  167. dhee-1.0.0/tests/test_sqlite_connection_pool.py +174 -0
  168. dhee-1.0.0/tests/test_sqlite_vec.py +234 -0
  169. dhee-1.0.0/tests/test_structural.py +455 -0
  170. dhee-1.0.0/tests/test_structured_resolution.py +574 -0
  171. dhee-1.0.0/tests/test_tasks.py +589 -0
  172. dhee-1.0.0/tests/test_traces.py +160 -0
  173. dhee-1.0.0/tests/test_trajectory.py +156 -0
  174. dhee-1.0.0/tests/test_unified_enrichment.py +504 -0
  175. dhee-1.0.0/tests/test_zvec_store.py +212 -0
dhee-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ashish Dwivedi
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.
dhee-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,342 @@
1
+ Metadata-Version: 2.4
2
+ Name: dhee
3
+ Version: 1.0.0
4
+ Summary: Cognition as a Service — the memory layer that makes ANY agent intelligent
5
+ Author: Sankhya AI Labs
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Sankhya-AI/Dhee
8
+ Project-URL: Repository, https://github.com/Sankhya-AI/Dhee
9
+ Project-URL: Issues, https://github.com/Sankhya-AI/Dhee/issues
10
+ Project-URL: Documentation, https://github.com/Sankhya-AI/Dhee#readme
11
+ Project-URL: Changelog, https://github.com/Sankhya-AI/Dhee/blob/main/CHANGELOG.md
12
+ Keywords: memory-layer,cognition,mcp,claude,cursor,codex,ai,agents,forgetting,llm
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: pydantic>=2.0
24
+ Requires-Dist: requests>=2.28.0
25
+ Requires-Dist: pyyaml>=6.0
26
+ Requires-Dist: dhee-accel>=0.1.0
27
+ Provides-Extra: gemini
28
+ Requires-Dist: google-genai>=1.0.0; extra == "gemini"
29
+ Provides-Extra: openai
30
+ Requires-Dist: openai>=1.0.0; extra == "openai"
31
+ Provides-Extra: ollama
32
+ Requires-Dist: ollama>=0.4.0; extra == "ollama"
33
+ Provides-Extra: nvidia
34
+ Requires-Dist: openai>=1.0.0; extra == "nvidia"
35
+ Provides-Extra: zvec
36
+ Requires-Dist: zvec>=0.2.1; extra == "zvec"
37
+ Provides-Extra: sqlite-vec
38
+ Requires-Dist: sqlite-vec>=0.1.1; extra == "sqlite-vec"
39
+ Provides-Extra: local
40
+ Requires-Dist: llama-cpp-python>=0.3; extra == "local"
41
+ Requires-Dist: sentence-transformers>=3.0; extra == "local"
42
+ Provides-Extra: mcp
43
+ Requires-Dist: mcp>=1.0.0; extra == "mcp"
44
+ Provides-Extra: api
45
+ Requires-Dist: fastapi>=0.100.0; extra == "api"
46
+ Requires-Dist: uvicorn>=0.20.0; extra == "api"
47
+ Provides-Extra: bus
48
+ Requires-Dist: dhee-bus>=0.1.0; extra == "bus"
49
+ Provides-Extra: training
50
+ Requires-Dist: unsloth; extra == "training"
51
+ Requires-Dist: datasets>=2.0; extra == "training"
52
+ Requires-Dist: trl>=0.7; extra == "training"
53
+ Requires-Dist: peft>=0.6; extra == "training"
54
+ Provides-Extra: all
55
+ Requires-Dist: google-genai>=1.0.0; extra == "all"
56
+ Requires-Dist: openai>=1.0.0; extra == "all"
57
+ Requires-Dist: ollama>=0.4.0; extra == "all"
58
+ Requires-Dist: mcp>=1.0.0; extra == "all"
59
+ Requires-Dist: fastapi>=0.100.0; extra == "all"
60
+ Requires-Dist: uvicorn>=0.20.0; extra == "all"
61
+ Requires-Dist: dhee-accel>=0.1.0; extra == "all"
62
+ Requires-Dist: dhee-bus>=0.1.0; extra == "all"
63
+ Requires-Dist: llama-cpp-python>=0.3; extra == "all"
64
+ Requires-Dist: sentence-transformers>=3.0; extra == "all"
65
+ Provides-Extra: dev
66
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
67
+ Requires-Dist: build>=1.0.0; extra == "dev"
68
+ Requires-Dist: twine>=5.0.0; extra == "dev"
69
+ Dynamic: license-file
70
+
71
+ <p align="center">
72
+ <img src="docs/dhee-logo.png" alt="Dhee" width="80">
73
+ </p>
74
+
75
+ <h1 align="center">Dhee</h1>
76
+
77
+ <h3 align="center">The cognition layer that turns your agent into a HyperAgent.</h3>
78
+
79
+ <p align="center">
80
+ 4 tools. 1 LLM call per session. ~$0.004 total cost.<br>
81
+ Your agent remembers, learns from outcomes, and predicts what you need next.
82
+ </p>
83
+
84
+ <p align="center">
85
+ <a href="https://pypi.org/project/dhee"><img src="https://img.shields.io/badge/python-3.9%2B-blue.svg" alt="Python 3.9+"></a>
86
+ <a href="https://github.com/Sankhya-AI/Dhee/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT License"></a>
87
+ </p>
88
+
89
+ ---
90
+
91
+ ## What is Dhee?
92
+
93
+ Most memory layers are glorified vector stores. Store text, retrieve text. Your agent is still stateless — it doesn't learn, doesn't track what worked, doesn't warn you when something is regressing.
94
+
95
+ **Dhee is a cognition layer.** It gives any agent — Claude, GPT, Gemini, custom — four capabilities that turn it into a self-improving HyperAgent:
96
+
97
+ | Capability | What Dhee does | What your agent gets |
98
+ |:-----------|:---------------|:---------------------|
99
+ | **Persistent memory** | Stores facts with echo-augmented retrieval (paraphrases, keywords, question-forms) | "What theme does the user prefer?" matches "User likes dark mode" even though the words are different |
100
+ | **Performance tracking** | Records task outcomes, detects trends automatically | Knows it's regressing on code reviews, warns you before you notice |
101
+ | **Insight synthesis** | Extracts causal hypotheses from outcomes — not raw data, synthesized learnings | "What worked: checking git blame first" transfers to the next bug fix |
102
+ | **Prospective memory** | Stores future triggers — "remember to X when Y" | Surfaces intentions when the trigger context matches |
103
+
104
+ ### Benchmark: LongMemEval
105
+
106
+ Dhee achieves near-perfect retrieval on [LongMemEval](https://arxiv.org/abs/2410.10813), the standard benchmark for long-term conversational memory — temporal reasoning, multi-session aggregation, knowledge updates, and counterfactual tracking across 500+ questions.
107
+
108
+ > Evaluation run in progress. Full results and methodology will be published in the benchmark report.
109
+
110
+ ---
111
+
112
+ ## Quick Start
113
+
114
+ ```bash
115
+ pip install dhee[openai,mcp]
116
+ export OPENAI_API_KEY=sk-...
117
+ ```
118
+
119
+ ### MCP (Claude Code, Cursor — zero code)
120
+
121
+ ```json
122
+ {
123
+ "mcpServers": {
124
+ "dhee": { "command": "dhee-mcp" }
125
+ }
126
+ }
127
+ ```
128
+
129
+ Your agent now has 4 tools. It will use them automatically.
130
+
131
+ ### Python SDK
132
+
133
+ ```python
134
+ from dhee import Dhee
135
+
136
+ d = Dhee()
137
+ d.remember("User prefers dark mode")
138
+ d.recall("what theme does the user like?")
139
+ d.context("fixing auth bug")
140
+ d.checkpoint("Fixed it", what_worked="git blame first")
141
+ ```
142
+
143
+ ### CLI
144
+
145
+ ```bash
146
+ dhee remember "User prefers Python"
147
+ dhee recall "programming language"
148
+ dhee checkpoint "Fixed auth bug" --what-worked "checked logs"
149
+ ```
150
+
151
+ ### Docker
152
+
153
+ ```bash
154
+ docker compose up -d # uses OPENAI_API_KEY from env
155
+ ```
156
+
157
+ ---
158
+
159
+ ## The 4 Tools
160
+
161
+ Every interface — MCP, Python, CLI, JS — exposes the same 4 operations.
162
+
163
+ ### `remember(content)`
164
+ Store a fact, preference, or observation.
165
+
166
+ **Hot path**: 0 LLM calls, 1 embedding (~$0.0002). The memory is stored immediately. Echo enrichment (paraphrases, keywords, question-forms that make future recall dramatically better) is deferred to `checkpoint`.
167
+
168
+ ```python
169
+ d.remember("User prefers FastAPI over Flask")
170
+ d.remember("Project uses PostgreSQL 15 with pgvector")
171
+ ```
172
+
173
+ ### `recall(query)`
174
+ Search memory. Returns top-K results ranked by relevance.
175
+
176
+ **Hot path**: 0 LLM calls, 1 embedding (~$0.0002). Pure vector search with echo-boosted re-ranking.
177
+
178
+ ```python
179
+ results = d.recall("what database does the project use?")
180
+ # [{"memory": "Project uses PostgreSQL 15 with pgvector", "score": 0.94}]
181
+ ```
182
+
183
+ ### `context(task_description)`
184
+ HyperAgent session bootstrap. Call once at the start of a conversation.
185
+
186
+ Returns everything the agent needs to be effective immediately:
187
+ - **Last session state** — pick up where you left off, zero cold start
188
+ - **Performance trends** — improving or regressing on this task type
189
+ - **Synthesized insights** — "What worked for bug_fix: checking git blame first"
190
+ - **Triggered intentions** — "Remember to run auth tests after modifying login.py"
191
+ - **Proactive warnings** — "Performance on code_review is declining"
192
+ - **Relevant memories** — top matches for the task
193
+
194
+ ```python
195
+ ctx = d.context("fixing the auth bug in login.py")
196
+ # ctx["warnings"] → ["Performance on 'bug_fix' declining (trend: -0.05)"]
197
+ # ctx["insights"] → [{"content": "What worked: git blame → found breaking commit"}]
198
+ # ctx["intentions"] → [{"description": "run auth tests after login.py changes"}]
199
+ ```
200
+
201
+ ### `checkpoint(summary, ...)`
202
+ Save session state before ending. This is where the cognition happens:
203
+
204
+ 1. **Session digest** — saved for cross-agent handoff (Claude Code crashes? Cursor picks up instantly)
205
+ 2. **Batch enrichment** — 1 LLM call per ~10 memories stored since last checkpoint. Adds echo paraphrases and keywords that make `recall` work across phrasings
206
+ 3. **Outcome recording** — tracks score per task type, auto-detects regressions and breakthroughs
207
+ 4. **Insight synthesis** — "what worked" and "what failed" become transferable learnings
208
+ 5. **Intention storage** — "remember to X when Y" fires when the trigger matches
209
+
210
+ ```python
211
+ d.checkpoint(
212
+ "Fixed auth bug in login.py",
213
+ task_type="bug_fix",
214
+ outcome_score=1.0,
215
+ what_worked="git blame showed the exact commit that broke auth",
216
+ what_failed="grep was too slow on the monorepo",
217
+ remember_to="run auth tests after any login.py change",
218
+ trigger_keywords=["login", "auth"],
219
+ )
220
+ ```
221
+
222
+ ---
223
+
224
+ ## Cost
225
+
226
+ | Operation | LLM calls | Embed calls | Cost |
227
+ |:----------|:----------|:------------|:-----|
228
+ | `remember` | 0 | 1 | ~$0.0002 |
229
+ | `recall` | 0 | 1 | ~$0.0002 |
230
+ | `context` | 0 | 0-1 | ~$0.0002 |
231
+ | `checkpoint` | 1 per ~10 memories | 0 | ~$0.001 |
232
+ | **Typical session** | **1** | **~15** | **~$0.004** |
233
+
234
+ ---
235
+
236
+ ## How It Works (Under the Hood)
237
+
238
+ Dhee has two layers: the memory store and the cognition engine.
239
+
240
+ ### Memory Store — Engram
241
+
242
+ Stores memories in SQLite + a vector index. On the hot path (`remember`/`recall`), zero LLM calls — just embedding. At `checkpoint`, unified enrichment runs in a single batched LLM call:
243
+
244
+ - **Echo encoding** — generates paraphrases, keywords, and question-forms so "User prefers dark mode" also matches queries like "what theme?" or "UI preferences"
245
+ - **Category inference** — auto-tags for filtering
246
+ - **Fact decomposition** — splits compound statements into atomic, searchable facts
247
+ - **Entity + profile extraction** — builds a knowledge graph of people, tools, projects
248
+
249
+ All of this happens in **1 LLM call per ~10 memories**. Not 4 calls per memory. One batched call.
250
+
251
+ Memory decays naturally (Ebbinghaus curve). Frequently accessed memories get promoted from short-term to long-term. Unused ones fade. ~45% less storage than systems that keep everything forever.
252
+
253
+ ### Cognition Engine — Buddhi
254
+
255
+ A parallel intelligence layer that observes the memory pipeline and builds meta-knowledge:
256
+
257
+ - **Performance tracking** — records outcomes per task type, computes trends (moving average). Auto-generates regression warnings and breakthrough insights.
258
+ - **Insight synthesis** — stores causal hypotheses ("what worked", "what failed"), not raw data. Insights have confidence scores that update on validation/invalidation.
259
+ - **Prospective memory** — stores future triggers with keyword matching. "Remember to run tests after modifying auth" fires when the next query mentions "auth".
260
+ - **Intention detection** — auto-detects "remember to X when Y" patterns in stored memories.
261
+
262
+ Zero LLM calls on the hot path. Pure pattern matching + statistics. Persistence via JSONL files (~3 files total).
263
+
264
+ Inspired by [Meta's DGM-Hyperagents](https://arxiv.org/abs/2603.19461) — agents that emergently develop persistent memory and performance tracking achieve self-accelerating improvement that transfers across domains. Dhee provides these capabilities as infrastructure.
265
+
266
+ ---
267
+
268
+ ## Architecture
269
+
270
+ ```
271
+ Agent (Claude, GPT, Cursor, custom)
272
+
273
+ ├── remember(content) → Engram: embed + store (0 LLM)
274
+ ├── recall(query) → Engram: embed + vector search (0 LLM)
275
+ ├── context(task) → Buddhi: performance + insights + intentions + memories
276
+ └── checkpoint(summary) → Engram: batch enrich (1 LLM/10 mems)
277
+ → Buddhi: outcome + reflect + intention
278
+ ```
279
+
280
+ ```
281
+ ~/.dhee/
282
+ ├── history.db # SQLite: memories, history, entities
283
+ ├── zvec/ # Vector index (embeddings)
284
+ └── buddhi/
285
+ ├── insights.jsonl # Synthesized learnings
286
+ ├── intentions.jsonl # Future triggers
287
+ └── performance.json # Task type scores + trends
288
+ ```
289
+
290
+ ---
291
+
292
+ ## Advanced
293
+
294
+ ### Full MCP Server (24 tools)
295
+
296
+ Power users who need granular control over skills, trajectories, structural search, and enrichment:
297
+
298
+ ```bash
299
+ dhee-mcp-full # exposes all 24 tools
300
+ ```
301
+
302
+ ### Python — Direct Memory Access
303
+
304
+ ```python
305
+ from dhee import FullMemory
306
+
307
+ m = FullMemory()
308
+ m.add("conversation content", user_id="u1", infer=True)
309
+ m.search("query", user_id="u1", limit=10)
310
+ m.think("complex question requiring reasoning across memories")
311
+ ```
312
+
313
+ ### Provider Options
314
+
315
+ ```bash
316
+ pip install dhee[openai,mcp] # OpenAI (recommended, cheapest embeddings)
317
+ pip install dhee[gemini,mcp] # Google Gemini
318
+ pip install dhee[ollama,mcp] # Ollama (local, zero cost)
319
+ ```
320
+
321
+ ---
322
+
323
+ ## Contributing
324
+
325
+ ```bash
326
+ git clone https://github.com/Sankhya-AI/Dhee.git
327
+ cd Dhee
328
+ pip install -e ".[dev]"
329
+ pytest
330
+ ```
331
+
332
+ ---
333
+
334
+ <p align="center">
335
+ <b>4 tools. 1 LLM call. Your agent remembers, learns, and predicts.</b>
336
+ <br><br>
337
+ <a href="https://github.com/Sankhya-AI/Dhee">GitHub</a> &middot;
338
+ <a href="https://pypi.org/project/dhee">PyPI</a> &middot;
339
+ <a href="https://github.com/Sankhya-AI/Dhee/issues">Issues</a>
340
+ </p>
341
+
342
+ <p align="center">MIT License &mdash; <a href="https://sankhyaailabs.com">Sankhya AI</a></p>
dhee-1.0.0/README.md ADDED
@@ -0,0 +1,272 @@
1
+ <p align="center">
2
+ <img src="docs/dhee-logo.png" alt="Dhee" width="80">
3
+ </p>
4
+
5
+ <h1 align="center">Dhee</h1>
6
+
7
+ <h3 align="center">The cognition layer that turns your agent into a HyperAgent.</h3>
8
+
9
+ <p align="center">
10
+ 4 tools. 1 LLM call per session. ~$0.004 total cost.<br>
11
+ Your agent remembers, learns from outcomes, and predicts what you need next.
12
+ </p>
13
+
14
+ <p align="center">
15
+ <a href="https://pypi.org/project/dhee"><img src="https://img.shields.io/badge/python-3.9%2B-blue.svg" alt="Python 3.9+"></a>
16
+ <a href="https://github.com/Sankhya-AI/Dhee/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT License"></a>
17
+ </p>
18
+
19
+ ---
20
+
21
+ ## What is Dhee?
22
+
23
+ Most memory layers are glorified vector stores. Store text, retrieve text. Your agent is still stateless — it doesn't learn, doesn't track what worked, doesn't warn you when something is regressing.
24
+
25
+ **Dhee is a cognition layer.** It gives any agent — Claude, GPT, Gemini, custom — four capabilities that turn it into a self-improving HyperAgent:
26
+
27
+ | Capability | What Dhee does | What your agent gets |
28
+ |:-----------|:---------------|:---------------------|
29
+ | **Persistent memory** | Stores facts with echo-augmented retrieval (paraphrases, keywords, question-forms) | "What theme does the user prefer?" matches "User likes dark mode" even though the words are different |
30
+ | **Performance tracking** | Records task outcomes, detects trends automatically | Knows it's regressing on code reviews, warns you before you notice |
31
+ | **Insight synthesis** | Extracts causal hypotheses from outcomes — not raw data, synthesized learnings | "What worked: checking git blame first" transfers to the next bug fix |
32
+ | **Prospective memory** | Stores future triggers — "remember to X when Y" | Surfaces intentions when the trigger context matches |
33
+
34
+ ### Benchmark: LongMemEval
35
+
36
+ Dhee achieves near-perfect retrieval on [LongMemEval](https://arxiv.org/abs/2410.10813), the standard benchmark for long-term conversational memory — temporal reasoning, multi-session aggregation, knowledge updates, and counterfactual tracking across 500+ questions.
37
+
38
+ > Evaluation run in progress. Full results and methodology will be published in the benchmark report.
39
+
40
+ ---
41
+
42
+ ## Quick Start
43
+
44
+ ```bash
45
+ pip install dhee[openai,mcp]
46
+ export OPENAI_API_KEY=sk-...
47
+ ```
48
+
49
+ ### MCP (Claude Code, Cursor — zero code)
50
+
51
+ ```json
52
+ {
53
+ "mcpServers": {
54
+ "dhee": { "command": "dhee-mcp" }
55
+ }
56
+ }
57
+ ```
58
+
59
+ Your agent now has 4 tools. It will use them automatically.
60
+
61
+ ### Python SDK
62
+
63
+ ```python
64
+ from dhee import Dhee
65
+
66
+ d = Dhee()
67
+ d.remember("User prefers dark mode")
68
+ d.recall("what theme does the user like?")
69
+ d.context("fixing auth bug")
70
+ d.checkpoint("Fixed it", what_worked="git blame first")
71
+ ```
72
+
73
+ ### CLI
74
+
75
+ ```bash
76
+ dhee remember "User prefers Python"
77
+ dhee recall "programming language"
78
+ dhee checkpoint "Fixed auth bug" --what-worked "checked logs"
79
+ ```
80
+
81
+ ### Docker
82
+
83
+ ```bash
84
+ docker compose up -d # uses OPENAI_API_KEY from env
85
+ ```
86
+
87
+ ---
88
+
89
+ ## The 4 Tools
90
+
91
+ Every interface — MCP, Python, CLI, JS — exposes the same 4 operations.
92
+
93
+ ### `remember(content)`
94
+ Store a fact, preference, or observation.
95
+
96
+ **Hot path**: 0 LLM calls, 1 embedding (~$0.0002). The memory is stored immediately. Echo enrichment (paraphrases, keywords, question-forms that make future recall dramatically better) is deferred to `checkpoint`.
97
+
98
+ ```python
99
+ d.remember("User prefers FastAPI over Flask")
100
+ d.remember("Project uses PostgreSQL 15 with pgvector")
101
+ ```
102
+
103
+ ### `recall(query)`
104
+ Search memory. Returns top-K results ranked by relevance.
105
+
106
+ **Hot path**: 0 LLM calls, 1 embedding (~$0.0002). Pure vector search with echo-boosted re-ranking.
107
+
108
+ ```python
109
+ results = d.recall("what database does the project use?")
110
+ # [{"memory": "Project uses PostgreSQL 15 with pgvector", "score": 0.94}]
111
+ ```
112
+
113
+ ### `context(task_description)`
114
+ HyperAgent session bootstrap. Call once at the start of a conversation.
115
+
116
+ Returns everything the agent needs to be effective immediately:
117
+ - **Last session state** — pick up where you left off, zero cold start
118
+ - **Performance trends** — improving or regressing on this task type
119
+ - **Synthesized insights** — "What worked for bug_fix: checking git blame first"
120
+ - **Triggered intentions** — "Remember to run auth tests after modifying login.py"
121
+ - **Proactive warnings** — "Performance on code_review is declining"
122
+ - **Relevant memories** — top matches for the task
123
+
124
+ ```python
125
+ ctx = d.context("fixing the auth bug in login.py")
126
+ # ctx["warnings"] → ["Performance on 'bug_fix' declining (trend: -0.05)"]
127
+ # ctx["insights"] → [{"content": "What worked: git blame → found breaking commit"}]
128
+ # ctx["intentions"] → [{"description": "run auth tests after login.py changes"}]
129
+ ```
130
+
131
+ ### `checkpoint(summary, ...)`
132
+ Save session state before ending. This is where the cognition happens:
133
+
134
+ 1. **Session digest** — saved for cross-agent handoff (Claude Code crashes? Cursor picks up instantly)
135
+ 2. **Batch enrichment** — 1 LLM call per ~10 memories stored since last checkpoint. Adds echo paraphrases and keywords that make `recall` work across phrasings
136
+ 3. **Outcome recording** — tracks score per task type, auto-detects regressions and breakthroughs
137
+ 4. **Insight synthesis** — "what worked" and "what failed" become transferable learnings
138
+ 5. **Intention storage** — "remember to X when Y" fires when the trigger matches
139
+
140
+ ```python
141
+ d.checkpoint(
142
+ "Fixed auth bug in login.py",
143
+ task_type="bug_fix",
144
+ outcome_score=1.0,
145
+ what_worked="git blame showed the exact commit that broke auth",
146
+ what_failed="grep was too slow on the monorepo",
147
+ remember_to="run auth tests after any login.py change",
148
+ trigger_keywords=["login", "auth"],
149
+ )
150
+ ```
151
+
152
+ ---
153
+
154
+ ## Cost
155
+
156
+ | Operation | LLM calls | Embed calls | Cost |
157
+ |:----------|:----------|:------------|:-----|
158
+ | `remember` | 0 | 1 | ~$0.0002 |
159
+ | `recall` | 0 | 1 | ~$0.0002 |
160
+ | `context` | 0 | 0-1 | ~$0.0002 |
161
+ | `checkpoint` | 1 per ~10 memories | 0 | ~$0.001 |
162
+ | **Typical session** | **1** | **~15** | **~$0.004** |
163
+
164
+ ---
165
+
166
+ ## How It Works (Under the Hood)
167
+
168
+ Dhee has two layers: the memory store and the cognition engine.
169
+
170
+ ### Memory Store — Engram
171
+
172
+ Stores memories in SQLite + a vector index. On the hot path (`remember`/`recall`), zero LLM calls — just embedding. At `checkpoint`, unified enrichment runs in a single batched LLM call:
173
+
174
+ - **Echo encoding** — generates paraphrases, keywords, and question-forms so "User prefers dark mode" also matches queries like "what theme?" or "UI preferences"
175
+ - **Category inference** — auto-tags for filtering
176
+ - **Fact decomposition** — splits compound statements into atomic, searchable facts
177
+ - **Entity + profile extraction** — builds a knowledge graph of people, tools, projects
178
+
179
+ All of this happens in **1 LLM call per ~10 memories**. Not 4 calls per memory. One batched call.
180
+
181
+ Memory decays naturally (Ebbinghaus curve). Frequently accessed memories get promoted from short-term to long-term. Unused ones fade. ~45% less storage than systems that keep everything forever.
182
+
183
+ ### Cognition Engine — Buddhi
184
+
185
+ A parallel intelligence layer that observes the memory pipeline and builds meta-knowledge:
186
+
187
+ - **Performance tracking** — records outcomes per task type, computes trends (moving average). Auto-generates regression warnings and breakthrough insights.
188
+ - **Insight synthesis** — stores causal hypotheses ("what worked", "what failed"), not raw data. Insights have confidence scores that update on validation/invalidation.
189
+ - **Prospective memory** — stores future triggers with keyword matching. "Remember to run tests after modifying auth" fires when the next query mentions "auth".
190
+ - **Intention detection** — auto-detects "remember to X when Y" patterns in stored memories.
191
+
192
+ Zero LLM calls on the hot path. Pure pattern matching + statistics. Persistence via JSONL files (~3 files total).
193
+
194
+ Inspired by [Meta's DGM-Hyperagents](https://arxiv.org/abs/2603.19461) — agents that emergently develop persistent memory and performance tracking achieve self-accelerating improvement that transfers across domains. Dhee provides these capabilities as infrastructure.
195
+
196
+ ---
197
+
198
+ ## Architecture
199
+
200
+ ```
201
+ Agent (Claude, GPT, Cursor, custom)
202
+
203
+ ├── remember(content) → Engram: embed + store (0 LLM)
204
+ ├── recall(query) → Engram: embed + vector search (0 LLM)
205
+ ├── context(task) → Buddhi: performance + insights + intentions + memories
206
+ └── checkpoint(summary) → Engram: batch enrich (1 LLM/10 mems)
207
+ → Buddhi: outcome + reflect + intention
208
+ ```
209
+
210
+ ```
211
+ ~/.dhee/
212
+ ├── history.db # SQLite: memories, history, entities
213
+ ├── zvec/ # Vector index (embeddings)
214
+ └── buddhi/
215
+ ├── insights.jsonl # Synthesized learnings
216
+ ├── intentions.jsonl # Future triggers
217
+ └── performance.json # Task type scores + trends
218
+ ```
219
+
220
+ ---
221
+
222
+ ## Advanced
223
+
224
+ ### Full MCP Server (24 tools)
225
+
226
+ Power users who need granular control over skills, trajectories, structural search, and enrichment:
227
+
228
+ ```bash
229
+ dhee-mcp-full # exposes all 24 tools
230
+ ```
231
+
232
+ ### Python — Direct Memory Access
233
+
234
+ ```python
235
+ from dhee import FullMemory
236
+
237
+ m = FullMemory()
238
+ m.add("conversation content", user_id="u1", infer=True)
239
+ m.search("query", user_id="u1", limit=10)
240
+ m.think("complex question requiring reasoning across memories")
241
+ ```
242
+
243
+ ### Provider Options
244
+
245
+ ```bash
246
+ pip install dhee[openai,mcp] # OpenAI (recommended, cheapest embeddings)
247
+ pip install dhee[gemini,mcp] # Google Gemini
248
+ pip install dhee[ollama,mcp] # Ollama (local, zero cost)
249
+ ```
250
+
251
+ ---
252
+
253
+ ## Contributing
254
+
255
+ ```bash
256
+ git clone https://github.com/Sankhya-AI/Dhee.git
257
+ cd Dhee
258
+ pip install -e ".[dev]"
259
+ pytest
260
+ ```
261
+
262
+ ---
263
+
264
+ <p align="center">
265
+ <b>4 tools. 1 LLM call. Your agent remembers, learns, and predicts.</b>
266
+ <br><br>
267
+ <a href="https://github.com/Sankhya-AI/Dhee">GitHub</a> &middot;
268
+ <a href="https://pypi.org/project/dhee">PyPI</a> &middot;
269
+ <a href="https://github.com/Sankhya-AI/Dhee/issues">Issues</a>
270
+ </p>
271
+
272
+ <p align="center">MIT License &mdash; <a href="https://sankhyaailabs.com">Sankhya AI</a></p>