{"record":{"id":"ddf6b029d9238377","repo":"agentscope-ai/agentscope","slug":"unsupported-source-type-type-source-ddf6b0","errorCode":null,"errorMessage":"Unsupported source type: {type(source)}","messagePattern":"Unsupported source type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/formatter/_gemini_formatter.py","lineNumber":108,"sourceCode":"                return {\n                    \"inline_data\": {\n                        \"data\": data,\n                        \"mime_type\": source.media_type,\n                    },\n                }\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 {\n                    \"inline_data\": {\n                        \"data\": data,\n                        \"mime_type\": source.media_type,\n                    },\n                }\n        else:\n            raise ValueError(f\"Unsupported source type: {type(source)}\")\n\n\nclass GeminiChatFormatter(_GeminiFormatterBase):\n    \"\"\"The Gemini formatter class for chatbot scenario, where only a user\n    and an agent are involved. We use the `role` field to identify different\n    entities in the conversation.\n    \"\"\"\n\n    input_types: list[str] = Field(\n        default_factory=lambda: [\n            \"text/plain\",\n            \"image/*\",\n            \"audio/*\",\n            \"video/*\",\n            \"application/pdf\",\n        ],\n        description=(\n            'The supported input types. Defaults to ``[\"text/plain\", '","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/formatter/_gemini_formatter.py#L90-L126","documentation":"The Gemini formatter's _format_media_source raises ValueError when a media block's source is neither a URLSource nor a Base64Source (the inline_data branch shown handles base64). Gemini's API accepts either inline base64 data or remote URIs, so other source types (e.g. LocalFileSource) are unsupported here.","triggerScenarios":"Formatting a Msg containing an ImageBlock/VideoBlock/AudioBlock whose source is a LocalFileSource or a raw path string/bytes with a GeminiChatFormatter.","commonSituations":"Pointing blocks at local files and expecting the Gemini formatter to upload them; reusing message pipelines built for OpenAI/Ollama formatters that handle local files; passing file-like objects as sources.","solutions":["Convert local files to Base64Source (read bytes, base64-encode, set the correct mime_type)","Use a URLSource with a publicly reachable URL (Google can fetch remote URIs)","Pre-validate source types before calling format() and fall back to a textual representation for unsupported ones"],"exampleFix":"# before\nblock = ImageBlock(source=LocalFileSource(path=\"pic.png\"), alt=\"pic\")\n\n# after\nimport base64\nblock = ImageBlock(source=Base64Source(data=base64.b64encode(open(\"pic.png\",\"rb\").read()).decode(), media_type=\"image/png\"), alt=\"pic\")","handlingStrategy":"type-guard","validationCode":"from agentscope.message import URLSource, Base64Source\nassert isinstance(block.source, (URLSource, Base64Source))","typeGuard":"def is_gemini_media_source(src) -> bool:\n    return isinstance(src, (URLSource, Base64Source))","tryCatchPattern":"try:\n    formatted = formatter.format(msgs)\nexcept ValueError as e:\n    if \"Unsupported source type\" in str(e):\n        # drop the media block or convert local file to Base64Source, retry\n        ...\n    raise","preventionTips":["Convert local media to Base64Source before formatting for Gemini","Keep a shared normalize_sources(msgs) step in multimodal pipelines"],"tags":["gemini","multimodal","formatter","media","agentscope"],"backgroundTag":"unsupported-media-source-type","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}