agentscope-ai/agentscope · error · ValueError
Unsupported image source type: {type(source)}
Error message
Unsupported image source type: {type(source)} What it means
The DashScope (Qwen) formatter builds an OpenAI-style image_url payload and only handles supported image source types (inline base64/local file -> data URL, and URL sources). Any other source object (None, dict, custom class) raises this ValueError before the request is sent.
Source
Thrown at src/agentscope/formatter/_dashscope_formatter.py:135
) -> dict[str, Any]:
"""Convert an image source to OpenAI-compatible ``image_url`` format.
Local ``file://`` URLs are read from disk and converted to base64
data URIs. Remote URLs are passed through unchanged.
"""
if isinstance(source, Base64Source):
url = f"data:{source.media_type};base64,{source.data}"
elif isinstance(source, URLSource):
url_str = str(source.url)
if url_str.startswith("file://"):
local_path = url_str.removeprefix("file://")
with open(local_path, "rb") as f:
encoded = base64.b64encode(f.read()).decode("utf-8")
url = f"data:{source.media_type};base64,{encoded}"
else:
url = url_str
else:
raise ValueError(f"Unsupported image source type: {type(source)}")
return {
"type": "image_url",
"image_url": {"url": url},
}
@staticmethod
def _format_video_source(
source: URLSource | Base64Source,
) -> dict[str, Any]:
"""Convert a video source to DashScope's ``video_url`` format
(OpenAI-compatible extension).
Local ``file://`` URLs are read from disk and converted to base64
data URIs. Remote URLs are passed through unchanged.
"""
if isinstance(source, Base64Source):
url = f"data:{source.media_type};base64,{source.data}"View on GitHub (pinned to e90f1c7592)
Solutions
- Ensure one agentscope version is installed and DataBlock sources come from agentscope.message
- Convert images to URLSource or Base64Source before adding to the message
- Validate blocks before sending (see type guard below)
Example fix
# before block = DataBlock(source=None, media_type="image/png") # after from agentscope.message import DataBlock, URLSource block = DataBlock(source=URLSource(url=img_url, media_type="image/png"))
Defensive patterns
Strategy: type-guard
Validate before calling
from agentscope.message import Base64Source, URLSource
for block in msg_image_blocks:
if not isinstance(getattr(block, "source", None), (Base64Source, URLSource)):
raise TypeError("image block source unsupported") Type guard
from agentscope.message import DataBlock, Base64Source, URLSource
def image_block_ok(block: DataBlock) -> bool:
return isinstance(getattr(block, "source", None), (Base64Source, URLSource)) Try / catch
try:
resp = await model(msg)
except ValueError as e:
if "Unsupported image source type" in str(e):
msg = normalize_image_blocks(msg)
resp = await model(msg)
else:
raise Prevention
- Convert images to URL or base64 sources at ingestion time
- Never leave DataBlock.source as None after a failed download
- Validate message content in tests with the type guard
When it happens
Trigger: Passing a message with an image DataBlock whose source is an unrecognized type; _format_dashscope_data_block -> _format_image_source falls to the final else.
Common situations: Version mismatch producing isinstance failures; building image blocks with raw dicts from JSON payloads; empty DataBlock with source=None from failed downloads.
Related errors
- Unsupported video source type: {type(source)}
- Unsupported source type: {type(source)}
- Unsupported audio source type: {type(source)}
- Unsupported image source type: {type(source)}
- Unsupported source type: {type(source)}
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/2c557026eb040a23.
Report an issue: GitHub.