{"record":{"id":"35e975a0cb854a78","repo":"agentscope-ai/agentscope","slug":"unsupported-image-source-type-type-source-35e975","errorCode":null,"errorMessage":"Unsupported image source type: {type(source)}","messagePattern":"Unsupported image source type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/formatter/_moonshot_formatter.py","lineNumber":51,"sourceCode":"    \"\"\"\n    if isinstance(source, Base64Source):\n        url = f\"data:{source.media_type};base64,{source.data}\"\n\n    elif isinstance(source, URLSource):\n        url_str = str(source.url)\n        if url_str.startswith(\"file://\"):\n            local_path = url_str.removeprefix(\"file://\")\n            with open(local_path, \"rb\") as f:\n                encoded = base64.b64encode(f.read()).decode(\"utf-8\")\n            url = f\"data:{source.media_type};base64,{encoded}\"\n        else:\n            response = requests.get(url_str, timeout=30)\n            response.raise_for_status()\n            encoded = base64.b64encode(response.content).decode(\"utf-8\")\n            url = f\"data:{source.media_type};base64,{encoded}\"\n\n    else:\n        raise ValueError(f\"Unsupported image source type: {type(source)}\")\n\n    return {\n        \"type\": \"image_url\",\n        \"image_url\": {\"url\": url},\n    }\n\n\nclass MoonshotChatFormatter(_OpenAIFormatterBase):\n    \"\"\"The Moonshot AI formatter for chatbot scenario.\n\n    Moonshot's API is OpenAI-compatible, but thinking models (``kimi-k2.6``,\n    ``kimi-k2-thinking``) return a ``reasoning_content`` field alongside\n    ``content`` in assistant messages.  This formatter preserves that field\n    when re-sending assistant messages back to the API so that the\n    *Preserved Thinking* feature works correctly in multi-turn conversations.\n    \"\"\"\n\n    input_types: list[str] = Field(","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/formatter/_moonshot_formatter.py#L33-L69","documentation":"The Moonshot formatter only accepts URLSource (remote URLs are converted to base64 data URLs by downloading) and Base64Source for images; any other source type (e.g. LocalFileSource, raw bytes) hits this ValueError in _moonshot_format_image_source.","triggerScenarios":"Passing an ImageBlock with a LocalFileSource or non-URL/base64 source to the Moonshot formatter; using a source class the Moonshot path doesn't isinstance-match.","commonSituations":"Local image paths fed into Moonshot pipelines; sharing message-building code across providers where some accept local files; stale source objects after library upgrades that renamed source classes.","solutions":["Convert the local image to a Base64Source before formatting","Host the image and use URLSource with the public URL","Pre-check source types and provide a text fallback for unsupported blocks"],"exampleFix":"# before\nImageBlock(source=LocalFileSource(path=\"cat.jpg\"), alt=\"cat\")\n\n# after\nimport base64\nImageBlock(source=Base64Source(data=base64.b64encode(open(\"cat.jpg\",\"rb\").read()).decode(), media_type=\"image/jpeg\"), alt=\"cat\")","handlingStrategy":"type-guard","validationCode":"from agentscope.message import URLSource, Base64Source\nassert isinstance(block.source, (URLSource, Base64Source))","typeGuard":"def is_moonshot_image_source(src) -> bool:\n    return isinstance(src, (URLSource, Base64Source))","tryCatchPattern":"try:\n    formatter.format(msgs)\nexcept ValueError as e:\n    if \"Unsupported image source type\" in str(e):\n        block.source = local_path_to_base64_source(path)  # then retry\n    else:\n        raise","preventionTips":["Convert local images to Base64Source up front","Remember the Moonshot formatter downloads remote URLs — ensure they're reachable to avoid requests errors"],"tags":["moonshot","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"}