langchain-ai/deepagents · error · RuntimeError
The namespace factory tried to read the Runtime, but it is u
Error message
The namespace factory tried to read the Runtime, but it is unavailable (running outside a LangGraph graph execution). Use StoreBackend inside a graph (e.g. via create_deep_agent), or pass a namespace factory that does not read the Runtime.
What it means
This is the namespace-side counterpart of the missing-runtime error: a namespace factory callable attempted to access the LangGraph `Runtime`, but the backend is running outside a graph execution so no Runtime can be resolved. The original lookup exception is chained (`from exc`). The library tells you to either run inside a graph or supply a factory that ignores the Runtime.
Source
Thrown at libs/deepagents/deepagents/backends/store.py:166
the runtime (e.g. `lambda rt: (rt.server_info.user.identity, ...)`)
raises a clear `RuntimeError` in that case rather than an opaque
`AttributeError` on `None`.
"""
try:
runtime: Runtime[Any] | None = get_runtime()
except (RuntimeError, KeyError):
runtime = None
try:
namespace = self._namespace(cast("Runtime[Any]", runtime))
except AttributeError as exc:
if runtime is None:
msg = (
"The namespace factory tried to read the Runtime, but it is "
"unavailable (running outside a LangGraph graph execution). "
"Use StoreBackend inside a graph (e.g. via create_deep_agent), "
"or pass a namespace factory that does not read the Runtime."
)
raise RuntimeError(msg) from exc
raise
return _validate_namespace(namespace)
def _convert_store_item_to_file_data(self, store_item: Item) -> FileData:
"""Convert current and legacy persisted store content to `FileData`.
Args:
store_item: The store `Item` containing file data.
Returns:
`FileData` with string content and encoding. Legacy `list[str]`
content is joined without modifying the persisted item. Includes
`created_at` and `modified_at` when present.
Raises:
ValueError: If the store item has no content.
TypeError: If content is neither a string nor a legacy list of strings.
"""View on GitHub (pinned to a1af029e6e)
Solutions
- Run the backend operations inside a LangGraph graph execution (e.g. via `create_deep_agent`)
- Pass a namespace that does not read the Runtime: `StoreBackend(store=my_store, namespace=('filesystem',))` or `namespace=lambda _rt: ('filesystem',)`
- Snapshot needed Runtime values (e.g. user id) inside the graph, then construct the backend with a constant namespace
- Fix typos in factory signatures so the parameter is a Runtime-or-None, not an eager attribute access
Example fix
// before
backend = StoreBackend(store=store, namespace=lambda rt: (rt.context['user'],)) # rt is None outside graph
// after
backend = StoreBackend(store=store, namespace=lambda _rt: ('filesystem',)) Defensive patterns
Strategy: try-catch
Validate before calling
def safe_namespace(factory):
def make(_rt):
try:
return factory(_rt)
except Exception:
return ('filesystem',)
return make
backend = StoreBackend(store=store, namespace=safe_namespace(lambda rt: (rt.context['user'],))) Try / catch
try:
items = backend.ls('/')
except RuntimeError as exc:
if 'Runtime' in str(exc) and 'namespace factory' in str(exc):
backend = StoreBackend(store=store, namespace=('filesystem',))
items = backend.ls('/')
else:
raise Prevention
- Write namespace factories that tolerate a None Runtime
- Use a constant namespace tuple when Runtime values are not required
- Snapshot Runtime context values inside the graph and close over the snapshot
- Only use Runtime-dependent namespaces inside create_deep_agent graph execution
When it happens
Trigger: Using `StoreBackend` with the default/runtime-reading namespace factory (or a custom `lambda rt: (rt.context[...],)`) outside a LangGraph graph; calling `ls`/`read`/`write`/`edit` on the backend in a plain script or after the graph run has ended.
Common situations: Standalone tests of StoreBackend; background threads or async tasks that outlive the graph run; reusing a backend created inside one graph in a context without a Runtime.
Related errors
- StoreBackend must be used inside a LangGraph graph execution
- Server process exited with code {self._process.returncode}
- Server graph '{graph_name}' failed readiness check (status:
- thread_id is required in config.configurable
- Pending graph work remained on thread {thread_id} after clea
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/a5f04dda364257e6.
Report an issue: GitHub.