{"record":{"id":"98cc7d852242a81e","repo":"langchain-ai/deepagents","slug":"failed-to-download-path-response-error","errorCode":null,"errorMessage":"Failed to download {path}: {response.error}","messagePattern":"Failed to download (.+?): (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/deepagents/deepagents/middleware/memory.py","lineNumber":306,"sourceCode":"            config: Runnable config.\n\n        Returns:\n            State update with memory_contents populated.\n        \"\"\"\n        # Skip if already loaded\n        if \"memory_contents\" in state:\n            return None\n\n        backend = self._backend\n        contents: dict[str, str] = {}\n\n        results = backend.download_files(list(self.sources))\n        for path, response in zip(self.sources, results, strict=True):\n            if response.error is not None:\n                if response.error == \"file_not_found\":\n                    continue\n                msg = f\"Failed to download {path}: {response.error}\"\n                raise ValueError(msg)\n            if response.content is not None:\n                contents[path] = response.content.decode(\"utf-8\")\n                logger.debug(\"Loaded memory from: %s\", path)\n\n        return MemoryStateUpdate(memory_contents=contents)\n\n    async def abefore_agent(self, state: MemoryState, runtime: Runtime, config: RunnableConfig) -> MemoryStateUpdate | None:  # ty: ignore[invalid-method-override]  # noqa: ARG002\n        \"\"\"Load memory content before agent execution.\n\n        Loads memory from all configured sources and stores in state.\n        Only loads if not already present in state.\n\n        Args:\n            state: Current agent state.\n            runtime: Runtime context.\n            config: Runnable config.\n\n        Returns:","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/deepagents/deepagents/middleware/memory.py#L288-L324","documentation":"In MemoryMiddleware.before_agent, memory source files are fetched via backend.download_files. If a download response carries an error other than \"file_not_found\" (which is skipped), ValueError is raised with the path and backend error. Not-found sources are tolerated; other backend failures are not.","triggerScenarios":"A source path exists in config but the backend fails to read it for reasons other than absence — e.g. permission denied, backend outage, serialization error, or a corrupted file record in a store-backed backend.","commonSituations":"Configured memory path points to a directory instead of a file, backend permissions changed, or a remote/store backend returns an unexpected error string.","solutions":["Read response.error in the message and fix the underlying backend issue for that path","Verify the path is a readable file, not a directory, in the configured backend","Remove or correct the bad entry in the sources list","Catch ValueError in your agent setup and degrade gracefully"],"exampleFix":"// before\nmw = MemoryMiddleware(backend=backend, sources=[\"notes/\"])\n// after\nmw = MemoryMiddleware(backend=backend, sources=[\"notes/memory.md\"])  # a real, readable file path","handlingStrategy":"try-catch","validationCode":"# pre-check sources via the backend before agent startup\nresults = backend.download_files(list(sources))\nbad = [p for p, r in zip(sources, results) if r.error not in (None, \"file_not_found\")]\nif bad:\n    raise ValueError(f\"Unreadable memory sources: {bad}\")","typeGuard":"def source_readable(path, backend) -> bool:\n    r = backend.download_files([path])[0]\n    return r.error in (None, \"file_not_found\")","tryCatchPattern":"try:\n    agent = create_agent(middleware=[MemoryMiddleware(backend=backend, sources=sources)])\nexcept ValueError as e:\n    if e.args and e.args[0].startswith(\"Failed to download\"):\n        logger.warning(\"Memory load failed, continuing without memory: %s\", e)\n    else:\n        raise","preventionTips":["Verify each source path is a readable file in the target backend at startup","Keep memory paths out of version-controlled configs that may drift per environment","Log and skip bad sources in a wrapper instead of failing the whole agent"],"tags":["python","memory","backend","file-download"],"backgroundTag":"memory-download-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}