{"record":{"id":"1d4c93b87fe45611","repo":"agentscope-ai/agentscope","slug":"unsupported-audio-source-type-type-source","errorCode":null,"errorMessage":"Unsupported audio source type: {type(source)}","messagePattern":"Unsupported audio source type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/formatter/_dashscope_formatter.py","lineNumber":216,"sourceCode":"                with open(local_path, \"rb\") as f:\n                    encoded = base64.b64encode(f.read()).decode(\"utf-8\")\n                return {\n                    \"type\": \"input_audio\",\n                    \"input_audio\": {\n                        \"data\": f\"data:;base64,{encoded}\",\n                        \"format\": fmt,\n                    },\n                }\n            else:\n                return {\n                    \"type\": \"input_audio\",\n                    \"input_audio\": {\n                        \"data\": url_str,\n                        \"format\": fmt,\n                    },\n                }\n\n        raise ValueError(f\"Unsupported audio source type: {type(source)}\")\n\n\nclass DashScopeChatFormatter(_DashScopeFormatterBase):\n    \"\"\"The DashScope formatter class for chatbot scenario (OpenAI-compatible\n    format), where only a user and an agent are involved. We use the ``role``\n    field to identify different entities in the conversation.\n\n    This formatter outputs messages in the OpenAI Chat Completions format,\n    with DashScope-specific extensions for video (``video_url``) and\n    thinking (``reasoning_content``).\n    \"\"\"\n\n    # pylint: disable=too-many-branches\n    async def format(\n        self,\n        msgs: list[Msg],\n    ) -> list[dict[str, Any]]:\n        \"\"\"Format message objects into DashScope OpenAI-compatible format.","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/formatter/_dashscope_formatter.py#L198-L234","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nmsg = Msg(\"user\", [AudioBlock(source=LocalFileSource(path=\"clip.wav\"), alt=\"clip\")])\nformatter.format(msg)\n\n# after\nimport base64\ndata = base64.b64encode(open(\"clip.wav\", \"rb\").read()).decode()\nmsg = Msg(\"user\", [AudioBlock(source=Base64Source(data=data, media_type=\"audio/wav\"), alt=\"clip\")])\nformatter.format(msg)","handlingStrategy":"type-guard","validationCode":"from agentscope.message import URLSource, Base64Source\nsrc = block.source\nassert isinstance(src, (URLSource, Base64Source)), f\"audio source must be URL/Base64, got {type(src)}\"","typeGuard":"def is_dashscope_audio_source(src) -> bool:\n    return isinstance(src, (URLSource, Base64Source))","tryCatchPattern":"try:\n    formatted = formatter.format(msgs)\nexcept ValueError as e:\n    if \"Unsupported audio source type\" in str(e):\n        # strip audio blocks or convert to base64, then retry\n        ...\n    raise","preventionTips":["Normalize all media sources to URLSource/Base64Source at message construction time","Centralize a to_base64_source(path, media_type) helper for local files"],"tags":["dashscope","audio","multimodal","formatter","agentscope"],"backgroundTag":"unsupported-media-source-type","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}