{"record":{"id":"6c8a47380622657c","repo":"agentscope-ai/agentscope","slug":"unsupported-source-type-type-source-6c8a47","errorCode":null,"errorMessage":"Unsupported source type: {type(source)}","messagePattern":"Unsupported source type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/formatter/_ollama_formatter.py","lineNumber":99,"sourceCode":"        \"\"\"\n        if isinstance(source, Base64Source):\n            return source.data\n        elif isinstance(source, URLSource):\n            url = str(source.url)\n            if url.startswith(\"file://\"):\n                # Local file - read and convert to base64\n                file_path = url.removeprefix(\"file://\")\n                with open(file_path, \"rb\") as f:\n                    data = base64.b64encode(f.read()).decode(\"utf-8\")\n                return data\n            else:\n                # Remote URL - download and convert to base64\n                response = requests.get(url, timeout=30)\n                response.raise_for_status()\n                data = base64.b64encode(response.content).decode(\"utf-8\")\n                return data\n        else:\n            raise ValueError(f\"Unsupported source type: {type(source)}\")\n\n\nclass OllamaChatFormatter(_OllamaFormatterBase):\n    \"\"\"The Ollama formatter class for chatbot scenario, where only a user\n    and an agent are involved. We use the `role` field to identify different\n    participants in the conversation.\n    \"\"\"\n\n    input_types: list[str] = Field(\n        default_factory=lambda: [\"text/plain\", \"image/*\"],\n        description=(\n            \"The supported input types. \"\n            'Defaults to ``[\"text/plain\", \"image/*\"]``.'\n        ),\n    )\n\n    async def format(\n        self,","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/formatter/_ollama_formatter.py#L81-L117","documentation":"The Ollama formatter's _format_image_source accepts Base64Source and URLSource (downloading remote URLs and converting to base64, since Ollama expects base64 image data); any other source type (LocalFileSource, plain strings/bytes) triggers this ValueError.","triggerScenarios":"Formatting a Msg with an ImageBlock whose source is a LocalFileSource or another unsupported source class via OllamaChatFormatter.","commonSituations":"Assuming Ollama, being local, can read local file paths directly; porting multimodal messages from other providers; constructing sources from raw paths without the typed wrapper classes.","solutions":["Read the local file and wrap it in a Base64Source","Or use a URLSource if the image is remotely hosted (the formatter downloads it)","Normalize message blocks to Base64Source at construction time when targeting Ollama"],"exampleFix":"# before\nImageBlock(source=LocalFileSource(path=\"dog.png\"), alt=\"dog\")\n\n# after\nimport base64\nImageBlock(source=Base64Source(data=base64.b64encode(open(\"dog.png\",\"rb\").read()).decode(), media_type=\"image/png\"), alt=\"dog\")","handlingStrategy":"type-guard","validationCode":"from agentscope.message import URLSource, Base64Source\nassert isinstance(block.source, (URLSource, Base64Source))","typeGuard":"def is_ollama_image_source(src) -> bool:\n    return isinstance(src, (URLSource, Base64Source))","tryCatchPattern":"try:\n    formatter.format(msgs)\nexcept ValueError as e:\n    if \"Unsupported source type\" in str(e):\n        block.source = to_base64_source(path)\n        formatted = formatter.format(msgs)\n    else:\n        raise","preventionTips":["Ollama always receives base64 — normalize local files to Base64Source at construction","Wrap requests-based downloads with retries if using URLSource"],"tags":["ollama","image","multimodal","formatter","agentscope"],"backgroundTag":"unsupported-media-source-type","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}