Observable Memory Infrastructure for AI Agents
The only memory layer with provenance, confidence decay, and OpenTelemetry observability.
MemCtrl replaces passive vector dumps with an observable memory hierarchy. Agents don't just "retrieve similar text" โ they reason over structured layers, forget irrelevant details, consolidate experience, and show exactly how every decision was made.
# Via pip
pip install memctrl
# Or via uv (fast, no global install needed)
uvx memctrl
memctrl init
memctrl add "we use FastAPI + PostgreSQL + Redis cache"
memctrl query "what is our stack?"
# โ root -> project -> tech_stack -> FastAPI + PostgreSQL + Redis cacheEvery answer shows its reasoning path. No black-box similarity scores. No forgotten context.
Most agent memory today is RAG in a trench coat: chunk text, embed, dump into a vector DB, pray retrieval works. That fails for agents that need to:
- Remember architectural decisions forever
- Forget yesterday's debugging session automatically
- Consolidate scattered session notes into project knowledge
- Show exactly how it found a memory
- Prove that retrieved memories haven't been poisoned
The research is clear: 95% of agent pilots fail โ and memory is the primary cause (MIT NANDA, 2025). Enterprises don't need better embeddings. They need memory they can observe, audit, and trust.
| Capability | Vector RAG | MemCtrl |
|---|---|---|
| Retrieval logic | Cosine similarity (black box) | ๐ฒ Hierarchical tree traversal with reasoning trace |
| Explainability | "Score: 0.87" | root โ project โ backend โ fastapi |
| Lifespan control | Manual cleanup | ๐ Rule-driven expiry + never-forget lists |
| Knowledge consolidation | None | ๐ Automatic session โ project merging |
| Memory provenance | None | โ Full audit trail: source, confidence, trace |
| Observability | None | ๐ OpenTelemetry gen_ai.memory.* exporter |
| Confidence decay | Static forever | โณ Inferred facts decay; explicit facts persist |
| Privacy | Cloud embeddings | ๐ Local SQLite. Your data never leaves your machine. |
| Retrieval cost | Per-query embedding API | ๐ฐ Zero API calls. Tree fits in context. |
MemCtrl implements a human-like memory pipeline with full observability:
graph TD
A[Input: Chat / Code / Events] --> B[Security Scan]
B --> C[Memory Extractor]
C --> D{Confidence Scoring}
D --> E[Working Memory]
E --> F[Reflection Engine]
F --> G[Compression Layer]
G --> H[Long-Term Memory]
E --> I[Episodic Memory]
I --> J[Forgetting & Expiry]
I --> K[Confidence Decay]
H --> L[Tree-Based Retrieval]
I --> L
L --> M[Retrieval Provenance]
M --> N[OpenTelemetry Export]
| Layer | Analog | Purpose | Default Lifespan |
|---|---|---|---|
| ๐๏ธ Project | Semantic memory | Architecture, tech stack, ADRs, "why we chose X" | Forever |
| ๐ Session | Working memory | Current task, WIP, what was done today | 7 days |
| ๐ค User | Episodic memory | Preferences, working style, coding patterns | 90 days |
Rules in .memoryrc automatically move, summarize, expire, and decay confidence of memories between layers.
# Option 1: pip
pip install memctrl
# Option 2: uv โ fast, modern Python packaging
uvx memctrl # run without installing
# or
uv tool install memctrl # install permanently
memctrl init # creates .memoryrc + .memctrl/ in your project
memctrl install # registers SKILL.md with your AI assistantThen open your AI assistant and type:
Please analyze this project and store what you learn in memctrl.
Later, ask:
What did we decide about authentication?
# โ MemCtrl retrieves with full provenance:
# Fact: "JWT auth with refresh tokens"
# Source: explicit (confidence: 1.0)
# Trace: root โ project โ architecture โ auth
# Why matched: exact keyword match + high confidence
Register the skill with your AI assistant:
| Platform | Command |
|---|---|
| Claude Code | memctrl install --tool claude_code |
| Codex | memctrl install --tool codex |
| Cursor | memctrl install --tool cursor |
| Kimi Code | memctrl install --tool kimi |
| Pi | memctrl install --tool pi |
| AxGa | memctrl install --tool axga |
Project-scoped install (commits into your repo):
memctrl install --project| Command | Description |
|---|---|
memctrl init |
Create .memoryrc + .memctrl/ in current directory |
memctrl add <text> |
Add a memory (default layer: session) |
memctrl add <text> --layer project |
Add a permanent project memory |
memctrl query <question> |
Retrieve memories with reasoning trace |
memctrl list |
List all memories (optionally --layer project) |
memctrl tree |
Display the memory tree (Rich-formatted) |
memctrl heatmap |
Show memory distribution by layer and tags |
memctrl timeline |
Show chronological memory events |
memctrl forget <id> |
Remove a specific memory |
memctrl clear |
Clear all memories or a specific layer |
| Command | Description |
|---|---|
memctrl trigger <event> |
Manually fire a trigger rule |
memctrl audit |
Show complete trigger audit log |
memctrl doctor |
Report stale memories, provenance gaps, risky sources, and OTel health |
memctrl done |
Explicit session end โ immediate consolidation |
memctrl reflect |
Check heuristics โ consolidate if any fire |
memctrl serve |
Start MCP server (stdio transport) |
memctrl --version |
Show version |
| Command | Description |
|---|---|
memctrl otel-export |
Export memory spans to JSON |
memctrl otel-stats |
Show memory operation statistics |
- ๐ก๏ธ Secret Redaction โ API keys, tokens, passwords, AWS keys, and private keys are automatically detected and replaced with
[REDACTED_<LABEL>]before storage. - ๐ PII Redaction โ Emails, SSNs, and phone numbers are sanitized.
- ๐ซ Never-Forget List โ Memories containing
passwords,keys,PII, orsecretsare blocked from auto-deletion. - ๐ Local-Only Default โ All data lives in
.memctrl/memories.dbinside your project. No cloud. No telemetry. No analytics. - ๐ Memory Poisoning Detection โ Retrieval provenance tracks the source of every memory, enabling detection of injected/poisoned memories.
Created automatically by memctrl init:
[memctrl]
db_path = ".memctrl/memories.db"
[layers]
project = "architecture decisions, tech stack, ADRs, why we chose X"
session = "current task, WIP, what was done this session"
user = "preferences, working style, patterns, personal rules"
[triggers]
on_commit = "consolidate session -> project"
on_session_end = "summarize session -> user"
'on_file "docs/ADR-*.md"' = "extract -> project"
'on_file "*.md"' = "extract -> project if contains decision"
[forget]
never = ["passwords", "keys", "PII", "secrets"]
after_days = { session = 7, user = 90 }
[extract]
confidence = { explicit = 1.0, inferred = 0.7, mentioned = 0.5 }Hot-reload enabled: edit .memoryrc and changes apply immediately.
MemCtrl exposes an MCP server for deep IDE integration using stdio transport:
memctrl serveAvailable tools:
memctrl_queryโ Ask the memory treememctrl_addโ Add a memory programmaticallymemctrl_triggerโ Fire automation rulesmemctrl_treeโ Get structured tree JSONmemctrl_auditโ Read the trigger log
Register with Claude Code / Cursor / Kimi Code via MCP config:
{
"mcpServers": {
"memctrl": {
"command": "memctrl",
"args": ["serve"],
"env": {}
}
}
}MemCtrl is designed to plug into existing agent stacks:
| Framework | Status | Notes |
|---|---|---|
| MCP | โ Ready | Stdio transport server included |
| Claude Code | โ Ready | memctrl install --tool claude_code |
| LangGraph | โ Ready | MemCtrlSaver checkpoint + MemoryNode (requires pip install "memctrl[langgraph]") |
| OpenTelemetry | โ Ready | First reference implementation for gen_ai.memory.* conventions |
| CrewAI | ๐ง Planned | Long-term memory backend |
| AutoGen | ๐ง Planned | Agent memory provider |
| OpenAI Agents SDK | ๐ง Planned | Context persistence layer |
from langgraph.graph import StateGraph
from memctrl.integrations.langgraph import MemCtrlSaver, MemoryNode
workflow = StateGraph(...)
workflow.add_node("memory", MemoryNode())
workflow.add_edge("agent", "memory")
# Persistent checkpoints with MemCtrl
app = workflow.compile(checkpointer=MemCtrlSaver())from memctrl.otel_exporter import MemoryOTelExporter
exporter = MemoryOTelExporter(service_name="my-agent")
exporter.start()
# All memory operations are automatically traced
exporter.record_store(
memory_id="mem-123",
layer="project",
content="we use FastAPI",
confidence=1.0,
)
# Export to Datadog, Grafana, Jaeger, Honeycomb...
exporter.export_otlp_json("spans.json")MemCtrl includes a small retention benchmark for local experimentation. Treat it as a harness for testing retrieval behavior, trace coverage, and memory-management overhead as the project evolves; it is not a validated vector database comparison yet.
| Metric | Baseline (Vector RAG) | MemCtrl | Improvement |
|---|---|---|---|
| Context retention | Demo harness only | No validated claim yet | Pending |
| Retrieval explainability | Demo harness only | No validated claim yet | Pending |
| Memory management overhead | Demo harness only | No validated claim yet | Pending |
| Long-horizon task success | Not measured | Not measured | Pending |
| Repeat query latency | Local cache check | Environment dependent | Pending |
๐ Run benchmarks locally:
python benchmarks/retention_benchmark.py
Before publishing performance claims, run a larger benchmark with real vector baselines, enough queries for variance, and documented methodology.
- Hierarchical tree-based retrieval (PageIndex-inspired)
- Rule-governed memory layers (project/session/user)
- Security scanning (secrets, PII)
- MCP server
- CLI with rich formatting
- Project-local database isolation
- Confidence Decay โ Inferred facts decay if not reinforced
- Query Result Cache โ Repeat queries return in <1ms
- Reflection Engine โ Auto-detect session end (git/time/explicit)
- Incremental Tree Rebuild โ Only rebuild affected branches
- Benchmark Harness โ Documented, reproducible methodology
- LangGraph Verification โ 13 tests, honest status
- Retrieval Provenance โ Full audit trail for every retrieval
- OpenTelemetry Exporter โ First reference implementation for
gen_ai.memory.* - Memory Span โ Context manager for operation tracing
- Memory Poisoning Detection โ MINJA attack defense
- Procedural Memory โ Workflow/rule storage (blue ocean)
- Multi-agent Consistency โ Shared project layer across agents
- Confidence Drift Detection โ Alert when memories go stale
- Self-modeling (agent knows what it knows)
- Behavioral adaptation from memory
- Autonomous memory optimization
- Cross-project user layer sharing
Run the repeated-bug demo for the sharpest product story:
python examples/killer_demo.pyIt simulates a coding agent that remembers an old JWT middleware incident and avoids repeating the same production bug in a later sprint.
See examples/coding_agent_demo.py for a broader multi-session simulation:
python examples/coding_agent_demo.pyThis demo simulates an AI coding agent working across multiple sessions. Watch how MemCtrl:
- Remembers architectural decisions forever (project layer)
- Tracks daily tasks in session layer
- Automatically consolidates session notes into project knowledge
- Shows the exact reasoning trace for every retrieval
- Decays confidence of old inferred facts
| Requirement | Minimum | Recommended |
|---|---|---|
| Python | 3.10+ | 3.12+ |
| SQLite | bundled with Python | โ |
| Package manager | pip | uv |
Install via pip:
pip install memctrlInstall via uv (faster, no global clutter):
uvx memctrl # run once, no install
uv tool install memctrl # install as a toolOptional LLM backends (for extraction only):
| Backend | Setup |
|---|---|
| OpenAI | export OPENAI_API_KEY=sk-... |
| LiteLLM | Any provider OpenAI-compatible |
| Local | Ollama (set MEMCTRL_LLM_BASE_URL) |
Optional observability backends:
| Backend | Setup |
|---|---|
| Datadog | OTLP receiver enabled |
| Grafana/Jaeger | OTLP collector running |
| Honeycomb | Direct OTLP ingestion |
git clone https://github.com/KJ-AIML/memctrl.git
cd memctrl
pip install -e ".[llm,dev]"
pytest tests/ -vMIT ยฉ 2025 MemCtrl Contributors
