Skip to main content
skill Claude Code CX Codex Cursor GitHub Copilot

deep-agents-memory — Claude Code skill: memory backends

A skill that maps where a Deep Agent keeps its files: thread state, a persistent store, or the real disk. Useful once the agent starts dropping context.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add langchain-ai/langchain-skills --skill deep-agents-memory -a claude-code
Open on GitHub

What deep-agents-memory does

The skill covers the backends behind file operations in deepagents. StateBackend is the default: files sit in thread state and vanish when the thread ends. StoreBackend keeps them across threads and sessions.

FilesystemMiddleware exposes the model to a fixed tool set: ls, read_file, write_file, edit_file, glob, grep. Their names are not configurable. FilesystemBackend points at the real disk through root_dir and caps reach with virtual_mode. Keep it out of web servers, the skill says, and use StateBackend or a sandbox there instead.

CompositeBackend routes by path prefix, so /draft.txt can stay ephemeral while /memories/ lands in the store and shows up in the next thread. That routing is where setups break: StoreBackend needs a real store instance passed to create_deep_agent, InMemoryStore() in the sample. Snippets come in Python and TypeScript, with a separate recipe for reaching store from a custom @tool.

What it helps with

  • carry user preferences across thread restarts
  • route one path prefix to persistent storage
  • let the agent edit disk files with write confirmation
  • read saved memory from a custom tool
  • stop losing scratch files when a thread ends

Example prompts for the agent

  • Set up a `CompositeBackend` so `/memories/` survives a thread restart
  • Switch to `FilesystemBackend` with `virtual_mode` and ask before every `write_file`
  • Why can't thread 2 read what thread 1 saved to `/memories/style.txt`?

How to install deep-agents-memory

1Skills CLI (Vercel)

npx skills add langchain-ai/langchain-skills --skill deep-agents-memory -a claude-code

2Manually: put the files in place

~/.claude/skills/deep-agents-memory/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/deep-agents-memory/

From the same set14

The whole set →
langgraph-persistence langchain-ai A Claude Code skill for LangGraph persistence: wiring a checkpointer, keeping conversations apart by thread_id, and replaying older graph state. Claude Code CX Codex Cursor +1 18,000installs langgraph-fundamentals langchain-ai Skill for writing LangGraph code across platforms. Covers StateGraph, state schemas, nodes, edges, Command, Send, invoke, streaming, and error handling. Claude Code CX Codex Cursor +1 18,000installs langchain-rag langchain-ai Equips coding agents with reference RAG implementations in Python and TypeScript using LangChain loaders, splitters, and vector stores. Claude Code CX Codex Cursor +1 17,500installs langchain-fundamentals langchain-ai Guides LangChain agent work with create_agent(), tools, and middleware. Use it when you need saved conversation state, approval flows, or error handling. Claude Code CX Codex Cursor +1 17,400installs langgraph-human-in-the-loop langchain-ai Skill for building LangGraph workflows that pause and wait for human input. Use it to show agent output, request approval, or validate user responses before continuing. Claude Code CX Codex Cursor +1 17,200installs langchain-middleware langchain-ai Adds middleware hooks for LangChain agents: pauses execution before dangerous tool calls, lets a human approve, edit or reject the action, intercepts calls for logging and retry logic. Claude Code CX Codex Cursor +1 16,200installs deep-agents-orchestration langchain-ai Guides setup of orchestration in Deep Agents: subagent delegation, todo planning, and human approval interrupts. Claude Code CX Codex Cursor +1 16,100installs langchain-dependencies langchain-ai Provides verified package versions and dependency rules for LangChain, LangGraph, and LangSmith. Helps set up clean Python or TypeScript projects without version conflicts. Claude Code CX Codex Cursor +1 16,000installs

Similar

