elfmem: Adaptive Memory System That Lets AI Agents Learn, Forget, and Evolve Like Biological Memory
The Tool
elfmem is a new Python library that gives LLM agents a biologically-inspired memory system — knowledge that gets stronger when used, fades when ignored, and is structured in a knowledge graph for recovery. It's available on GitHub with zero infrastructure requirements.
The Problem It Solves
LLM agents are fundamentally stateless:
- Every session starts from zero
- Context windows fill up and reset
- RAG retrieves documents but never learns from them
- Most memory solutions require external infrastructure (vector DBs, Redis, Postgres)
How elfmem Works
Core Concepts
Adaptive Decay: Knowledge survives when reinforced through use, fades when ignored. A session-aware clock means your agent's memory doesn't decay over weekends.
SELF Frame: Persistent agent identity. Values, style, and constraints survive across sessions with near-permanent retention.
Knowledge Graph: Related-but-not-identical knowledge is always recoverable through graph connections.
Contradiction Detection: Automatically identifies and resolves conflicting knowledge.
Usage
import asyncio
from elfmem import MemorySystem
system = await MemorySystem.from_config("agent.db", {
"llm": {"model": "claude-sonnet-4-6"},
"embeddings": {"model": "text-embedding-3-small"},
})
async with system.session():
await system.learn("Use Celery with Redis for background tasks.")
identity = await system.frame("self")
context = await system.frame("attention", query="background job processing")
Infrastructure
- Zero infrastructure — uses a single SQLite file
- MCP native support
- Python SDK with async/await
- Available on PyPI
Comparison
| Feature | elfmem | mem0 | LangChain Memory | Chroma/Weaviate |
|---|---|---|---|---|
| Infrastructure | None (SQLite) | Postgres/Redis | In-memory | Vector DB server |
| Adaptive decay | Yes | No | No | No |
| Knowledge graph | Yes | No | No | No |
| Contradiction detection | Yes | No | No | No |
Why It Matters
This is a fundamental shift in how agents maintain state:
- Agents can truly learn from their experiences, not just retrieve documents
- No infrastructure overhead — perfect for solo developers and small teams
- MCP support means it integrates with the emerging agent interoperability standard
- Biological inspiration may prove more effective than brute-force vector search
GitHub: github.com/emson/elfmem