MemorySync
Getting Started

LangChain Tools

Five structured memory tools that let a LangChain agent store, search, list, update and delete memories — with scoping, idempotent writes, and failures that never abort an agent run.

The tool set

ToolWhat it does
add_memorySave one durable fact or preference. Repeats are recognised, not duplicated.
search_memorySemantic search over the user’s memories, with relevance scores.
list_memoriesNewest-first listing, for "what do you remember about me?".
update_memoryChange tags or importance by id. Memory text is immutable.
delete_memoryPermanently delete one memory by id.

Create the tools

from langchain.agents import create_agent
from langchain_memorysync import create_memorysync_tools
tools = create_memorysync_tools(end_user_id="user-123")
agent = create_agent(model, tools=tools)
agent.invoke({"messages": [{"role": "user", "content": "Remember that I'm allergic to peanuts."}]})

The factory also works with LangGraph’s create_react_agent and the legacy AgentExecutor on 0.3.x — the tools are plain structured tools, nothing framework-version specific.

Scope to the right user

Pass end_user_id whenever the key belongs to an organisation. It is what keeps one customer’s memories out of another’s session: every tool call is isolated to that user, and a delete cannot reach another user’s memory even by id.

tools = create_memorysync_tools(
end_user_id="user-123",
read_only=True, # only search_memory and list_memories
)

Write behaviour worth knowing

  • add_memory derives an idempotency key from the content, so an agent that repeats "remember X" gets "already stored" instead of a duplicate.
  • Extraction judges what is durable: transient chit-chat comes back as "nothing stored" with guidance to rephrase, not as a memory.
  • Memory text is immutable by design — the update tool changes tags and importance, and replacing a fact is delete plus add, which keeps history auditable.
  • Over-quota writes degrade silently server-side; the agent sees a normal response rather than a billing error to narrate to the end user.

Where to go next

Was this page helpful?