DEV Community

Darren
Darren

Posted on • Originally published at mrmemory.dev

Chatbot Amnesia: Fixing It with MrMemory

My Assistant's Memory Problem

I built a chatbot with OpenAI, but every time I restarted the process, it had no recollection of our previous conversations. Serialization wasn't cutting it – context windows filled up, token costs skyrocketed, and my assistant started truncating history.

What I really needed was:

  • To store facts as they happened
  • Retrieve only what's relevant
  • Synthesize when necessary

Enter MrMemory, a library that lets you add memory to your OpenAI Agents with minimal fuss.

The Simple Loop

Here's the entire workflow in three API calls:

  1. recall(query) - pull relevant memories
  2. OpenAI completion - inject memory into system prompt
  3. retain(exchange) - store conversation

Let's dive into each step.

Step 1 — Initializing MrMemory

First, install MrMemory using pip:

pip install mrmemory
Enter fullscreen mode Exit fullscreen mode

Then, initialize the client with your API key:

from mrmemory import MrMemory
client = MrMemory(api_key="your-key")
Enter fullscreen mode Exit fullscreen mode

Now you can start storing facts about user interactions.

Step 2 — Storing and Retrieving Facts

Store a fact like this:

client.remember("user prefers dark mode", tags=["preferences"])
Enter fullscreen mode Exit fullscreen mode

And retrieve it when needed:

results = client.recall("what theme does the user like?")
Enter fullscreen mode Exit fullscreen mode

Why MrMemory?

Other solutions, like Mem0 and Zep, require vector databases or RAG pipelines. Not MrMemory – its simple API lets you add memory in just three calls.

Conclusion

Adding memory to your OpenAI Agents doesn't have to be a headache. With MrMemory, you can store facts as they happen, retrieve only what's relevant, and synthesize when necessary.

Try it out today with our 7-day free trial:

Sign up

Related Posts

Top comments (0)