agentscope-ai/agentscope · error · RuntimeError

Supported OpenAI Responses tool-result media could not be fo

Error message

Supported OpenAI Responses tool-result media could not be formatted: {media_type}.

What it means

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.

Source

Thrown at src/agentscope/formatter/_openai_response_formatter.py:138

            if isinstance(block, TextBlock):
                output_parts.append(
                    {"type": "input_text", "text": block.text},
                )
                continue

            media_type = block.source.media_type
            supports_native_output = (
                media_type.split("/", 1)[0] == "image"
                or media_type == "application/pdf"
            ) and any(
                fnmatch(media_type, pattern)
                for pattern in self.supported_input_media_types
            )

            if supports_native_output:
                formatted = self._format_response_data_block(block)
                if formatted is None:
                    raise RuntimeError(
                        "Supported OpenAI Responses tool-result media could "
                        f"not be formatted: {media_type}.",
                    )
                output_parts.append(formatted)
                has_native_media = True
            else:
                output_parts.append(
                    {
                        "type": "input_text",
                        "text": (
                            self._convert_unsupported_data_block_to_string(
                                block,
                            )
                        ),
                    },
                )

        if has_native_media:

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Inspect the exact media_type in the message and verify the block's payload structure (data/base64/url fields) matches what the formatter expects
  2. Check for a version mismatch: upgrade agentscope so the formatter supports the media type declared as supported
  3. Re-encode the tool-result media into a plainly supported form (e.g. base64-encoded image/png) before putting it in the tool result
  4. If using custom ContentBlock subclasses, ensure they carry the fields _format_response_data_block reads, or register a custom formatter

Example fix

// before
result = ToolResultBlock(content=[ImageBlock(url=chart_url, media_type="image/svg+xml")])
msg = Msg("tool", content=[result])
formatter.format(msg)  # raises 220

// after
png = convert_svg_to_png_bytes(chart_url)
b64 = base64.b64encode(png).decode()
result = ToolResultBlock(content=[ImageBlock(data=b64, media_type="image/png")])
msg = Msg("tool", content=[result])
formatter.format(msg)
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED = {"image/png", "image/jpeg", "image/gif", "image/webp"}
media_types = [b.media_type for b in tool_result_content if getattr(b, "media_type", None)]
assert all(m in SUPPORTED for m in media_types), f"unsupported media: {media_types}"

Try / catch

try:
    formatter.format(msg)
except RuntimeError as e:
    if "could not be formatted" in str(e):
        # strip media from tool result and retry with text-only output
        ...

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28). Data as JSON: /api/errors/6516f2497975e9b6. Report an issue: GitHub.