{"record":{"id":"a5f04dda364257e6","repo":"langchain-ai/deepagents","slug":"the-namespace-factory-tried-to-read-the-runtime-b","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"libs/deepagents/deepagents/backends/store.py","lineNumber":166,"sourceCode":"        the runtime (e.g. `lambda rt: (rt.server_info.user.identity, ...)`)\n        raises a clear `RuntimeError` in that case rather than an opaque\n        `AttributeError` on `None`.\n        \"\"\"\n        try:\n            runtime: Runtime[Any] | None = get_runtime()\n        except (RuntimeError, KeyError):\n            runtime = None\n        try:\n            namespace = self._namespace(cast(\"Runtime[Any]\", runtime))\n        except AttributeError as exc:\n            if runtime is None:\n                msg = (\n                    \"The namespace factory tried to read the Runtime, but it is \"\n                    \"unavailable (running outside a LangGraph graph execution). \"\n                    \"Use StoreBackend inside a graph (e.g. via create_deep_agent), \"\n                    \"or pass a namespace factory that does not read the Runtime.\"\n                )\n                raise RuntimeError(msg) from exc\n            raise\n        return _validate_namespace(namespace)\n\n    def _convert_store_item_to_file_data(self, store_item: Item) -> FileData:\n        \"\"\"Convert current and legacy persisted store content to `FileData`.\n\n        Args:\n            store_item: The store `Item` containing file data.\n\n        Returns:\n            `FileData` with string content and encoding. Legacy `list[str]`\n                content is joined without modifying the persisted item. Includes\n                `created_at` and `modified_at` when present.\n\n        Raises:\n            ValueError: If the store item has no content.\n            TypeError: If content is neither a string nor a legacy list of strings.\n        \"\"\"","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/deepagents/deepagents/backends/store.py#L148-L184","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nbackend = StoreBackend(store=store, namespace=lambda rt: (rt.context['user'],))  # rt is None outside graph\n// after\nbackend = StoreBackend(store=store, namespace=lambda _rt: ('filesystem',))","handlingStrategy":"try-catch","validationCode":"def safe_namespace(factory):\n    def make(_rt):\n        try:\n            return factory(_rt)\n        except Exception:\n            return ('filesystem',)\n    return make\nbackend = StoreBackend(store=store, namespace=safe_namespace(lambda rt: (rt.context['user'],)))","typeGuard":null,"tryCatchPattern":"try:\n    items = backend.ls('/')\nexcept RuntimeError as exc:\n    if 'Runtime' in str(exc) and 'namespace factory' in str(exc):\n        backend = StoreBackend(store=store, namespace=('filesystem',))\n        items = backend.ls('/')\n    else:\n        raise","preventionTips":["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"],"tags":["runtime-context","namespace","langgraph"],"backgroundTag":"missing-runtime-context","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}