Dhee - world memory layer and context compiler for AI agents
pip install dhee==7.6.0 Copy PIP instructions
World memory for AI agents. A arc based context compiler for ai agents
Dhee gives an agent the bigger story before it takes the next action.
LLMs are powerful, but they still miss the arc. What is the user trying to become? What happened last session? Which decision was already made? Which failure should not be repeated? Which proof is required before touching code?
Dhee stores that story locally and compiles it into the smallest useful context. Not a transcript pile. Not vibes. Memory with shape.
pip install dhee dhee install Or use the one-command installer:
curl -fsSL https://raw.githubusercontent.com/Sankhya-AI/Dhee/main/install.sh | sh
cd /path/to/repo-or-folder dhee init dhee status dhee ui dhee init is the opt-in switch. Run it in the current directory, pass a folder, or pass a git URL:
dhee init /path/to/folder dhee init https://github.com/org/repo.git Folders that have not run dhee init stay vanilla in Codex and Claude Code.
Dhee runs with no provider at all: EmbeddingGemma 2 (Google DeepMind's embedding model, its 270M text part) on your CPU for vectors, and no LLM.
pip install 'dhee[gemma,zvec]' dhee models download gemma # 314 MB, once; otherwise it downloads on first use from dhee import Dhee memory = Dhee(provider="gemma") memory.remember("The project runs its tests with `make test`.") memory.recall("which command runs the test suite") The model lives in ~/.cache/dhee/models (set DHEE_MODELS_DIR to move it). Switching an existing store to it keeps your memories: memory.repair_memory_vectors(dry_run=False, reembed=True).
With zvec, recall searches words and meaning together: a BM25 index sits beside the vectors, so an exact command, path or name is found even where its meaning alone would rank it below a look-alike.
dhee completion --shell zsh dhee completion --shell bash dhee completion --shell fish What Is Dhee? Dhee is the memory layer agents should have had from day one.
It runs beside the model and answers the questions that raw chat history cannot:
Most agents drown in context or starve without it. Dhee does the boring hard part in the middle.
The model gets the part of the world it needs, in the form it can use.
Series -> Season -> Episode -> Scene -> SceneCard -> MemoryItem In plain English:
That story gives the model anticipation. The prior is advisory, never bossy: explicit user intent, facts, privacy, and proof gates win.
Dhee can run model-free, but the production retrieval path is built for serious agent work:
python3.11 -m pip install "dhee[nvidia,zvec,mcp]" dhee key set nvidia Current high-quality stack:
Deterministic filters still go first: secrets, private scenes, contradicted cards, superseded cards, and code-mutation proof gates cannot be talked around by a high similarity score.
{ "mcpServers": { "dhee": { "command": "dhee-mcp" } } } Scene intelligence tools:
dhee_scene_start dhee_scene_event dhee_scene_end dhee_scene_context dhee_narrative_prior Core context tools:
dhee_context_bootstrap dhee_read dhee_grep dhee_bash dhee_context_pack dhee_scene_search A good agent loop is simple:
bootstrap -> start scene -> gather evidence -> retrieve context -> act -> verify -> end scene -> save digest Agent Runtime Dhee now plugs into existing agents with a few lines of code.
If you already have an agent, you keep your provider SDK, model, tools, audio interface, callbacks, and deployment. Dhee adds the missing memory loop:
before run -> inject compact Dhee context during run -> expose a dhee_memory tool after run -> checkpoint what should matter next time Current native integrations:
Dhee can also run as a small HTTP sidecar for agents that cannot use local Python or stdio MCP.
export DHEE_HTTP_TOKEN="dev-token" export ELEVENLABS_WEBHOOK_SECRET="..." dhee serve --host 0.0.0.0 --port 8765 --profile elevenlabs Unsigned ElevenLabs post-call webhooks are rejected by default; use --allow-unsigned-webhooks only for local development.
The universal runtime surface is intentionally provider-neutral:
import dhee memory = dhee.Client(user_id="user_123", app_id="elevenlabs:support-agent") run = memory.run(task="voice support call") patch = run.before(channel="voice") run.tool("remember", content="User prefers WhatsApp follow-up.") run.finish(summary="User asked about refund status.") For an existing ElevenLabs voice agent, the minimal native path is:
from dhee import ElevenLabsAgent agent = ElevenLabsAgent( public_base_url="https://memory.example.com", user_id="user_123", agent_id="support-agent", ) conversation = agent.create_conversation(api_key="...") conversation.start_session() That keeps your ElevenLabs agent, audio interface, and callbacks intact while Dhee adds:
If you already construct Conversation(...) yourself, make the smaller patch:
memory = ElevenLabsAgent( public_base_url="https://memory.example.com", user_id="user_123", agent_id=agent_id, ) conversation = Conversation( client=elevenlabs, agent_id=agent_id, config=memory.conversation_initiation_data(), client_tools=memory.client_tools(existing_client_tools), callback_user_transcript=memory.wrap_user_transcript(on_user_transcript), callback_agent_response=memory.wrap_agent_response(on_agent_response), audio_interface=audio_interface, ) Install the optional SDK bridge with:
pip install "dhee[elevenlabs]" For hosted/server-tool deployment, use the profile helper:
dhee elevenlabs init --public-url https://memory.example.com That prints the dynamic variables, dhee_memory server tool, and post-call webhook URL. The flow is:
call start -> {{dhee_context}} during call -> dhee_memory server tool call end -> post-call webhook checkpoint next call -> better injected context The native provider lives at dhee.providers.elevenlabs and is exported as dhee.ElevenLabsAgent and dhee.ElevenAgent.
For an existing Gemini API agent, add Dhee to the existing generate_content call:
from google import genai from dhee import GeminiAgent client = genai.Client(api_key="...") memory = GeminiAgent(user_id="user_123", model="gemini-2.5-flash") response = client.models.generate_content( model=memory.model, contents="What did I ask you to remember?", config=memory.generate_content_config(), ) The config injects Dhee context as a system instruction and adds memory.dhee_memory as a Gemini Python function tool. You can also call through Dhee:
response = memory.generate_content( "Please remember I prefer concise summaries.", client=client, ) The native Gemini provider lives at dhee.providers.gemini and is exported as dhee.GeminiAgent and dhee.GeminiAPIAgent.
For an existing OpenAI Responses API agent, add Dhee to the existing request:
from openai import OpenAI from dhee import OpenAIAgent client = OpenAI(api_key="...") memory = OpenAIAgent(user_id="user_123", model="gpt-4.1") response = client.responses.create( **memory.response_create_kwargs( input="What should you remember about me?", ) ) When the model returns function_call items, Dhee can execute them and format Responses API tool outputs:
tool_outputs = memory.function_call_outputs(response) followup = client.responses.create( model=memory.model, input=tool_outputs, previous_response_id=response.id, tools=memory.tools(), ) The native OpenAI provider lives at dhee.providers.openai and is exported as dhee.OpenAIAgent and dhee.OpenAIResponsesAgent.
Dhee's repo brain answers with graph-backed evidence:
The repo brain is git-SHA scoped and persisted under .dhee/context/repo_brain/, so the agent does not rebuild the same understanding every session.
Normal memory says: "Here are some old notes."
The result is an agent that feels less random because it can see the arc.
Reproduction notes and outputs live in benchmarks/longmemeval/.
The open source package includes the local memory OS, context compiler, DheeFS, MCP servers, CLI, UI, runtime daemon, handoff bus, repo brain, update capsules, narrative scene intelligence, release checks, and proof tooling.
Team governance, hosted dashboards, org policy, and managed source connectors can build on top of these local primitives. Dhee itself is useful without a hosted account.
python3.11 -m pip install -e ".[dev,nvidia,zvec,mcp]" pytest Focused release checks:
python -m pytest tests/test_narrative_scene_intelligence.py tests/test_mcp_tools_slim.py tests/test_scene.py tests/test_temporal_scenes.py tests/test_reranker_defaults.py tests/test_nvidia_embedder.py -q python -m build python -m twine check dist/* License MIT. Built by Sankhya AI Labs.
gemini openai elevenlabs ollama nvidia zvec sqlite-vec graph swe local gemma mcp api bus benchmarks edge training app all dev
world-memory context-compiler developer-brain coding-agents mcp claude-code codex chotu local-first memory-layer ai agents
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.




