Integrating MrMemory with LangChain: A Solution to Persistent AI
Most large language models (LLMs) are stateless, starting each interaction without any context or memory. This limitation leads to wasted power and lost insight in conversational AI.
MrMemory is a REST + WebSocket API that solves this problem. It provides seven powerful primitives: remember, recall, share, auto-remember, compress, self-edit, and governance. MrMemory integrates with LangChain, enabling agents to continuously improve, personalize responses, and maintain consistent behavior across sessions.
Setting Up MrMemory
To integrate MrMemory with LangChain, you'll need to install the MrMemory package using pip:
pip install mrmemory
Next, import the MrMemory client in your Python script:
from mrmemory import MrMemory
client = MrMemory(api_key="your-key")
Using MrMemory with LangChain
Once set up, you can use MrMemory's API to store and retrieve memories. For example, let's store a memory about the user's preferences:
client.remember("user prefers dark mode", tags=["preferences"])
Later, when recalling memories related to the user's theme preference, LangChain will search for similar content using semantic recall:
results = client.recall("what theme does the user like?")
Integrating with Other Solutions
MrMemory also provides native integration with LangGraph's Long-term Memory Store. This allows agents to maintain long-term memory and continuously improve.
Other memory solutions, such as Mem0, Zep, and MemGPT, exist but lack some of MrMemory's features, like compression (40-60% token savings) and self-edit tools.
Comparison Table:
| Feature | MrMemory | Mem0 | Zep | MemGPT |
|---|---|---|---|---|
| Compression | 40-60% token savings | No | No | No |
| Self-Edit Tools | Yes | No | No | No |