<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mamlesh VA</title>
    <description>The latest articles on DEV Community by Mamlesh VA (@mamleshva).</description>
    <link>https://dev.to/mamleshva</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4074763%2Fe7806d5f-2701-47d5-bec4-8a1940d79b5a.png</url>
      <title>DEV Community: Mamlesh VA</title>
      <link>https://dev.to/mamleshva</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mamleshva"/>
    <language>en</language>
    <item>
      <title>MemDream: long-term memory for AI agents that keeps itself correct</title>
      <dc:creator>Mamlesh VA</dc:creator>
      <pubDate>Tue, 24 Nov 2026 08:19:48 +0000</pubDate>
      <link>https://dev.to/mamleshva/memdream-long-term-memory-for-ai-agents-that-keeps-itself-correct-42hn</link>
      <guid>https://dev.to/mamleshva/memdream-long-term-memory-for-ai-agents-that-keeps-itself-correct-42hn</guid>
      <description>&lt;p&gt;MemDream: long-term memory for AI agents that keeps itself correct&lt;/p&gt;

&lt;p&gt;An open-source Python library that decides whether each new fact adds to, replaces, or merges with what your agent already knows, then tidies up in the background.&lt;/p&gt;

&lt;p&gt;Tell your agent "I live in Chennai." A month later, tell it "I moved to Bangalore last month."&lt;/p&gt;

&lt;p&gt;Most agent memory is a vector database with an add() call, so it now holds both facts. Ask "where does the user live?" and you get whichever sentence is worded closer to the question. Nothing was missing from memory. The problem is that nothing ever decided which fact is still true.&lt;/p&gt;

&lt;p&gt;I built MemDream to make that decision. It's an open-source Python library (Apache 2.0) that gives an AI agent long-term memory that maintains itself.&lt;/p&gt;

&lt;p&gt;pip install memdream&lt;/p&gt;

&lt;p&gt;What it does&lt;/p&gt;

&lt;p&gt;Every new fact is compared with what the agent already knows about that user, and one of four things happens:&lt;/p&gt;

&lt;p&gt;Decision    When    What happens to the old memory&lt;br&gt;
ADD A genuinely new fact    Nothing&lt;br&gt;
SUPERSEDE   It contradicts something stored Kept as history, marked superseded, linked to its replacement&lt;br&gt;
MERGE   The same fact, said better  Kept as history, linked to the canonical version&lt;br&gt;
NOOP    It adds nothing Unchanged, and the reason is recorded&lt;/p&gt;

&lt;p&gt;Then, in the background, a process called Dream reads across a user's memories, writes down patterns that no single memory states, and retires facts that are no longer true.&lt;/p&gt;

&lt;p&gt;Thirty seconds of code&lt;br&gt;
from memdream import MemDream&lt;/p&gt;

&lt;p&gt;mem = MemDream(&lt;br&gt;
    user_id="alice",&lt;br&gt;
    prompts="./prompts",&lt;br&gt;
    llm="openai:gpt-4o-mini",&lt;br&gt;
    embeddings="openai:text-embedding-3-small",&lt;br&gt;
    database="memory",          # no database server needed to try it&lt;br&gt;
)&lt;/p&gt;

&lt;p&gt;mem.add("I live in Chennai.")&lt;br&gt;
mem.add("I moved to Bangalore last month.")   # SUPERSEDE: Chennai becomes history&lt;/p&gt;

&lt;p&gt;print(mem.search("Where does the user live?", latest_only=True).as_context())&lt;/p&gt;

&lt;h1&gt;
  
  
  - User lives in Bangalore.
&lt;/h1&gt;

&lt;p&gt;database="memory" keeps everything inside your process, so you can try it with no database server. For production, point the same call at MongoDB or PostgreSQL. Nothing else changes.&lt;/p&gt;

&lt;p&gt;It's a library, not a service. There's no server to deploy and no worker to run. Your agent imports it, and the whole engine runs in your process.&lt;/p&gt;

&lt;p&gt;In an agent loop&lt;br&gt;
memories = mem.search(user_message, latest_only=True)            # recall&lt;br&gt;
reply = your_llm(system_prompt + memories.as_context(), user_message)&lt;br&gt;
mem.add(user_message)                                            # remember&lt;/p&gt;

&lt;p&gt;Recall before responding, and remember after. If you remember first, the user's current message becomes context for answering itself. In a web server, use AsyncMemDream (the same methods, awaited) and run the add in the background so the user isn't waiting on it.&lt;/p&gt;

&lt;p&gt;You write the prompts&lt;/p&gt;

&lt;p&gt;MemDream ships no built-in prompts. The engine knows how to extract facts, choose between adding and superseding, find patterns and compact old memories. What it says to the model is up to you, because a memory layer for a clinic, a bank and a support desk should remember different things.&lt;/p&gt;

&lt;p&gt;python -m memdream prompts ./prompts&lt;/p&gt;

&lt;p&gt;That gives you a working starter set to edit. MemDream appends the output JSON format and validates the model's answer, so your prompt only has to describe your domain. In practice, two or three worked examples (an input message and the fact you want stored) change behaviour more than paragraphs of instructions.&lt;/p&gt;

