{"record":{"id":"6516f2497975e9b6","repo":"agentscope-ai/agentscope","slug":"supported-openai-responses-tool-result-media-could","errorCode":null,"errorMessage":"Supported OpenAI Responses tool-result media could not be formatted: {media_type}.","messagePattern":"Supported OpenAI Responses tool-result media could not be formatted: (.+?)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/agentscope/formatter/_openai_response_formatter.py","lineNumber":138,"sourceCode":"            if isinstance(block, TextBlock):\n                output_parts.append(\n                    {\"type\": \"input_text\", \"text\": block.text},\n                )\n                continue\n\n            media_type = block.source.media_type\n            supports_native_output = (\n                media_type.split(\"/\", 1)[0] == \"image\"\n                or media_type == \"application/pdf\"\n            ) and any(\n                fnmatch(media_type, pattern)\n                for pattern in self.supported_input_media_types\n            )\n\n            if supports_native_output:\n                formatted = self._format_response_data_block(block)\n                if formatted is None:\n                    raise RuntimeError(\n                        \"Supported OpenAI Responses tool-result media could \"\n                        f\"not be formatted: {media_type}.\",\n                    )\n                output_parts.append(formatted)\n                has_native_media = True\n            else:\n                output_parts.append(\n                    {\n                        \"type\": \"input_text\",\n                        \"text\": (\n                            self._convert_unsupported_data_block_to_string(\n                                block,\n                            )\n                        ),\n                    },\n                )\n\n        if has_native_media:","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/formatter/_openai_response_formatter.py#L120-L156","documentation":"The OpenAI Responses formatter found a tool-result media block whose media type is listed as supported, but the internal _format_response_data_block returned None, meaning the block could not be converted into a native Responses API output part. This indicates a mismatch between the declared supported_input_media_types and the formatter's actual conversion capabilities, or a malformed/unsupported data block payload. It is an internal invariant failure surfaced during formatting of an Msg with tool results for the OpenAI Responses API.","triggerScenarios":"Calling format() (or running an agent with the OpenAI Responses model) on a message containing a ToolResultBlock with a media block whose type passes the supported_input_media_types check but whose payload (e.g. image/audio bytes, URL, or base64 data) cannot be mapped by _format_response_data_block.","commonSituations":"Upgrading agentscope where a new media type was added to supported_input_media_types without a matching formatter branch; passing an image/audio block with an unexpected encoding (raw bytes vs base64 vs URL); using a custom block subclass that reports a supported media type but lacks standard fields.","solutions":["Inspect the exact media_type in the message and verify the block's payload structure (data/base64/url fields) matches what the formatter expects","Check for a version mismatch: upgrade agentscope so the formatter supports the media type declared as supported","Re-encode the tool-result media into a plainly supported form (e.g. base64-encoded image/png) before putting it in the tool result","If using custom ContentBlock subclasses, ensure they carry the fields _format_response_data_block reads, or register a custom formatter"],"exampleFix":"// before\nresult = ToolResultBlock(content=[ImageBlock(url=chart_url, media_type=\"image/svg+xml\")])\nmsg = Msg(\"tool\", content=[result])\nformatter.format(msg)  # raises 220\n\n// after\npng = convert_svg_to_png_bytes(chart_url)\nb64 = base64.b64encode(png).decode()\nresult = ToolResultBlock(content=[ImageBlock(data=b64, media_type=\"image/png\")])\nmsg = Msg(\"tool\", content=[result])\nformatter.format(msg)","handlingStrategy":"validation","validationCode":"SUPPORTED = {\"image/png\", \"image/jpeg\", \"image/gif\", \"image/webp\"}\nmedia_types = [b.media_type for b in tool_result_content if getattr(b, \"media_type\", None)]\nassert all(m in SUPPORTED for m in media_types), f\"unsupported media: {media_types}\"","typeGuard":null,"tryCatchPattern":"try:\n    formatter.format(msg)\nexcept RuntimeError as e:\n    if \"could not be formatted\" in str(e):\n        # strip media from tool result and retry with text-only output\n        ...","preventionTips":["Keep tool-result media to widely supported types (png/jpeg base64)","Pin agentscope versions where formatter and supported_input_media_types are consistent","Add a formatting smoke test for every media type your tools emit"],"tags":["openai","responses-api","media-formatting","tool-result"],"backgroundTag":"media-encoding-unsupported","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}