{"record":{"id":"11e202988f84f0f1","repo":"langchain-ai/deepagents","slug":"conversation-history-was-offloaded-to-file-path","errorCode":null,"errorMessage":"Conversation history was offloaded to {file_path}, but {failed_media} media block(s) could not be offloaded and appear as failed placeholders in the saved history; the original media is not recoverable.","messagePattern":"Conversation history was offloaded to (.+?), but (.+?) media block\\(s\\) could not be offloaded and appear as failed placeholders in the saved history; the original media is not recoverable\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"libs/deepagents/deepagents/middleware/summarization.py","lineNumber":1444,"sourceCode":"        session_id = self._get_session_id(request.state)\n\n        # Offload to backend first so history is preserved before summarization.\n        # If offload fails, summarization still proceeds (with file_path=None).\n        file_path = self._offload_to_backend(backend, offloaded_media_messages, session_id)\n        if file_path is None:\n            msg = \"Offloading conversation history to backend failed during summarization. Older messages will not be recoverable.\"\n            logger.error(msg)\n            warnings.warn(msg, stacklevel=2)\n        elif failed_media:\n            # History was saved, but some media became failed-offload placeholders.\n            # Tie the warning to the saved file so the recovery pointer is honest.\n            msg = (\n                f\"Conversation history was offloaded to {file_path}, but {failed_media} media \"\n                \"block(s) could not be offloaded and appear as failed placeholders in the saved \"\n                \"history; the original media is not recoverable.\"\n            )\n            logger.warning(msg)\n            warnings.warn(msg, stacklevel=2)\n\n        # Generate summary\n        summary = self._create_summary(offloaded_media_messages)\n\n        # Build summary message with file path reference\n        new_messages = self._build_new_messages_with_path(summary, file_path)\n\n        previous_event = request.state.get(\"_summarization_event\")\n        state_cutoff_index = self._compute_state_cutoff(previous_event, cutoff_index)\n\n        # Create new summarization event\n        new_event: SummarizationEvent = {\n            \"cutoff_index\": state_cutoff_index,\n            \"summary_message\": new_messages[0],  # The HumanMessage with summary  # ty: ignore[invalid-argument-type]\n            \"file_path\": file_path,\n        }\n\n        # Modify request to use summarized messages","sourceCodeStart":1426,"sourceCodeEnd":1462,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/deepagents/deepagents/middleware/summarization.py#L1426-L1462","documentation":"A UserWarning raised by the summarization middleware's sync `wrap_model_call`. When the conversation exceeds token thresholds, the middleware offloads older messages (including inline media) to a file in the configured backend before summarizing. This warning means the history file WAS written, but some media blocks (images, etc.) could not be offloaded and were saved only as failed placeholders — the original media bytes are lost and cannot be recovered from the saved history.","triggerScenarios":"`SummarizationMiddleware.wrap_model_call` runs when `_should_summarize` is true (or a `ContextOverflowError` is caught), `_offload_inline_media` returns a non-empty `failed_media` count (a media block fails backend upload or encoding), yet `_offload_to_backend` succeeds (returns a `file_path`). The `failed_media` count and the saved `file_path` are interpolated into the message.","commonSituations":"Long agent sessions with image-bearing tool results or multimodal user messages that trip the token limit; a storage backend that rejects large or unsupported payloads (size limits, permissions, transient object-store errors); media blocks in message formats the offloader cannot serialize.","solutions":["Inspect the saved history file at the `file_path` in the warning to see which blocks are failed placeholders.","Check backend connectivity, credentials, and size limits — fix the upload failure so future media offloads succeed.","Re-upload or re-attach the original media if you still hold it (e.g. re-run the tool that produced it); the middleware cannot recover it.","Raise the summarization token threshold or pre-truncate large tool results so media offload triggers less often.","If the media is not needed for the rest of the session, treat the warning as informational and continue."],"exampleFix":"// before\nmiddleware = SummarizationMiddleware(backend=unreachable_backend)\n\n// after\nbackend = StateBackend()  # or a reachable/credentialed store\nmiddleware = SummarizationMiddleware(backend=backend, keep_messages=20)","handlingStrategy":"validation","validationCode":"# verify the backend is writable before starting the session\nfrom deepagents.backends import StateBackend\nbackend = build_backend()\nprobe = backend.write(\"/_healthcheck/probe.txt\", b\"ok\")\nassert not getattr(probe, \"error\", None), \"backend not writable; media offload will fail\"","typeGuard":"def backend_ok(backend) -> bool:\n    try:\n        result = backend.write(\"/_healthcheck/probe.txt\", b\"ok\")\n        return getattr(result, \"error\", None) is None\n    except Exception:\n        return False","tryCatchPattern":"import warnings\nwith warnings.catch_warnings(record=True) as caught:\n    warnings.simplefilter(\"always\")\n    run_agent(...)\nmedia_warnings = [w for w in caught if \"media\" in str(w.message) and \"offloaded\" in str(w.message)]\nfor w in media_warnings:\n    file_path = str(w.message).split(\"offloaded to \")[1].split(\",\")[0]\n    inspect_history_file(file_path)  # find failed placeholders and re-attach media","preventionTips":["Verify backend connectivity and credentials before long multimodal sessions.","Confirm the backend accepts your media payload sizes (object-store limits).","Tune summarization thresholds so offload happens under healthy storage conditions.","Keep original media (tool outputs, uploads) retrievable outside the agent history.","Treat `warnings` from the summarization middleware as signals, not noise — alert on them in production."],"tags":["summarization","media","storage","data-loss","python"],"backgroundTag":"media-offload-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}