agentscope-ai/agentscope · error · ValueError
Unsupported audio source type: {type(source)}
Error message
Unsupported audio source type: {type(source)} What it means
DashScope formatter raises this ValueError in _format_audio_source when an audio block's source object is neither a URLSource nor a Base64Source (e.g. a LocalFileSource or raw string/bytes). The formatter dispatches on isinstance checks for those two source types; anything else falls through to this raise. It indicates the message's audio data block was built with a source type unsupported by the DashScope backend formatter.
Source
Thrown at src/agentscope/formatter/_dashscope_formatter.py:216
with open(local_path, "rb") as f:
encoded = base64.b64encode(f.read()).decode("utf-8")
return {
"type": "input_audio",
"input_audio": {
"data": f"data:;base64,{encoded}",
"format": fmt,
},
}
else:
return {
"type": "input_audio",
"input_audio": {
"data": url_str,
"format": fmt,
},
}
raise ValueError(f"Unsupported audio source type: {type(source)}")
class DashScopeChatFormatter(_DashScopeFormatterBase):
"""The DashScope formatter class for chatbot scenario (OpenAI-compatible
format), where only a user and an agent are involved. We use the ``role``
field to identify different entities in the conversation.
This formatter outputs messages in the OpenAI Chat Completions format,
with DashScope-specific extensions for video (``video_url``) and
thinking (``reasoning_content``).
"""
# pylint: disable=too-many-branches
async def format(
self,
msgs: list[Msg],
) -> list[dict[str, Any]]:
"""Format message objects into DashScope OpenAI-compatible format.View on GitHub (pinned to e90f1c7592)
Solutions
- Convert the audio to a Base64Source before formatting (read the file, base64-encode it, set media_type e.g. 'audio/wav')
- If the file is hosted, use a URLSource pointing to the remote audio instead
- Check the source type before calling format() and give a clear user-facing error or fallback to text
- If you control the pipeline, normalize all media blocks to URLSource/Base64Source at message-construction time
Example fix
# before
msg = Msg("user", [AudioBlock(source=LocalFileSource(path="clip.wav"), alt="clip")])
formatter.format(msg)
# after
import base64
data = base64.b64encode(open("clip.wav", "rb").read()).decode()
msg = Msg("user", [AudioBlock(source=Base64Source(data=data, media_type="audio/wav"), alt="clip")])
formatter.format(msg) Defensive patterns
Strategy: type-guard
Validate before calling
from agentscope.message import URLSource, Base64Source
src = block.source
assert isinstance(src, (URLSource, Base64Source)), f"audio source must be URL/Base64, got {type(src)}" Type guard
def is_dashscope_audio_source(src) -> bool:
return isinstance(src, (URLSource, Base64Source)) Try / catch
try:
formatted = formatter.format(msgs)
except ValueError as e:
if "Unsupported audio source type" in str(e):
# strip audio blocks or convert to base64, then retry
...
raise Prevention
- Normalize all media sources to URLSource/Base64Source at message construction time
- Centralize a to_base64_source(path, media_type) helper for local files
When it happens
Trigger: Calling format() on a DashScope formatter with a Msg containing an AudioBlock whose source is a LocalFileSource (or plain path string/bytes) instead of URLSource/Base64Source; any custom source class not derived from the two supported types.
Common situations: Loading audio from a local file path and passing the path or LocalFileSource directly into the audio block; migrating messages between model formatters (OpenAI/Ollama accept local files, DashScope does not); constructing blocks from dicts without going through the source factory helpers.
Related errors
- Unsupported audio source type: {type(source)}.
- Unsupported source type: {type(source)}
- Unsupported image source type: {type(source)}
- Unsupported source type: {type(source)}
- Unsupported image source type: {type(source)}
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/1d4c93b87fe45611.
Report an issue: GitHub.