agentscope-ai/agentscope · error · ValueError
Unsupported source type: {type(source)}
Error message
Unsupported source type: {type(source)} What it means
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.
Source
Thrown at src/agentscope/formatter/_gemini_formatter.py:108
return {
"inline_data": {
"data": data,
"mime_type": source.media_type,
},
}
else:
# Remote URL - download and convert to base64
response = requests.get(url, timeout=30)
response.raise_for_status()
data = base64.b64encode(response.content).decode("utf-8")
return {
"inline_data": {
"data": data,
"mime_type": source.media_type,
},
}
else:
raise ValueError(f"Unsupported source type: {type(source)}")
class GeminiChatFormatter(_GeminiFormatterBase):
"""The Gemini 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(
default_factory=lambda: [
"text/plain",
"image/*",
"audio/*",
"video/*",
"application/pdf",
],
description=(
'The supported input types. Defaults to ``["text/plain", 'View on GitHub (pinned to e90f1c7592)
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
Example fix
# before
block = ImageBlock(source=LocalFileSource(path="pic.png"), alt="pic")
# after
import base64
block = ImageBlock(source=Base64Source(data=base64.b64encode(open("pic.png","rb").read()).decode(), media_type="image/png"), alt="pic") Defensive patterns
Strategy: type-guard
Validate before calling
from agentscope.message import URLSource, Base64Source assert isinstance(block.source, (URLSource, Base64Source))
Type guard
def is_gemini_media_source(src) -> bool:
return isinstance(src, (URLSource, Base64Source)) Try / catch
try:
formatted = formatter.format(msgs)
except ValueError as e:
if "Unsupported source type" in str(e):
# drop the media block or convert local file to Base64Source, retry
...
raise Prevention
- Convert local media to Base64Source before formatting for Gemini
- Keep a shared normalize_sources(msgs) step in multimodal pipelines
When it happens
Trigger: Formatting a Msg containing an ImageBlock/VideoBlock/AudioBlock whose source is a LocalFileSource or a raw path string/bytes with a GeminiChatFormatter.
Common situations: 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.
Related errors
- Unsupported audio source type: {type(source)}
- Unsupported image source type: {type(source)}
- Unsupported source type: {type(source)}
- Unsupported image source type: {type(source)}
- Unsupported audio source type: {type(source)}.
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/ddf6b029d9238377.
Report an issue: GitHub.