agentscope-ai/agentscope · error · ValueError
Unsupported source type: {type(source)}
Error message
Unsupported source type: {type(source)} What it means
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.
Source
Thrown at src/agentscope/formatter/_anthropic_formatter.py:349
The Anthropic block type, ``"image"`` or ``"document"``.
Returns:
`dict[str, Any]`:
The formatted content block.
"""
if isinstance(source, Base64Source):
data = source.data
elif isinstance(source, URLSource):
url = str(source.url)
if url.startswith("file://"):
with open(url.removeprefix("file://"), "rb") as f:
data = base64.b64encode(f.read()).decode("utf-8")
else:
response = requests.get(url, timeout=30)
response.raise_for_status()
data = base64.b64encode(response.content).decode("utf-8")
else:
raise ValueError(f"Unsupported source type: {type(source)}")
return {
"type": block_type,
"source": {
"type": "base64",
"media_type": source.media_type,
"data": data,
},
}
class AnthropicChatFormatter(_AnthropicFormatterBase):
"""The Anthropic formatter class for chatbot scenario, where only a user
and an agent are involved. We use the `role` field to identify different
entities in the conversation.
"""
input_types: list[str] = Field(View on GitHub (pinned to e90f1c7592)
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
Example fix
# before msg.content = [DataBlock(source=custom_src)] # custom_src not Base/URLSource # after from agentscope.message import DataBlock, Base64Source msg.content = [DataBlock(source=Base64Source(data=b64, media_type="image/png"))]
Defensive patterns
Strategy: type-guard
Validate before calling
from agentscope.message import Base64Source, URLSource
for block in content:
src = getattr(block, "source", None)
if src is not None and not isinstance(src, (Base64Source, URLSource)):
raise TypeError(f"unsupported source {type(src)}") Type guard
from agentscope.message import DataBlock, Base64Source, URLSource
def blocks_are_formattable(content: list) -> bool:
return all(
not isinstance(c, DataBlock)
or isinstance(getattr(c, "source", None), (Base64Source, URLSource))
for c in content
) Try / catch
try:
await agent(msg)
except ValueError as e:
if "Unsupported source type" in str(e):
msg = rebuild_blocks_with_supported_sources(msg)
await agent(msg)
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unsupported source type {type(source).__name__} in DataBlock
- Unsupported image source type: {type(source)}
- Unsupported video source type: {type(source)}
- Invalid input: {item!r}. Expected str or DataBlock.
- Unsupported audio source type: {type(source)}
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/74d549c42775ccc6.
Report an issue: GitHub.