This page covers long-term memory: memory that persists across conversations. For short-term memory (conversation history and scratch files within a single session), see the context engineering guide. Short-term memory is managed automatically as part of the agent’s state.
How memory works
- Point the agent at memory files. Pass file paths to
memory=when creating the agent. A backend controls where those files are stored and who can access them. - Agent loads memory on startup. At the start of each conversation, the agent reads its memory files into the system prompt.
- Agent updates memory during the conversation. As the agent learns new information, it uses its built-in
edit_filetool to update memory files. Changes are persisted and available in the next conversation.
Agent-scoped memory
Give the agent a shared memory file that all users read from and write to. The agent improves over time as it accumulates knowledge across every conversation. It can also learn and update skills when it has write access. See skills as procedural memory. The key is the backend namespace: setting it to(assistant_id,) means every conversation for this agent reads and writes the same memory file.
User-scoped memory
Give each user their own memory file. The agent remembers preferences, context, and history per user while core agent instructions stay fixed. Users can also have per-user skills if stored in a user-scoped backend. The namespace uses(user_id,) so each user gets an isolated copy of the memory file. User A’s preferences never leak into User B’s conversations.
Advanced usage
The sections above cover the basics: configure memory paths, choose a scope, and let the agent handle the rest. This section covers more advanced patterns.| Dimension | Question it answers | Options |
|---|---|---|
| Duration | How long does it last? | Short-term (single conversation) or long-term (across conversations) |
| Information type | What kind of information is it? | Episodic (past experiences), procedural (instructions and skills), or semantic (facts) |
| Scope | Who can see and modify it? | User, agent, or organization |
| Update strategy | When are memories written? | During conversation (default) or between conversations |
| Retrieval | How are memories read? | Loaded into prompt (default) or on demand (e.g., skills) |
| Agent permissions | Can the agent write to memory? | Read-write (default) or read-only (for shared policies) |
Episodic memory
Episodic memory stores records of past experiences: what happened, in what order, and what the outcome was. Unlike semantic memory (facts and preferences stored in files likeAGENTS.md), episodic memory preserves the full conversational context so the agent can recall how a problem was solved, not just what was learned from it.
Deep Agents get episodic memory for free through checkpointers: every conversation is persisted as a checkpointed thread. To make past conversations searchable, wrap thread search in a tool. The user_id is pulled from the runtime context rather than passed as a parameter:
Skills as procedural memory
Skills are a form of procedural memory: reusable instructions that tell the agent how to perform a task. Unlike semantic memory (facts) or episodic memory (experiences), procedural memory encodes step-by-step capabilities the agent can apply on demand. Skills can be either:- Read-only (developer-defined): The developer writes skills and the agent uses them but cannot modify them. This is the most common pattern.
- Read-write (agent-learned): The agent creates and updates skills based on experience. When the agent has write access to memory, it can also write to its skills directory. Use policy hooks to control which paths are writable.
skills= parameter. Skills are loaded on demand rather than injected into every prompt, keeping context lean until a capability is needed:
Organization-level memory
Organization-level memory follows the same pattern as user-scoped memory, but with a shared namespace instead of a per-user one. Use it for policies or knowledge that should apply across all users and agents. Organization memory is typically read-only to prevent prompt injection via shared state. See read-only vs writable memory for details.Background consolidation
By default, the agent writes memories during the conversation (hot path). An alternative is to process memories between conversations as a background task, sometimes called sleep time compute. A separate deep agent reviews recent conversations, extracts key facts, and merges them with existing memories.| Approach | Pros | Cons |
|---|---|---|
| Hot path (during conversation) | Memories available immediately, transparent to user | Adds latency, agent must multitask |
| Background (between conversations) | No user-facing latency, can synthesize across multiple conversations | Memories not available until next conversation, requires a second agent |
| Trigger | When it runs | Best for |
|---|---|---|
| Cron | Fixed schedule (e.g., every 6 hours) | Batching across many conversations, synthesizing trends |
| Scheduled run | After a delay on the same thread | Simple setups where the client controls when consolidation fires |
Consolidation agent
The consolidation agent reads recent conversation history and merges key facts into the memory store. Register it alongside your main agent inlanggraph.json:
src/consolidation-agent.ts
langgraph.json
Cron
A cron job runs the consolidation agent on a fixed schedule. The agent searches all recent conversations and synthesizes them into memory. Schedule the consolidation agent with a cron job:All cron schedules are interpreted in UTC. See cron jobs for details on managing and deleting cron jobs.
Scheduled run
Schedule a run after each conversation using theafter_seconds parameter. This is activity-driven: consolidation only fires when a user has been active. Pass the same thread_id so the consolidation agent has access to the conversation context.
The delay gives the conversation time to finish (the user may send follow-up messages) so the consolidation agent sees the full exchange.
If the user sends another message during the delay, the new run’s multitask_strategy controls what happens to the pending consolidation run. Use rollback on the new run to delete the stale consolidation run, then schedule a fresh one after the next response:
multitask_strategy controls the behavior of concurrent runs on the same thread.
For more on deploying agents with background processes, see going to production.
Read-only vs writable memory
By default, the agent can both read and write memory files. For shared state like organization policies or compliance rules, you may want to make memory read-only so the agent can reference it but not modify it. This prevents prompt injection via shared memory and ensures that only your application code controls what’s in the file.| Permission | Use case | How it works |
|---|---|---|
| Read-write (default) | User preferences, agent self-improvement, learned skills | Agent updates files via edit_file tool |
| Read-only | Organization policies, compliance rules, shared knowledge bases, developer-defined skills | Populate via application code or the Store API. Use policy hooks to block agent writes. |
- Default to user scope
(user_id)unless you have a specific reason to share - Use read-only memory for shared policies (populate via application code, not the agent)
- Add human-in-the-loop validation before the agent writes to shared memory. Use an interrupt to require human approval for writes to sensitive paths.
Concurrent writes
Multiple threads can write to memory in parallel, but concurrent writes to the same file can cause last-write-wins conflicts. For user-scoped memory this is rare since users typically have one active conversation at a time. For agent-scoped or organization-scoped memory, consider using background consolidation to serialize writes, or structure memory as separate files per topic to reduce contention. In practice, if a write fails due to a conflict, the LLM is usually smart enough to retry or recover gracefully, so a single lost write is not catastrophic.Multiple agents in the same deployment
To give each agent its own memory in a shared deployment, addassistant_id to the namespace:
(assistant_id,) alone if you only need per-agent isolation without per-user scoping.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