github-project-management ruvnet Turns issue triage and board upkeep into gh and ruv-swarm calls: labels, subtasks, duplicate lookup. Useful when the tracker holds more tickets than order. Claude Code CX Codex Cursor +1 1,400installs ads-plan AgriciDaniel Walks an agent through a paid-media plan: objectives, channel choice, campaign architecture, budget, measurement and rollback terms. Meant for the stage before money hits the ad account. Claude Code CX Codex Cursor +1 4,000installs unfreeze garrytan Clears the freeze boundary set by /freeze, allowing edits to all directories again. Use it when you need to unlock restricted folders or return to unrestricted editing. Claude Code CX Codex Cursor +1 327installs cli-developer https://github.com/Jeffallan Skill for command-line development: guides you through building CLI tools with argument parsing, interactive prompts, progress bars and shell completions. Works with commander, click, typer and cobra. Claude Code CX Codex Cursor +1 4,800installs opensrc vercel-labs Gives an agent dependency source code when types and documentation are not enough to inspect internal logic or debug library behaviour. Claude Code CX Codex Cursor +1 2,600installs golang-gopls samber Semantic navigation and refactoring for Go code through gopls, the official language server. Use it when grep finds text but you need types, call graphs, and build structure. Claude Code CX Codex Cursor +1 10,900installs setup-matt-pocock-skills Matt Pocock This skill configures a repository for Matt Pocock's engineering skills by setting its issue tracker, triage labels, and domain docs layout. Run it before using the other skills. Claude Code 1,052,851installs to-tickets Matt Pocock Turns a plan, spec, or conversation into small end-to-end tickets with explicit blockers. Use it to agree on the work breakdown before tickets go to a tracker. Claude Code 711,230installs

Questions about deep-agents-memory

How do I install deep-agents-memory in Claude Code?

Run npx skills add langchain-ai/langchain-skills --skill deep-agents-memory -a claude-code. The skill file lands at ~/.claude/skills/deep-agents-memory/SKILL.md.

What does deep-agents-memory do?

It explains the file and memory backends in Deep Agents and which one fits which job. Python and TypeScript examples cover StateBackend, StoreBackend, CompositeBackend and FilesystemBackend.

Does StoreBackend work on its own?

No, it needs a store instance handed to create_deep_agent, such as InMemoryStore() from langgraph.store.memory. Switch the backend without it and persistence never kicks in.

Source text

SKILL.md · MIT
---
name: deep-agents-memory
description: "INVOKE THIS SKILL when your Deep Agent needs memory, persistence, or filesystem access. Covers StateBackend (ephemeral), StoreBackend (persistent), FilesystemMiddleware, and CompositeBackend for routing."
---

<overview>
Deep Agents use pluggable backends for file operations and memory:

**Short-term (StateBackend)**: Persists within a single thread, lost when thread ends
**Long-term (StoreBackend)**: Persists across threads and sessions
**Hybrid (CompositeBackend)**: Route different paths to different backends

FilesystemMiddleware provides tools: `ls`, `read_file`, `write_file`, `edit_file`, `glob`, `grep`
</overview>

<backend-selection>

| Use Case | Backend | Why |
|----------|---------|-----|
| Temporary working files | StateBackend | Default, no setup |
| Local development CLI | FilesystemBackend | Direct disk access |
| Cross-session memory | StoreBackend | Persists across threads |
| Hybrid storage | CompositeBackend | Mix ephemeral + persistent |

</backend-selection>

<ex-default-state-backend>
<python>
Default StateBackend stores files ephemerally within a thread.

```python
from deepagents import create_deep_agent

agent = create_deep_agent()  # Default: StateBackend
result = agent.invoke({
    "messages": [{"role": "user", "content": "Write notes to /draft.txt"}]
}, config={"configurable": {"thread_id": "thread-1"}})
# /draft.txt is lost when thread ends
```
</python>
<typescript>
Default StateBackend stores files ephemerally within a thread.

```typescript
import { createDeepAgent } from "deepagents";

const agent = await createDeepAgent();  // Default: StateBackend
const result = await agent.invoke({
  messages: [{ role: "user", content: "Write notes to /draft.txt" }]
}, { configurable: { thread_id: "thread-1" } });
// /draft.txt is lost when thread ends
```
</typescript>
</ex-default-state-backend>

<ex-composite-backend-for-hybrid>
<python>
Configure CompositeBackend to route paths to different storage backends.

