{"record":{"id":"74d549c42775ccc6","repo":"agentscope-ai/agentscope","slug":"unsupported-source-type-type-source","errorCode":null,"errorMessage":"Unsupported source type: {type(source)}","messagePattern":"Unsupported source type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/formatter/_anthropic_formatter.py","lineNumber":349,"sourceCode":"                The Anthropic block type, ``\"image\"`` or ``\"document\"``.\n\n        Returns:\n            `dict[str, Any]`:\n                The formatted content block.\n        \"\"\"\n        if isinstance(source, Base64Source):\n            data = source.data\n        elif isinstance(source, URLSource):\n            url = str(source.url)\n            if url.startswith(\"file://\"):\n                with open(url.removeprefix(\"file://\"), \"rb\") as f:\n                    data = base64.b64encode(f.read()).decode(\"utf-8\")\n            else:\n                response = requests.get(url, timeout=30)\n                response.raise_for_status()\n                data = base64.b64encode(response.content).decode(\"utf-8\")\n        else:\n            raise ValueError(f\"Unsupported source type: {type(source)}\")\n\n        return {\n            \"type\": block_type,\n            \"source\": {\n                \"type\": \"base64\",\n                \"media_type\": source.media_type,\n                \"data\": data,\n            },\n        }\n\n\nclass AnthropicChatFormatter(_AnthropicFormatterBase):\n    \"\"\"The Anthropic 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(","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/formatter/_anthropic_formatter.py#L331-L367","documentation":"The Anthropic formatter converts a DataBlock into an Anthropic base64 content source and only knows how to handle two source shapes (inline base64 data and URL download). Any other source type falls through to this ValueError, so the message cannot be formatted for the API call.","triggerScenarios":"Sending a message whose DataBlock source is None, a dict, or a custom/foreign source class; _format_anthropic_data_block -> _format_source reaches the final else branch.","commonSituations":"Multiple agentscope versions installed so isinstance checks against Base64Source/URLSource fail; hand-constructed message dicts bypassing normal constructors; source objects from plugins or user subclasses.","solutions":["Verify a single agentscope install (fresh venv; pip check) so source classes match","Construct DataBlock with Base64Source or URLSource from agentscope.message","Log type(source) and module to identify stray custom classes, then convert them to a supported source"],"exampleFix":"# before\nmsg.content = [DataBlock(source=custom_src)]  # custom_src not Base/URLSource\n\n# after\nfrom agentscope.message import DataBlock, Base64Source\nmsg.content = [DataBlock(source=Base64Source(data=b64, media_type=\"image/png\"))]","handlingStrategy":"type-guard","validationCode":"from agentscope.message import Base64Source, URLSource\nfor block in content:\n    src = getattr(block, \"source\", None)\n    if src is not None and not isinstance(src, (Base64Source, URLSource)):\n        raise TypeError(f\"unsupported source {type(src)}\")","typeGuard":"from agentscope.message import DataBlock, Base64Source, URLSource\n\ndef blocks_are_formattable(content: list) -> bool:\n    return all(\n        not isinstance(c, DataBlock)\n        or isinstance(getattr(c, \"source\", None), (Base64Source, URLSource))\n        for c in content\n    )","tryCatchPattern":"try:\n    await agent(msg)\nexcept ValueError as e:\n    if \"Unsupported source type\" in str(e):\n        msg = rebuild_blocks_with_supported_sources(msg)\n        await agent(msg)\n    else:\n        raise","preventionTips":["Single agentscope install per venv; run pip check","Build DataBlocks only via agentscope.message constructors","Log type(source).__module__ when this fires to catch dual-version imports"],"tags":["anthropic","formatter","datablock","source-type"],"backgroundTag":"unsupported-source-type","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}