You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -63,7 +63,7 @@ Here are a few prebuilt filesystem backends that you can quickly use with your d
63
63
|---|---|
64
64
|[Default](#statebackend-ephemeral)|`agent = create_deep_agent()` <br></br> Ephemeral in state. The default filesystem backend for an agent is stored in `langgraph` state. Note that this filesystem only persists _for a single thread_. |
65
65
|[Local filesystem persistence](#filesystembackend-local-disk)|`agent = create_deep_agent(backend=FilesystemBackend(root_dir="/Users/nh/Desktop/"))` <br></br>This gives the deep agent access to your local machine's filesystem. You can specify the root directory that the agent has access to. Note that any provided `root_dir` must be an absolute path. |
66
-
|[Durable store (LangGraph store)](#storebackend-langgraph-store)|`agent = create_deep_agent(backend=lambda rt: StoreBackend(rt))` <br></br>This gives the agent access to long-term storage that is _persisted across threads_. This is great for storing longer term memories or instructions that are applicable to the agent over multiple executions. |
66
+
|[Durable store (LangGraph store)](#storebackend-langgraph-store)|`agent = create_deep_agent(backend=StoreBackend())` <br></br>This gives the agent access to long-term storage that is _persisted across threads_. This is great for storing longer term memories or instructions that are applicable to the agent over multiple executions. |
67
67
|[Sandbox](/oss/deepagents/sandboxes)|`agent = create_deep_agent(backend=sandbox)` <br></br>Execute code in isolated environments. Sandboxes provide filesystem tools plus the `execute` tool for running shell commands. Choose from Modal, Daytona, Deno, or local VFS. |
68
68
|[Local shell](#localshellbackend-local-shell)|`agent = create_deep_agent(backend=LocalShellBackend(root_dir=".", env={"PATH": "/usr/bin:/bin"}))` <br></br>Filesystem and shell execution directly on the host. No isolation—use only in controlled development environments. See [security considerations](#localshellbackend-local-shell) below. |
69
69
|[Composite](#compositebackend-router)| Ephemeral by default, `/memories/` persisted. The Composite backend is maximally flexible. You can specify different routes in the filesystem to point towards different backends. See Composite routing below for a ready-to-paste example. |
@@ -212,6 +212,8 @@ Use with extreme caution and only in appropriate environments.
212
212
213
213
A namespace factory controls where `StoreBackend` reads and writes data. It receives a `BackendContext` and returns a tuple of strings used as the store namespace. Use namespace factories to isolate data between users, tenants, or assistants.
214
214
215
+
Pass the namespace factory to the `namespace` parameter when constructing a `StoreBackend`:
# Per-assistant: all users of the same assistant share storage
239
-
backend =lambdart: StoreBackend(
240
-
rt,
240
+
backend = StoreBackend(
241
241
namespace=lambdactx: (
242
242
get_config()["metadata"]["assistant_id"],
243
243
),
244
244
)
245
245
246
246
# Per-thread: storage scoped to a single conversation
247
-
backend =lambdart: StoreBackend(
248
-
rt,
247
+
backend = StoreBackend(
249
248
namespace=lambdactx: (
250
249
get_config()["configurable"]["thread_id"],
251
250
),
@@ -259,20 +258,20 @@ import { getConfig } from "@langchain/langgraph";
259
258
import { StoreBackend } from"deepagents";
260
259
261
260
// Per-user: each user gets their own isolated storage
262
-
const backend =(rt) =>newStoreBackend(rt, {
261
+
const backend =newStoreBackend({
263
262
namespace: (ctx) => [ctx.runtime.context.userId],
264
263
});
265
264
266
265
// Per-assistant: all users of the same assistant share storage
267
-
const backend =(rt) =>newStoreBackend(rt, {
266
+
const backend =newStoreBackend({
268
267
namespace: (ctx) => {
269
268
const config =getConfig();
270
269
return [config.metadata.assistantId];
271
270
},
272
271
});
273
272
274
273
// Per-thread: storage scoped to a single conversation
275
-
const backend =(rt) =>newStoreBackend(rt, {
274
+
const backend =newStoreBackend({
276
275
namespace: (ctx) => {
277
276
const config =getConfig();
278
277
return [config.configurable.threadId];
@@ -322,19 +321,15 @@ Namespace components must contain only alphanumeric characters, hyphens, undersc
322
321
## Specify a backend
323
322
324
323
:::python
325
-
- Pass a backend to `create_deep_agent(backend=...)`. The filesystem middleware uses it for all tooling.
326
-
- You can pass either:
327
-
- An instance implementing `BackendProtocol` (for example, `FilesystemBackend(root_dir=".")`), or
328
-
- A factory `BackendFactory = Callable[[ToolRuntime], BackendProtocol]` (for backends that need runtime like `StateBackend` or `StoreBackend`).
329
-
- If omitted, the default is `lambda rt: StateBackend(rt)`.
324
+
- Pass a backend instance to `create_deep_agent(backend=...)`. The filesystem middleware uses it for all tooling.
325
+
- The backend must implement `BackendProtocol` (for example, `StateBackend()`, `FilesystemBackend(root_dir=".")`, `StoreBackend()`).
326
+
- If omitted, the default is `StateBackend()`.
330
327
:::
331
328
332
329
:::js
333
-
- Pass a backend to `createDeepAgent({ backend: ... })`. The filesystem middleware uses it for all tooling.
334
-
- You can pass either:
335
-
- An instance implementing `AnyBackendProtocol` (`BackendProtocolV1` or `BackendProtocolV2`) — for example, `new FilesystemBackend({ rootDir: "." })`, or
336
-
- A `BackendFactory` function `(stateAndStore: StateAndStore) => AnyBackendProtocol` — for backends that need runtime state or a store, like `StateBackend` or `StoreBackend`.
337
-
- If omitted, the default is `(config) => new StateBackend(config)`.
330
+
- Pass a backend instance to `createDeepAgent({ backend: ... })`. The filesystem middleware uses it for all tooling.
331
+
- The backend must implement `AnyBackendProtocol` (`BackendProtocolV1` or `BackendProtocolV2`) — for example, `new StateBackend()`, `new FilesystemBackend({ rootDir: "." })`, `new StoreBackend()`.
332
+
- If omitted, the default is `new StateBackend()`.
338
333
339
334
<Note>
340
335
Before version 1.9.0, only `BackendProtocol` was supported which is now `BackendProtocolV1`. V1 backends are automatically adapted to V2 at runtime via `adaptBackendProtocol()`. No code changes are required to keep using existing V1 backends. To update to v2, see [update existing backends to v2](#update-existing-backends-to-v2).
@@ -351,29 +346,29 @@ Route parts of the namespace to different backends. Commonly used to persist `/m
351
346
from deepagents import create_deep_agent
352
347
from deepagents.backends import CompositeBackend, StateBackend, FilesystemBackend
- Longer prefixes win (for example, route `"/memories/projects/"` can override `"/memories/"`).
387
-
- For StoreBackend routing, ensure the agent runtime provides a store (`runtime.store`).
382
+
- For StoreBackend routing, ensure a store is provided via `create_deep_agent(store=...)` or provisioned by the platform.
388
383
389
384
## Use a virtual filesystem
390
385
@@ -716,7 +711,106 @@ type FileData =
716
711
};
717
712
```
718
713
719
-
Backends may encounter either format when reading from state or store. The framework handles both transparently. New writes default to the v2 format. During rolling deployments where older readers need the legacy format, pass `fileFormat: "v1"` to the backend constructor (e.g., `new StoreBackend(rt, { fileFormat: "v1" })`).
714
+
Backends may encounter either format when reading from state or store. The framework handles both transparently. New writes default to the v2 format. During rolling deployments where older readers need the legacy format, pass `fileFormat: "v1"` to the backend constructor (e.g., `new StoreBackend({ fileFormat: "v1" })`).
715
+
:::
716
+
717
+
## Migrate from backend factories
718
+
719
+
<Warning>
720
+
The backend factory pattern is **deprecated**. Pass pre-constructed backend instances directly instead of factory functions.
721
+
</Warning>
722
+
723
+
Previously, backends like `StateBackend` and `StoreBackend` required a factory function that received a runtime object, because they needed runtime context (state, store) to operate. Backends now resolve this context internally via LangGraph's `get_config()`, `get_store()`, and `get_runtime()` helpers, so you can pass instances directly.
0 commit comments