Hierarchical memory for AI agents. Three-layer (buffer/working/core) with decay and promotion.
io.github.kael-bit/engram MCP Server
The io.github.kael-bit/engram MCP server provides hierarchical memory for AI agents. It implements a three-layer structure (buffer/working/core) with decay and promotion to manage how information moves and degrades over time.
π οΈ Key Features
Hierarchical memory model for AI agents
Three layers: buffer, working, core
Decay and promotion behavior
π Use Cases
Supporting AI agents that require structured memory
Memory engine for AI agents. Two axes: time (three-layer decay & promotion) and space (self-organizing topic tree). Important memories get promoted, noise fades, related knowledge clusters automatically.
Most agent memory is a flat store β dump everything in, keyword search to get it back. No forgetting, no organization, no lifecycle. engram-rs adds the part that makes memory actually useful: the ability to forget what doesn't matter and surface what does.
engram demo β store, context reset, recall
Single Rust binary, one SQLite file, zero external dependencies. No Python, no Redis, no vector DB β curl | bash and it runs. ~10 MB binary, ~100 MB RSS, single-digit ms search latency.
Quick Start
bash
# Install (interactive β will prompt for embedding provider config)
curl -fsSL https://raw.githubusercontent.com/kael-bit/engram-rs/main/install.sh | bash
# Store a memory
curl -X POST http://localhost:3917/memories \
-d '{"content": "Always run tests before deploying", "tags": ["deploy"]}'# Recall by meaning
curl -X POST http://localhost:3917/recall \
-d '{"query": "deployment checklist"}'# Restore full context (session start)
curl http://localhost:3917/resume
Buffer: Entry point for all new memories. Temporary staging β evicted when below threshold
Working: Promoted via consolidation. Never deleted, importance decays at different rates by kind
Core: Promoted through LLM quality gate. Never deleted
LLM Quality Gate
Promotion isn't rule-based guesswork β an LLM evaluates each memory in context and decides whether it genuinely warrants long-term retention.
code
Buffer β [LLM gate: "Is this a decision, lesson, or preference?"] β Working
Working β [sustained access + LLM gate] β Core
Automatic Decay
Decay is activity-driven β it only fires during active consolidation cycles, not wall-clock time. If the system is idle, memories stay intact.
Exponential decay follows the Ebbinghaus forgetting curve β fast at first, then long-tail. Memories never fully vanish (floor = 0.01), remaining retrievable under precise queries. When a memory is recalled, it gets an activation boost, strengthening frequently-used knowledge.
Kind
Decay rate
Half-life
Use case
episodic
Fastest
~35 epochs
Events, experiences, time-bound context
semantic
Medium
~58 epochs
Knowledge, preferences, lessons (default)
procedural
Slowest
~173 epochs
Workflows, instructions, how-to
Algorithm Visualizations
Chart
What it shows
Sigmoid score compression. Raw scores are mapped through a sigmoid function, approaching 1.0 asymptotically. High-relevance results remain distinguishable instead of being crushed into the same value.
Ebbinghaus forgetting curve. Exponential decay with kind-differentiated rates β episodic memories fade fastest, procedural slowest. Floor at 0.01 means memories never fully vanish; they remain retrievable under precise queries.
Kind Γ layer weight bias. Additive biases adjust memory weight by type and layer. Procedural+core memories rank highest, episodic+buffer lowest β but the spread stays bounded so no single combination dominates.
Reinforcement signals. Repetition and access bonuses follow logarithmic saturation. Early interactions matter most; later ones contribute diminishing returns, discriminating between "used occasionally" and "used daily".
Use it or lose it. Left: a memory that's never recalled decays into the buffer layer. Right: periodic recall triggers activation boosts that keep the memory in the working layer. Dashed line shows the unrecalled trajectory for comparison.
Semantic Dedup & Merge
Two memories saying the same thing in different words? Detected and merged automatically:
code
"use PostgreSQL for auth" + "auth service runs on Postgres"
β Merged into one, preserving context from both
Self-Organizing Topic Tree
Vector clustering groups related memories together, LLM names the clusters. No manual tagging required:
The problem this solves: vector search requires asking the right question. Topic trees let agents browse by subject β scan the directory, drill into the right branch.
Triggers
Tag a memory with trigger:deploy, and the agent can recall all deployment lessons before executing:
bash
curl -X POST http://localhost:3917/memories \
-d '{"content": "LESSON: always backup DB before migration", "tags": ["trigger:deploy", "lesson"]}'# Pre-deployment check
curl http://localhost:3917/triggers/deploy
Session Recovery
Agent wakes up, calls GET /resume, gets full context back. No file scanning needed:
code
=== Core (24) ===
deploy: test β build β stop β start (procedural)
LESSON: never force-push to main
...
=== Recent ===
switched auth to OAuth2
published API docs
=== Topics (Core: 24, Working: 57, Buffer: 7) ===
kb1: "Deploy Procedures" [5]
kb2: "Auth Architecture" [3]
kb3: "Memory Design" [8]
...
Triggers: deploy, git-push, database-migration
Section
Content
Purpose
Core
Full text of permanent rules and identity
The unforgettable stuff
Recent
Recently changed memories
Short-term continuity
Topics
Topic index (table of contents)
Drill in on demand, no full load
Triggers
Pre-action tags
Auto-recall lessons before risky ops
Agent reads the directory, finds relevant topics, calls POST /topic to expand on demand.
Search & Retrieval
Semantic embeddings + BM25 keyword search with CJK tokenization (jieba). IDF-weighted scoring β rare terms get boosted, common terms auto-downweighted. No stopword lists to maintain.
bash
# Semantic search
curl -X POST http://localhost:3917/recall \
-d '{"query": "how do we handle auth", "budget_tokens": 2000}'# Note: min_score defaults to 0.30. Use "min_score": 0.0 to get all results.# Topic drill-down
curl -X POST http://localhost:3917/topic \
-d '{"ids": ["kb3"]}'
Background Maintenance
Fully automatic, activity-driven β no writes means the cycle is skipped:
Consolidation (every 30 minutes)
Decay β reduce importance of unaccessed memories
engram-rs works without an LLM β keyword search and rule-based lifecycle still function. Adding an LLM unlocks intelligent features (triage, gate, merge, topic naming):
bash
export ENGRAM_LLM_URL=https://api.openai.com/v1
export ENGRAM_LLM_KEY=sk-...
# Any OpenAI-compatible API (Ollama, LM Studio, etc.)export ENGRAM_LLM_URL=http://localhost:11434/v1
# Anthropic nativeexport ENGRAM_LLM_PROVIDER=anthropic
export ENGRAM_LLM_KEY=sk-ant-...
Two-tier model config β strong model for judgment, lightweight for text processing:
bash
ENGRAM_GATE_MODEL=gpt-4o # quality decisions
ENGRAM_LLM_MODEL=gpt-4o-mini # text processing
For AI Agents
Add to your agent's system prompt:
code
Set up engram-rs (persistent memory) by following the guide at:
https://raw.githubusercontent.com/kael-bit/engram-rs/main/docs/SETUP.md
Integration
Works with Claude Code, Cursor, Windsurf, OpenClaw, and any MCP-compatible tool.