```python
from deepagents import create_deep_agent
from deepagents.backends import CompositeBackend, StateBackend, StoreBackend
from langgraph.store.memory import InMemoryStore

store = InMemoryStore()

composite_backend = lambda rt: CompositeBackend(
    default=StateBackend(rt),
    routes={"/memories/": StoreBackend(rt)}
)

agent = create_deep_agent(backend=composite_backend, store=store)

# /draft.txt -> ephemeral (StateBackend)
# /memories/user-prefs.txt -> persistent (StoreBackend)
```
</python>
<typescript>
Configure CompositeBackend to route paths to different storage backends.

```typescript
import { createDeepAgent, CompositeBackend, StateBackend, StoreBackend } from "deepagents";
import { InMemoryStore } from "@langchain/langgraph";

const store = new InMemoryStore();

const agent = await createDeepAgent({
  backend: (config) => new CompositeBackend(
    new StateBackend(config),
    { "/memories/": new StoreBackend(config) }
  ),
  store
});

// /draft.txt -> ephemeral (StateBackend)
// /memories/user-prefs.txt -> persistent (StoreBackend)
```
</typescript>
</ex-composite-backend-for-hybrid>

<ex-cross-session-memory>
<python>
Files in /memories/ persist across threads via StoreBackend routing.

```python
# Using CompositeBackend from previous example
config1 = {"configurable": {"thread_id": "thread-1"}}
agent.invoke({"messages": [{"role": "user", "content": "Save to /memories/style.txt"}]}, config=config1)

config2 = {"configurable": {"thread_id": "thread-2"}}
agent.invoke({"messages": [{"role": "user", "content": "Read /memories/style.txt"}]}, config=config2)
# Thread 2 can read file saved by Thread 1
```
</python>
<typescript>
Files in /memories/ persist across threads via StoreBackend routing.

```typescript
// Using CompositeBackend from previous example
const config1 = { configurable: { thread_id: "thread-1" } };
await agent.invoke({ messages: [{ role: "user", content: "Save to /memories/style.txt" }] }, config1);

const config2 = { configurable: { thread_id: "thread-2" } };
await agent.invoke({ messages: [{ role: "user", content: "Read /memories/style.txt" }] }, config2);
// Thread 2 can read file saved by Thread 1
```
</typescript>
</ex-cross-session-memory>

<ex-filesystem-backend-local-dev>
<python>
Use FilesystemBackend for local development with real disk access and human-in-the-loop.

```python
from deepagents import create_deep_agent
from deepagents.backends import FilesystemBackend
from langgraph.checkpoint.memory import MemorySaver

agent = create_deep_agent(
    backend=FilesystemBackend(root_dir=".", virtual_mode=True),  # Restrict access
    interrupt_on={"write_file": True, "edit_file": True},
    checkpointer=MemorySaver()
)

# Agent can read/write actual files on disk
```
</python>
<typescript>
Use FilesystemBackend for local development with real disk access and human-in-the-loop.

```typescript
import { createDeepAgent, FilesystemBackend } from "deepagents";
import { MemorySaver } from "@langchain/langgraph";

const agent = await createDeepAgent({
  backend: new FilesystemBackend({ rootDir: ".", virtualMode: true }),
  interruptOn: { write_file: true, edit_file: true },
  checkpointer: new MemorySaver()
});
```
</typescript>

**Security: Never use FilesystemBackend in web servers - use StateBackend or sandbox instead.**
</ex-filesystem-backend-local-dev>

<ex-store-in-custom-tools>
<python>
Access the store directly in custom tools for long-term memory operations.

```python
from langchain.tools import tool, ToolRuntime
from langchain.agents import create_agent
from langgraph.store.memory import InMemoryStore

@tool
def get_user_preference(key: str, runtime: ToolRuntime) -> str:
    """Get a user preference from long-term storage."""
    store = runtime.store
    result = store.get(("user_prefs",), key)
    return str(result.value) if result else "Not found"

@tool
def save_user_preference(key: str, value: str, runtime: ToolRuntime) -> str:
    """Save a user preference to long-term storage."""
    store = runtime.store
    store.put(("user_prefs",), key, {"value": value})
    return f"Saved {key}={value}"

store = InMemoryStore()

agent = create_agent(
    model="gpt-4.1",
    tools=[get_user_preference, save_user_preference],
    store=store
)
```
</python>
</ex-store-in-custom-tools>

