agentscope-ai/agentscope · error · ValueError
Unsupported video source type: {type(source)}
Error message
Unsupported video source type: {type(source)} What it means
Video counterpart of the image guard: while formatting a video DataBlock for DashScope, the source is neither a supported inline/local type (converted to a data: URL) nor a URL source, so formatting aborts with ValueError.
Source
Thrown at src/agentscope/formatter/_dashscope_formatter.py:164
"""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}"
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 video source type: {type(source)}")
return {
"type": "video_url",
"video_url": {"url": url},
}
@staticmethod
def _format_audio_source(
source: URLSource | Base64Source,
) -> dict[str, Any]:
"""Convert an audio source to DashScope ``input_audio`` format.
DashScope's compatible API accepts URLs directly in the ``data``
field. Base64-encoded audio must be wrapped in a data URL. Local
files are read, base64-encoded, and wrapped in the same form.
"""
fmt = source.media_type.split("/")[-1]
if fmt == "mpeg":View on GitHub (pinned to e90f1c7592)
Solutions
- Re-encode path as Base64Source/local file source or reference the hosted file with URLSource
- Check that video loading actually succeeded (source is not None) before building the message
- Keep a single agentscope version in the environment
Example fix
# before block = DataBlock(source=None, media_type="video/mp4") # after from agentscope.message import DataBlock, URLSource block = DataBlock(source=URLSource(url="https://cdn/x.mp4", media_type="video/mp4"))
Defensive patterns
Strategy: type-guard
Validate before calling
from agentscope.message import Base64Source, URLSource
for block in msg_video_blocks:
if not isinstance(getattr(block, "source", None), (Base64Source, URLSource)):
raise TypeError("video block source unsupported") Type guard
from agentscope.message import DataBlock, Base64Source, URLSource
def video_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 video source type" in str(e):
msg = normalize_video_blocks(msg)
resp = await model(msg)
else:
raise Prevention
- Check video download/load succeeded (source set) before building messages
- Use URLSource for large videos instead of inline base64
- Normalize all media blocks through one helper before sending
When it happens
Trigger: Video DataBlock with source=None, a plain dict, or a foreign/custom source class passed to a DashScope model; _format_video_source reaches its final else.
Common situations: Large video files where source loading failed silently and left None; mixed-version imports; converting from OpenAI video formats that use dicts.
Related errors
- Unsupported image source type: {type(source)}
- Multimodal embedding API only supports URL input for video d
- Unsupported source type: {type(source)}
- Unsupported audio source type: {type(source)}
- Text embedding model {self.model!r} only accepts str inputs,
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/27bb4a7e28c5f6f2.
Report an issue: GitHub.