{"record":{"id":"da79489ae50fd06a","repo":"microsoft/autogen","slug":"image-content-cannot-be-converted-to-text","errorCode":null,"errorMessage":"Image content cannot be converted to text","messagePattern":"Image content cannot be converted to text","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/experimental/task_centric_memory/utils/teachability.py","lineNumber":51,"sourceCode":"        return self._name\n\n    def _extract_text(self, content_item: str | MemoryContent) -> str:\n        \"\"\"Extract searchable text from content.\"\"\"\n        if isinstance(content_item, str):\n            return content_item\n\n        content = content_item.content\n        mime_type = content_item.mime_type\n\n        if mime_type in [MemoryMimeType.TEXT, MemoryMimeType.MARKDOWN]:\n            return str(content)\n        elif mime_type == MemoryMimeType.JSON:\n            if isinstance(content, dict):\n                # Store original JSON string representation\n                return str(content).lower()\n            raise ValueError(\"JSON content must be a dict\")\n        elif isinstance(content, Image):\n            raise ValueError(\"Image content cannot be converted to text\")\n        else:\n            raise ValueError(f\"Unsupported content type: {mime_type}\")\n\n    async def update_context(\n        self,\n        model_context: ChatCompletionContext,\n    ) -> UpdateContextResult:\n        \"\"\"\n        Extracts any advice from the last user turn to be stored in memory,\n        and adds any relevant memories to the model context.\n        \"\"\"\n        self._logger.enter_function()\n\n        # Extract text from the user's last message\n        messages = await model_context.get_messages()\n        if not messages:\n            self._logger.leave_function()\n            return UpdateContextResult(memories=MemoryQueryResult(results=[]))","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/experimental/task_centric_memory/utils/teachability.py#L33-L69","documentation":"Teachability's text extraction cannot convert binary/image memory items to text. When a MemoryContent contains an Image object, the converter raises because advice extraction and retrieval operate on text only.","triggerScenarios":"Passing MemoryContent(content=Image.from_uri(...)) (or any Image instance) into the teachability memory's update_context / query path, which routes through the text converter.","commonSituations":"Multimodal agents sharing a memory store with image artifacts; accidentally storing screenshot/image content in a text-only teachable memory.","solutions":["Filter out image contents before adding them to the teachability memory (check isinstance(content, Image)).","Store a textual description/caption of the image instead of the Image object.","Use a memory implementation that supports multimodal content for images."],"exampleFix":"# before\nawait memory.add(MemoryContent(content=Image.from_uri(img_uri), mime_type=MemoryMimeType.IMAGE))\n# after\nawait memory.add(MemoryContent(content=describe_image(img_uri), mime_type=MemoryMimeType.TEXT))","handlingStrategy":"validation","validationCode":"from autogen_core.models import Image\nif isinstance(content, Image):\n    raise SkipContent(\"image not supported by teachability\")  # or convert to a caption\nc = MemoryContent(content=content, mime_type=MemoryMimeType.TEXT)","typeGuard":"from autogen_core.models import Image\n\ndef is_text_safe_memory_content(content) -> bool:\n    return not isinstance(content, Image)","tryCatchPattern":null,"preventionTips":["Filter Image instances out before adding to teachability memory.","Store image captions/descriptions instead of Image objects.","Keep a separate multimodal memory for binary artifacts."],"tags":["autogen","memory","multimodal","validation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}