<boundaries>
### What Agents CAN Configure

- Backend type and configuration
- Routing rules for CompositeBackend
- Root directory for FilesystemBackend
- Human-in-the-loop for file operations

### What Agents CANNOT Configure

- Tool names (ls, read_file, write_file, edit_file, glob, grep)
- Access files outside virtual_mode restrictions
- Cross-thread file access without proper backend setup
</boundaries>

<fix-storebackend-requires-store>
<python>
StoreBackend requires a store instance.

```python
# WRONG
agent = create_deep_agent(backend=lambda rt: StoreBackend(rt))

# CORRECT
agent = create_deep_agent(backend=lambda rt: StoreBackend(rt), store=InMemoryStore())
```
</python>
<typescript>
StoreBackend requires a store instance.

```typescript
// WRONG
const agent = await createDeepAgent({ backend: (c) => new StoreBackend(c) });

// CORRECT
const agent = await createDeepAgent({ backend: (c) => new StoreBackend(c), store: new InMemoryStore() });
```
</typescript>
</fix-storebackend-requires-store>

<fix-statebackend-files-dont-persist>
<python>
StateBackend files are thread-scoped - use same thread_id or StoreBackend for cross-thread access.

```python
# WRONG: thread-2 can't read file from thread-1
agent.invoke({"messages": [...]}, config={"configurable": {"thread_id": "thread-1"}})  # Write
agent.invoke({"messages": [...]}, config={"configurable": {"thread_id": "thread-2"}})  # File not found!
```
</python>
<typescript>
StateBackend files are thread-scoped - use same thread_id or StoreBackend for cross-thread access.

```typescript
// WRONG: thread-2 can't read file from thread-1
await agent.invoke({ messages: [...] }, { configurable: { thread_id: "thread-1" } });  // Write
await agent.invoke({ messages: [...] }, { configurable: { thread_id: "thread-2" } });  // File not found!
```
</typescript>
</fix-statebackend-files-dont-persist>

<fix-path-prefix-for-persistence>
<python>
Path must match CompositeBackend route prefix for persistence.

```python
# With routes={"/memories/": StoreBackend(rt)}:
agent.invoke(...)  # /prefs.txt -> ephemeral (no match)
agent.invoke(...)  # /memories/prefs.txt -> persistent (matches route)
```
</python>
<typescript>
Path must match CompositeBackend route prefix for persistence.

```typescript
// With routes: { "/memories/": StoreBackend }:
await agent.invoke(...);  // /prefs.txt -> ephemeral (no match)
await agent.invoke(...);  // /memories/prefs.txt -> persistent (matches route)
```
</typescript>
</fix-path-prefix-for-persistence>

<fix-production-store>
<python>
Use PostgresStore for production (InMemoryStore lost on restart).

```python
# WRONG                              # CORRECT
store = InMemoryStore()              store = PostgresStore(connection_string="postgresql://...")
```
</python>
<typescript>
Use PostgresStore for production (InMemoryStore lost on restart).

```typescript
// WRONG                                    // CORRECT
const store = new InMemoryStore();          const store = new PostgresStore({ connectionString: "..." });
```
</typescript>
</fix-production-store>

<fix-filesystem-backend-needs-virtual-mode>
<python>
Enable virtual_mode=True to restrict path access (prevents ../ and ~/ escapes).

```python
backend = FilesystemBackend(root_dir="/project", virtual_mode=True)  # Secure
```
</python>
</fix-filesystem-backend-needs-virtual-mode>

<fix-longest-prefix-match>
<python>
CompositeBackend matches longest prefix first.

```python
routes = {"/mem/": StoreBackend(rt), "/mem/temp/": StateBackend(rt)}
# /mem/file.txt -> StoreBackend, /mem/temp/file.txt -> StateBackend (longer match)
```
</python>
</fix-longest-prefix-match>

© langchain-ai · MIT · langchain-ai/langchain-skills

See also

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor