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

Updating and deleting memories

Pass existing memories and the model can change them instead of adding duplicates: PatchDoc edits a memory by id, RemoveDoc deletes one when deletes are enabled.

Example
update = manager.invoke({"messages": [{"role": "user", "content": "Actually, text me instead."}], "existing": existing})
for memory in update:
    changed = "same id" if memory.id in dict(existing) else "new id"
    print(changed, "|", memory.content.content)

existing is a list of (id, content) pairs. The contact memory kept its id and changed its text: the model called PatchDoc with that id and a JSON Patch replace on /content. The other two memories come back unchanged, so the result is the whole new state, not only the changes.

Deletes

Example
forgetful = create_memory_manager(MemoryModel(), enable_deletes=True)
result = forgetful.invoke({"messages": [{"role": "user", "content": "Please forget my name."}], "existing": existing})
for memory in result:
    print(type(memory.content).__name__, "|", getattr(memory.content, "content", ""))

Deleting is off by default. With enable_deletes=True, the model gets a RemoveDoc tool, and a deleted memory comes back as a RemoveDoc with its id instead of a Memory. Your code then deletes it from wherever you keep memories. A store manager, lesson 11, does that for you.

Updates can lose information
An update overwrites. A real model that misreads "text me when it is urgent" as "text me" replaces the email preference. Keep a history if memories matter, or use enable_updates=False and add new memories instead.
Try it yourself
  • Send "My name is Priya" with existing and see which memory changes.
  • Pass enable_updates=False and send "Text me instead" again.
  • Delete a memory from a Python dict of memories using the RemoveDoc ids.

You understood something today that you didn't yesterday.