LangMemLangMem 0.0.30 · LangGraph 1.2 · Python 3.10+
Dashboard
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
19 small wins to finish your pathNext lesson →

Updates and deletes

Updates and deletes are the two ways a LangMem memory manager changes memories it already has: PatchDoc rewrites a memory in place and keeps its id, and RemoveDoc marks one for deletion.

Last updated: 30 Sep, 2026 · LangMem 0.0.30

Facts change. Asha asked for email, then decides she prefers text messages. A collection that only adds would now hold both preferences, and the assistant would not know which is current. Passing existing gives the model a PatchDoc tool, as The extraction request showed, and enable_deletes=True adds a RemoveDoc tool.

Syntax:

python
create_memory_manager(model, enable_updates=True)   # the default: PatchDoc is available
create_memory_manager(model, enable_deletes=True)   # adds RemoveDoc; off by default

The memory to change

The update needs a memory to start from. The first call extracts it, the same as in Collections.

python
first = manager.invoke({"messages": [
    {"role": "user", "content": "Hi, I'm Asha. Order A-1001 arrived broken. Please email me."},
]})
existing = [(memory.id, memory.content) for memory in first]

A message that changes a fact

python
update = manager.invoke({
    "messages": [{"role": "user", "content": "Please text me instead of email."}],
    "existing": existing,
})

Updating a contact preference

ExampleAPI key
from langchain.chat_models import init_chat_model
from langmem import create_memory_manager

model = init_chat_model("groq:openai/gpt-oss-120b", temperature=0)
manager = create_memory_manager(
    model,
    instructions="Extract what helps support this customer. Record everything in a single Memory call.",
)

first = manager.invoke({"messages": [
    {"role": "user", "content": "Hi, I'm Asha. Order A-1001 arrived broken. Please email me."},
]})
existing = [(memory.id, memory.content) for memory in first]
print("before:", first[0].content.content)

update = manager.invoke({
    "messages": [{"role": "user", "content": "Please text me instead of email."}],
    "existing": existing,
})
for memory in update:
    status = "same id" if memory.id in dict(existing) else "new id"
    print(f"after:  {memory.content.content} ({status})")

How the update landed

  • same id. The model called PatchDoc on the existing memory, so the text changed and the id stayed. Code that stored the memory by id replaces it in place.
  • Both mentions of email became text, including a sentence Asha never said: "The support action required is to send an email apology..." is the model's own plan, added in the first extraction and carried into the update.
  • The result is the whole collection after the change. With one memory, that is the one patched memory.

Deleting memories on request

With enable_deletes=True, a memory the model decides to drop comes back as a RemoveDoc with the id to delete. Removing it from wherever you keep memories is up to your code; the store manager in Store managers does it for you.

ExampleAPI key
from langchain.chat_models import init_chat_model
from langmem import create_memory_manager

model = init_chat_model("groq:openai/gpt-oss-120b", temperature=0)
manager = create_memory_manager(
    model,
    instructions="Extract what helps support this customer. Record everything in a single Memory call.",
    enable_deletes=True,
)
first = manager.invoke({"messages": [
    {"role": "user", "content": "Hi, I'm Asha. Order A-1001 arrived broken. Please email me."},
]})
existing = [(memory.id, memory.content) for memory in first]

result = manager.invoke({
    "messages": [{"role": "user", "content": "Please delete everything you saved about me."}],
    "existing": existing,
})
for memory in result:
    print(type(memory.content).__name__, "|", memory.content)

One RemoveDoc came back, naming the id of the only memory, and no Memory was left: the model deleted everything, as asked. Deleting that id from your own list or database is your code's job.

PatchDoc vs RemoveDoc

PatchDocRemoveDoc
Turned on byPassing existing memories (enable_updates is on by default)enable_deletes=True
Returned asThe same id with new contentA RemoveDoc naming the id
Your codeReplaces the memory with that idDeletes the memory with that id

When updates and deletes matter

  • Contact preferences, addresses and plans, which change and must not pile up.
  • Privacy requests, where a customer asks the assistant to forget them.
  • Facts the customer corrects ("it was A-1002, not A-1001").
Watch out. An update overwrites. If the model misreads "text me when it is urgent" as "text me", the email preference is gone. Keep a history of memories you cannot afford to lose, or set enable_updates=False so the manager only adds.
Try it yourself
  • Send "My name is Priya, not Asha" with the existing memory and read what changed.
  • Create the manager with enable_updates=False and send the text-me message again.
  • Keep memories in a dictionary by id and delete the ids that come back as RemoveDoc.
PreviousCollections

Little by little, you're building something great.