&lt;p&gt;What happens on add()&lt;/p&gt;

&lt;p&gt;Cheap, deterministic checks run first. The model runs last, on as little as possible:&lt;/p&gt;

&lt;p&gt;your message&lt;br&gt;
  → triage               "hi", "thanks", "ok" never reach the model&lt;br&gt;
  → extraction (LLM)     pull out durable facts, using your prompt&lt;br&gt;
  → policy               confidence and importance floors, sensitivity rules&lt;br&gt;
  → duplicate check      a hash lookup, free if the user repeats themselves&lt;br&gt;
  → find candidates      similar memories for this user only&lt;br&gt;
  → decision (LLM)       ADD / SUPERSEDE / MERGE / NOOP, using your prompt&lt;br&gt;
  → validation           drop invented ids, protect permanent facts&lt;br&gt;
  → state change         done by code, never by the model&lt;br&gt;
  → vector index + audit log&lt;/p&gt;

&lt;p&gt;Measured with gpt-4o-mini and text-embedding-3-small, a message with a new fact costs about $0.0007 (two model calls). Small talk is filtered out before any model call, so "thanks!" costs nothing.&lt;/p&gt;

&lt;p&gt;Dream runs by itself&lt;/p&gt;

&lt;p&gt;With the default auto_dream=True there's no cron job or queue to set up:&lt;/p&gt;

&lt;p&gt;What    When&lt;br&gt;
Synthesis: pattern memories such as "User usually orders vegetarian on weekdays", linked to their evidence  After a user gains 20 new memories, at most every 6 hours&lt;br&gt;
Expiry: retires memories whose validity has ended   Once a day&lt;br&gt;
Compaction: folds piles of low-value memories into one summary  Off by default&lt;br&gt;
Decay: retires what nothing has recalled in a long time Off by default&lt;/p&gt;

&lt;p&gt;Retiring is a status change, not a deletion, so a wrong call can be undone. Set auto_dream=False and call mem.synthesize() and mem.consolidate() on your own schedule instead.&lt;/p&gt;

&lt;p&gt;Design decisions&lt;br&gt;
History is kept. Superseded memories stay, with a pointer to what replaced them, so "where did they live before?" can still be answered with mem.history(memory_id).&lt;br&gt;
The model proposes; the code decides. The model's answer is checked against the memories it was actually shown. It can't touch a memory it never saw, and it can't retire protected ones.&lt;br&gt;
Users are isolated by construction. Every storage call needs the user's scope, and each user's vectors live in their own partition.&lt;br&gt;
Every decision is explainable. Each one writes an audit row with the model's reason, NOOPs included, so mem.audit() answers "why wasn't this remembered?"&lt;br&gt;
Delete means delete. mem.forget() retires a memory and can be undone. mem.delete() erases it, including its text in the audit log. mem.purge(confirm=True) erases everything about one user, for requests like GDPR erasure.&lt;br&gt;
Bring your own stack&lt;br&gt;
LLMs: OpenAI, Azure OpenAI, Anthropic, Gemini, Ollama, Together, Fireworks, or any OpenAI-compatible endpoint&lt;br&gt;
Embeddings: OpenAI, Azure OpenAI, Gemini, Ollama&lt;br&gt;
Database: MongoDB, PostgreSQL, or in-memory&lt;br&gt;
Vector index: FAISS (the default), Qdrant, pgvector, Chroma, Pinecone, Milvus, Azure AI Search&lt;/p&gt;

&lt;p&gt;With Ollama, the whole thing runs on your own machine with no API key.&lt;/p&gt;

&lt;p&gt;Where it stands, and how you can help&lt;/p&gt;

&lt;p&gt;MemDream is at version 0.1.1. CI runs the test suite on Python 3.10 to 3.13 and against real MongoDB, PostgreSQL with pgvector, and Qdrant. It's early, and I'd rather hear what breaks now than later.&lt;/p&gt;

&lt;p&gt;Next on my list:&lt;/p&gt;

&lt;p&gt;Public numbers on the LongMemEval and LoCoMo memory benchmarks&lt;br&gt;
Integration examples for LangChain, LlamaIndex, CrewAI and the OpenAI Agents SDK&lt;br&gt;
More vector stores and model providers&lt;/p&gt;

&lt;p&gt;If you build agents, please try it and open an issue about anything that confused you. Contributions are welcome. A new vector store, provider or example makes a good first contribution, because each one is self-contained.&lt;/p&gt;

&lt;p&gt;GitHub: &lt;a href="https://github.com/Mamlesh18/MemDream" rel="noopener noreferrer"&gt;https://github.com/Mamlesh18/MemDream&lt;/a&gt;&lt;br&gt;
PyPI: &lt;a href="https://pypi.org/project/memdream/" rel="noopener noreferrer"&gt;https://pypi.org/project/memdream/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If MemDream is useful to you, a star on GitHub helps other people find it.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fov8r5s023as59zm0mlf7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fov8r5s023as59zm0mlf7.png" alt=" " width="716" height="784"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>memory</category>
      <category>agents</category>
    </item>
  </channel>
</rss>
