Skip to content

Commit 8a1f0e8

Browse files
authored
Merge pull request #11 from Sankhya-AI/alpha
feat: Dhee V2.0 — Self-Evolving Cognition Plugin
2 parents 46e5836 + 31bdb10 commit 8a1f0e8

32 files changed

Lines changed: 6718 additions & 173 deletions

CHANGELOG.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,91 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/).
66

7+
## [2.0.0] - 2026-03-30
8+
9+
Dhee V2: Self-Evolving Cognition Plugin. This release transforms Dhee from a memory layer into a **self-improving cognition plugin** that can make any agent — local or cloud, software or embodied — a HyperAgent that gets better with every interaction.
10+
11+
### Added — Phase 1: Universal Plugin
12+
13+
- **DheePlugin** (`dhee/adapters/base.py`): Framework-agnostic entry point wrapping Engram + Buddhi behind 4 tools (remember/recall/context/checkpoint), with session lifecycle (frozen snapshot pattern) and trajectory recording for skill mining.
14+
- **DheeEdge** (`dhee/edge/`): Minimal-footprint offline plugin for hardware/humanoid deployment. All-local inference (GGUF + ONNX), embodiment hooks (`on_sensor_input`, `on_action_result`, `predict_environment`), <500MB working set.
15+
- **BuddhiMini** (`dhee/mini/`): Scaffold for trainable model with 3 new task heads (`[MEMORY_OP]`, `[HEURISTIC]`, `[RETRIEVAL_JUDGE]`) on top of DheeModel. Includes `TraceSegmenter` that splits agent trajectories into `[REASON]/[ACT]/[MEMORY_OP]` spans for structured training data.
16+
- Export `DheePlugin` from `dhee.__init__` and `dhee/adapters/__init__`.
17+
- `pyproject.toml`: Added `edge` optional dependency group.
18+
- `SamskaraCollector.get_training_data()`: Exports SFT samples, DPO pairs, and vasana reports for the training pipeline.
19+
- `DheeLLM`: 3 new convenience methods (`classify_memory_op`, `generate_heuristic`, `judge_retrieval`).
20+
21+
### Added — Phase 2: Self-Evolving Cognition
22+
23+
- **ContrastiveStore** (`dhee/core/contrastive.py`): Success/failure pair storage with MaTTS re-ranking. Inspired by *ReasoningBank* (arXiv:2509.25140). Auto-creates pairs from `checkpoint(what_worked=..., what_failed=...)`. Exports DPO training pairs.
24+
- **HeuristicDistiller** (`dhee/core/heuristic.py`): Distills abstract reasoning patterns at 3 levels (specific / domain / universal) from agent trajectories. Inspired by *ERL: Efficient Reinforcement Learning* (arXiv:2603.24639). Deduplicates via Jaccard similarity.
25+
- **MetaBuddhi** (`dhee/core/meta_buddhi.py`): Self-referential cognition loop — proposes retrieval strategy mutations, evaluates them against samskara signals, promotes or rolls back. Inspired by *DGM-Hyperagents* (arXiv:2603.19461). The improvement procedure can improve itself.
26+
- **RetrievalStrategy** (`dhee/core/strategy.py`): Versioned scoring weights stored as human-readable JSON files. Tunable knobs: semantic/keyword weights, recency boost, contrastive boost, heuristic relevance, context budgets.
27+
- **ProgressiveTrainer** (`dhee/mini/progressive_trainer.py`): 3-stage training pipeline (SFT → DPO → RL gate). Inspired by *AgeMem* (arXiv:2601.01885). Weights samples by vasana degradation signals. Minimum thresholds prevent training on insufficient data.
28+
- **HyperContext** gains `contrasts` and `heuristics` fields — agents now receive contrastive evidence (do/avoid) and learned heuristics at session start.
29+
- **Buddhi** auto-wiring: `reflect()` auto-creates contrastive pairs and distills heuristics. `get_hyper_context()` populates contrasts and heuristics.
30+
- **HybridSearcher**: Added `contrastive_boost` parameter — results aligned with past successes score higher.
31+
- **EvolutionLayer**: Now runs dual loops — Nididhyasana (model training) + MetaBuddhi (strategy improvement).
32+
- **SkillMiner**: Triggers heuristic distillation after successful skill mining.
33+
34+
### Added — Phase 3: Scale
35+
36+
- **EvolvingGraph** (`dhee/core/graph_evolution.py`): Extends KnowledgeGraph with entity versioning (append-only JSONL), personalized PageRank per user/agent, and schema-free entity extraction via LLM (entities are typed as `DYNAMIC` when they don't match the fixed schema).
37+
- **HiveMemory** (`dhee/hive/hive_memory.py`): Multi-agent shared cognition on top of engram-bus. Agents publish insights, heuristics, and skills to the hive. Quality gating via Wilson score lower bound. Voting and adoption tracking.
38+
- **CRDT Sync** (`dhee/hive/sync.py`): Offline/edge sync protocol. LWW-Register for content, G-Counter for votes, OR-Set for adoption lists. `SyncEnvelope` wire format (JSON over bytes). Nodes converge after arbitrary offline periods.
39+
- **Framework Adapters**:
40+
- `dhee/adapters/openai_funcs.py``OpenAIToolAdapter` with `tool_definitions()` and `execute()` dispatch. Works with any API-compatible provider.
41+
- `dhee/adapters/langchain.py``get_dhee_tools()` returns 4 LangChain `BaseTool` instances. Lazy import — no hard dependency.
42+
- `dhee/adapters/autogen.py``get_autogen_functions()` for v0.2, `get_autogen_tool_specs()` for v0.4+. `register_dhee_tools()` for auto-registration.
43+
- `dhee/adapters/system_prompt.py``generate_snapshot()` renders HyperContext as a frozen system prompt block. Configurable sections, minimal mode for edge.
44+
- **EdgeTrainer** (`dhee/edge/edge_trainer.py`): On-device micro-training. LoRA rank-4, CPU-only, <2GB RAM. Deferred training mode for GGUF models. Vasana-weighted sample emphasis.
45+
- **KnowledgeGraph**: Added `DYNAMIC` entity type, `save()`/`load()` JSON persistence.
46+
47+
### Changed
48+
49+
- **Version**: 1.0.0 → 2.0.0
50+
- **MCP server** (`dhee/mcp_slim.py`): Refactored to wrap `DheePlugin` as backing singleton.
51+
- **pyproject.toml**: Updated description, keywords, classifier to Production/Stable.
52+
53+
### Research References
54+
55+
This release was informed by the following research (March 2026):
56+
57+
| Paper | Key Idea Applied |
58+
|-------|-----------------|
59+
| *DGM-Hyperagents* (arXiv:2603.19461) | Self-referential meta-agents that modify their own improvement procedure → MetaBuddhi |
60+
| *ERL* (arXiv:2603.24639) | Distill trajectories into abstract heuristics, not raw logs → HeuristicDistiller |
61+
| *ReasoningBank* (arXiv:2509.25140) | Contrastive learning from success/failure pairs, MaTTS scoring → ContrastiveStore |
62+
| *AgeMem* (arXiv:2601.01885) | Memory ops as RL-optimized tool calls, 3-stage progressive training → ProgressiveTrainer |
63+
| *Structured Agent Distillation* (arXiv:2505.13820) | [REASON]/[ACT] segmented traces for training small models → TraceSegmenter |
64+
65+
### Migration from V1
66+
67+
V2 is backwards-compatible with V1. Existing code using `Memory`, `Engram`, or `Dhee` classes continues to work unchanged. The new `DheePlugin` is additive — adopt it when you want the self-evolution capabilities.
68+
69+
```python
70+
# V1 (still works)
71+
from dhee import Memory
72+
m = Memory()
73+
m.add("fact")
74+
75+
# V2 (new universal plugin)
76+
from dhee import DheePlugin
77+
p = DheePlugin()
78+
p.remember("fact")
79+
ctx = p.context("what am I working on?")
80+
prompt = p.session_start("fixing auth bug")
81+
```
82+
83+
---
84+
85+
## [1.0.0] - 2026-03-22
86+
87+
### Changed
88+
- Renamed project from Engram to Dhee.
89+
- Clean repository for public push.
90+
- All imports updated (`engram.*``dhee.*`).
91+
792
## [0.4.0] - 2025-02-09
893

994
### Added

dhee/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,27 @@
2323
from dhee.memory.core import CoreMemory
2424
from dhee.memory.smart import SmartMemory
2525
from dhee.memory.main import FullMemory
26-
from dhee.simple import Engram
26+
from dhee.simple import Engram, Dhee
27+
from dhee.adapters.base import DheePlugin
2728
from dhee.core.category import CategoryProcessor, Category, CategoryType, CategoryMatch
2829
from dhee.core.echo import EchoProcessor, EchoDepth, EchoResult
2930
from dhee.configs.base import MemoryConfig, FadeMemConfig, EchoMemConfig, CategoryMemConfig, ScopeConfig
3031

3132
# Default: CoreMemory (lightest, zero-config)
3233
Memory = CoreMemory
3334

34-
__version__ = "1.0.0"
35+
__version__ = "2.0.0"
3536
__all__ = [
3637
# Tiered memory classes
3738
"CoreMemory",
3839
"SmartMemory",
3940
"FullMemory",
4041
"Memory",
4142
# Simplified interface
43+
"Dhee",
4244
"Engram",
45+
# Universal plugin
46+
"DheePlugin",
4347
# CategoryMem
4448
"CategoryProcessor",
4549
"Category",

dhee/adapters/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Dhee adapters — universal plugin interface for any agent framework.
2+
3+
Available adapters:
4+
- DheePlugin: Base universal plugin (remember/recall/context/checkpoint)
5+
- OpenAIToolAdapter: OpenAI function calling (tools= parameter)
6+
- get_dhee_tools: LangChain BaseTool wrappers
7+
- get_autogen_functions: AutoGen v0.2 callables + schemas
8+
- generate_snapshot: Frozen system prompt for non-tool-calling agents
9+
"""
10+
11+
from dhee.adapters.base import DheePlugin
12+
13+
__all__ = ["DheePlugin"]

0 commit comments

Comments
 (0)