Deconstruct language with Peirce's semiotics. Govern group memory with game theory. The first AI memory layer that mines your agent's subconscious β and lets a swarm of agents argue out their disagreements.
Every time you open a new chat, it forgets what worked yesterday. Every time two agents disagree, the loudest one wins. Every time you fix a bug, the next agent asks the same question again.
DeepMemory fixes this in 5 lines of code.
It's not another vector database. It's a governance layer β built on 100 years of semiotic philosophy (Charles Sanders Peirce's sign / object / interpretant triad) and 80 years of game theory (Vickrey, Nash, Shapley). All of it compiled into pure Python that runs on your laptop. No OpenAI key. No GPU. No cloud.
π New here? Start with Getting Started (15 min).
import random
from deepmemory.cognition.bandit import ThompsonRanker
from deepmemory.cognition.bayesian import BayesianConfidenceEngine, FeedbackSignal
from deepmemory.policies.cognition import BayesianBanditCognitionPolicy
from deepmemory.runtime.engine import DeepMemoryRuntime
from deepmemory.runtime.feedback import record_recall_feedback
from deepmemory.storage.in_memory import InMemoryMemoryStore
# Set up a memory that *learns*
bayesian = BayesianConfidenceEngine(cold_start_threshold=2.0)
runtime = DeepMemoryRuntime(
store=InMemoryMemoryStore(),
cognition=BayesianBanditCognitionPolicy(
bayesian, ThompsonRanker(bayesian, rng=random.Random(42))
),
)
# Use it like normal β but feed back what worked
top = runtime.recall_for_object("module:upload")[0]
record_recall_feedback(runtime, top.memory_id, FeedbackSignal.RECALLED_USED)That's it. Five lines and your agent now learns from feedback.
π Verified jump: top-1 hit rate from 20.5% β 66.8%, p < 1e-6 (Phase 1 A/B report).
| You've tried... | And hit this wall... | DeepMemory's answer |
|---|---|---|
| π Stuffing context into every prompt | "I told you yesterday!" Your AI forgets across sessions. | Persistent + learns which notes deserve trust |
| π Vanilla RAG / vector DB | Retrieves similar, not correct. The wrong answer is the most-similar answer. | Bayesian posterior per memory β the system grades itself |
| π€ OpenAI Assistants API | $$, vendor lock-in, no idea why it picks what it picks. | 100% local, free, fully introspectable |
| π Hand-rolled SQL "memory" tables | No conflict detection, no decay, no rep system, no joy. | All built in. Optional. Boring to set up. Dramatic in effect. |
| βοΈ LangChain memory chains | Heavy deps, opaque ranking, breaks every release. | 5-line opt-in. Transparent algorithms. No magic. |
We didn't invent memory governance. We stole the answer from two century-old academic traditions and compiled them into Python.
Charles Sanders Peirce, 1900s philosopher, figured out something LLMs
still struggle with: a sign isn't the thing it points to. Your AI
saying "fix the lock" is a sign; the actual lock contention bug is the
object; the agent's interpretation of why it works is the
interpretant. Most memory systems collapse all three. DeepMemory keeps
them apart, then runs Bayesian inference on the interpretant to learn
which interpretations actually pay off.
That's how we mine your agent's subconscious: by tracking, per memory, which interpretations get rewarded by reality.
When 2+ agents disagree about the same object, you need a way to settle it that doesn't reward the loudest voice. We use:
- Vickrey auctions (Nobel-prize algorithm) β memories bid for attention; honest bidding is the dominant strategy.
- Nash equilibrium β when two agents contradict, solve the bimatrix game; output is an adoption probability per memory.
- Shapley values β fairly attribute credit when a recall set collectively succeeds.
- Reputation + VCG β agents who consistently produce useful notes earn admission privileges; spammers get throttled in ~6 rounds.
This is how we stop semantic drift in agent populations: by giving the math, not the loudest agent, the final word.
Each layer is opt-in and stacks on the previous one.
| Module | One-line description |
|---|---|
BayesianConfidenceEngine |
Beta distribution per memory. Learns from every "this worked" / "this didn't". |
ThompsonRanker |
Multi-armed bandit ranking. Balances "use what's proven" with "try what's new". |
Bm25Index / TfidfIndex |
Search across memories by meaning, not just by ID. |
ContradictionDetector |
Auto-flags "should X" vs "should not X" pairs for human review. |
EwmaRegistry / CUSUM |
Useful memories get a longer life; stale ones decay faster. |
MctsMemoryComposer |
Find the best combination of memories for a complex task. |
| Module | One-line description |
|---|---|
VickreyAuction |
Memories silently bid for attention. The winner gets shown; honest bidding wins. |
solve_nash |
Two memories disagree? Solve the equilibrium, output adoption probabilities. |
shapley_* |
A team of memories nailed it. Who deserves how much credit? |
ReputationRegistry + VcgMechanism |
Reputation that learns. Spammers throttled. Top contributors fast-tracked. |
- Restart-safe β append-only JSONL on every state store
- Thread-safe β
RLockeverywhere; multi-threaded use officially supported - Observable β
runtime.cognition_failedevents;cognition_degradedflag on degraded recalls - Manageable β 17 CLI commands, including
reputation-list,state-compact,beta-state-export
Phase 1 β Probabilistic Foundation
baseline: 20.5% top-1 hit rate
challenger: 66.8% top-1 hit rate β +46.3pp, p < 1e-6
Phase 3 β Game-Theoretic Governance (multi-agent)
baseline: 96.8% top-1 hit rate
challenger: 100.0% top-1 hit rate β Vickrey is *deterministic*
Phase 4 β Reputation in Action (3 agents, 50 rounds, 1 spammer)
spammer detected by round ~6
expected_task_success: 0.860 β 0.882
Reproduce: PYTHONPATH=. python3 scripts/run_phase1_ab.py --seeds 1,2,3,4,5
git clone <repo> && cd deepmemory
python3 -m venv .venv && source .venv/bin/activate # recommended: use a venv
pip install -e . # core install (pure stdlib, zero external deps)
deepmemory version # β deepmemory 2.1.0-rc1
deepmemory capabilities # see what's insideDeepMemory core has zero external dependencies (pure stdlib). Install extras as needed:
pip install -e ".[http]" # HTTP server (FastAPI + Uvicorn + Pydantic)
pip install -e ".[mcp]" # MCP server (Model Context Protocol)
pip install -e ".[dev]" # dev deps (includes http + pytest)
pip install -e ".[http,mcp]" # both HTTP and MCPRun DeepMemory as a long-lived REST service so any HTTP-capable client (Go, Node,
front-end, gateways) can integrate without coupling to the Python SDK. The HTTP
surface coexists with the stdio MCP server β both wrap the same
DeepMemoryFacade.
pip install -e '.[http]'
DEEPMEMORY_STORE=./artifacts/memory.jsonl deepmemory-http
# β uvicorn on http://127.0.0.1:8765
# β OpenAPI: http://127.0.0.1:8765/openapi.json
# β Swagger UI: http://127.0.0.1:8765/docsEndpoints (all under /api/v1/):
| Method | Path | Purpose |
|---|---|---|
| GET | /health |
liveness + memory count + daemon status |
| POST | /memory/ingest |
create one memory unit |
| GET | /memory/recall?object_id=β¦ |
recall by object |
| POST | /memory/recall_multi |
batch recall + dedupe + status-priority sort |
| POST | /memory/recall_by_prefix |
prefix scan over object_id (handles LLM key drift) |
| POST | /memory/{id}/promote |
governance state transition |
| POST | /memory/{id}/revise |
update claim / confidence / context |
| DELETE | /memory/{id} |
delete with reason |
| POST | /memory/ingest_async |
enqueue raw turn text β LLM extraction worker |
| GET | /memory/ingest_async/{task_id} |
poll async task status |
| POST | /memory/evolve |
run one evolution cycle on demand |
| GET | /memory/events |
tail event log |
All responses use the envelope {"code": 0, "message": "ok", "data": β¦}.
| Variable | Default | Effect |
|---|---|---|
DEEPMEMORY_STORE |
./artifacts/memory.jsonl |
JSONL store path; events go alongside as *_events.jsonl |
DEEPMEMORY_DEFAULT_ACTOR |
http-server |
actor_ref for server-originated writes |
DEEPMEMORY_HTTP_HOST / DEEPMEMORY_HTTP_PORT |
127.0.0.1 / 8765 |
bind address |
DEEPMEMORY_API_TOKEN |
(unset) | when set, all endpoints except /health require Authorization: Bearer β¦ |
DEEPMEMORY_EVOLVE_INTERVAL_HOURS |
0 |
when > 0 launches the in-process evolution daemon |
DEEPMEMORY_EVOLVE_MIN_CONFIDENCE / DEEPMEMORY_EVOLVE_STALE_HOURS / DEEPMEMORY_EVOLVE_MAX_PER_OBJECT |
0.35 / 168 / 20 |
daemon EvolutionPolicy overrides |
/health is intentionally exempt from auth so that K8s liveness / readiness
probes work without leaking the token. The response includes
extractor_llm β {noop, configured, none} β see the production note
below.
The default AsyncExtractor (used when deepmemory-http starts without an
explicit client wired in) falls back to a _NoopLLM stub that always returns
"[]". The /memory/ingest_async endpoint will look healthy at the protocol
layer (200 OK, task transitions queued β running β done) but no
MemoryUnits will ever be produced β ingested stays [] and recall keeps
returning empty.
Two ways to detect this:
GET /healthreturnsextractor_llm: "noop"when the stub is in use.- The wire-it-in path: build a client implementing
async def acomplete(prompt, **kw) -> _LLMResponse(a duck-typed object with a.contentJSON string) and pass it to the extractor:
from deepmemory import DeepMemoryFacade
from deepmemory.runtime.async_extractor import AsyncExtractor
from deepmemory.http_server import create_app
facade = DeepMemoryFacade(store_path="./artifacts/memory.jsonl",
event_path="./artifacts/events.jsonl")
extractor = AsyncExtractor(facade=facade, llm_client=my_real_llm_client)
app = create_app(facade=facade, extractor=extractor)Alternatively, do the LLM-side extraction in your gateway and call the
synchronous /memory/ingest endpoint with already-structured triples β
that path has no LLM dependency.
Run DeepMemory as an MCP tool server for AI toolchains (Claude Desktop, Cursor, etc.):
pip install -e ".[mcp]"
deepmemory-mcp
# or: python -m deepmemory.mcp_serverMCP client configuration example:
{
"mcpServers": {
"deepmemory": {
"command": "python",
"args": ["-m", "deepmemory.mcp_server"],
"env": {"DEEPMEMORY_STORE": "./artifacts/memory.jsonl"}
}
}
}| Mode | Best for | Start command | Dependencies |
|---|---|---|---|
| CLI | Daily ops, quick testing | deepmemory ingest/recall/... |
Core install |
| Python SDK | Embed in agent code | import deepmemory |
Core install |
| HTTP server | Microservice / gateway integration | deepmemory-http |
pip install ".[http]" |
| MCP server | AI toolchain (Claude/Cursor) | deepmemory-mcp |
pip install ".[mcp]" |
# Who do I trust?
deepmemory reputation-list --state-dir ./agent_state
# What's contradicting itself?
deepmemory conflict-scan --events events.jsonl
# Inspect a memory's confidence
deepmemory beta-state-export --state-dir ./agent_state --memory-id mu_xxx
# Punish a spammer manually
deepmemory reputation-set --state-dir ./agent_state --actor X --delta -0.5
# Reclaim disk
deepmemory state-compact --state-dir ./agent_state
# v1 stable lifecycle (unchanged)
deepmemory ingest / recall / promote / revise / delete
deepmemory run-harness / run-drift-audit / run-evolution| You are... | Read this |
|---|---|
| π Brand new | Getting Started (15 min) (δΈζ) |
| β¬οΈ Upgrading from v1 | Migration Guide (δΈζ) |
| π Going to production | Deployment Guide (δΈζ) |
| π On-call SRE | Operations Runbook (δΈζ) |
| β Just curious | FAQ (δΈζ) |
| π Schema-pedantic | core-schema v0.2 (δΈζ) |
| π€ Compat-pedantic | compatibility-statement (δΈζ) |
| π§ Philosophical | v2 Grand Summary |
| π Everything | docs/README.md |
deepmemory/
βββ core/ # Sign / Object / Interpretant β Peirce's triad as code
βββ runtime/ # Lifecycle engine, hooks, persistence layout
βββ cognition/ # Pure-stdlib algorithm layer
β βββ bayesian/ # Beta posteriors learn from feedback
β βββ bandit/ # Thompson sampling β explore vs exploit
β βββ similarity/ # TF-IDF Β· BM25 Β· contradiction detection
β βββ timeseries/ # EWMA Β· CUSUM
β βββ mcts/ # Monte Carlo composition search
βββ gametheory/ # Pure-stdlib game theory layer
β βββ auction/ # Vickrey
β βββ nash/ # Bimatrix support enumeration
β βββ shapley/ # Exact + Monte Carlo
β βββ evolutionary/# Replicator dynamics
β βββ mechanism/ # Reputation + VCG
βββ policies/ # 4 cognition policies + game policies
βββ harness/ # Event-driven metrics + paired A/B comparison
βββ packs/coding/ # Coding-domain pack
βββ adapters/ # External substrate adapters
βββ cli/ # 17 CLI commands
examples/ # Runnable demos for each layer
scripts/ # A/B benchmark scripts
tests/ # 304 tests, zero regression on v1 baseline
docs/ # Bilingual user docs (en + zh)
python3 -m pytest # 304 tests, ~0.5s
PYTHONPATH=. python3 examples/bayesian_evolution_demo.py
PYTHONPATH=. python3 scripts/run_phase1_ab.py --seeds 1,2,3,4,5MIT.
v2.1.0-rc1 is in closed-R&D phase β no production users yet. Schema and APIs are stabilizing; minor breaking changes still allowed before the first true GA. Old v0.1 jsonl files auto-migrate to v0.2 on read; 51 v1 tests pass byte-level identical.
"Semiotics deconstructs individual cognition. Game theory empowers collective intelligence."
β DeepMemory v2 design philosophy
β If this resonates, drop a star β it's how we know the philosophical bet is paying off.