Skip to content

[Bug]: OpenAIMessageConverter silently drops DataBlock — multimodal image URL never reaches the model #1693

Closed

Description

@Buktal

Describe the bug

使用 DataBlock + URLSource 构建多模态 UserMessage 时,图片内容被静默丢弃,模型始终收不到图片,只收到文本部分,回复"图片未收到"。

To Reproduce

// 用 DataBlock + URLSource 构建多模态消息
URLSource urlSource = URLSource.builder().url("https://example.com/image.png").build();
DataBlock dataBlock = DataBlock.builder().source(urlSource).build();
TextBlock textBlock = TextBlock.builder().text("分析下这张图片:").build();

UserMessage msg = new UserMessage(List.of(textBlock, dataBlock));
agent.streamEvents(msg, ctx).blockLast();

模型只看到文本块,图片内容消失,回复如"图片未收到,请提供图片链接"。

对比验证:将图片 URL 直接拼进文本(TextBlock("分析下这张图片 https://..."))时,模型可以正常分析图片。

Expected behavior

图片 URL 应以 image_url content part 的形式出现在发给 OpenAI 兼容接口的请求体中,模型能正常处理图片内容。

Error messages

无异常抛出,失败是静默的。OpenAIMessageConverter.convertContentBlocks() 没有 instanceof DataBlock 分支,遇到 DataBlock 直接跳过,不产生任何警告,API 请求体中只剩文本块。

Environment

  • AgentScope-Java Version: 2.0.0-RC1
  • Java Version: 21
  • OS: Windows 11

Additional context

根因:OpenAIMessageConverter.convertContentBlocks() 只处理旧版具体媒体类型(ImageBlock、AudioBlock、VideoBlock),而 2.0 新引入的统一容器 DataBlock 没有对应的 instanceof 分支,会被静默跳过。

DataBlock 的 Javadoc 明确写道它是"面向未来的多模态统一容器",并建议"新代码应优先使用 DataBlock 而非旧版子类"。这造成了误导性契约:按文档推荐的 API 写出来的代码,配合 OpenAIChatModel 使用时行为完全错误。

我们在业务层的临时绕过方案:在 converter 层根据 mimeType 前缀路由,构造对应的旧版媒体块,而非使用 DataBlock。

// 绕过方案 — 在 DataBlock 得到支持前,使用旧版媒体块
URLSource urlSource = URLSource.builder().url(block.getUrl()).build();
if (mimeType.startsWith("video/")) {
    return VideoBlock.builder().source(urlSource).build();
}
if (mimeType.startsWith("audio/")) {
    return AudioBlock.builder().source(urlSource).build();
}
return ImageBlock.builder().source(urlSource).build(); // image/* 或 mimeType 缺失

正确的修复应在 OpenAIMessageConverter.convertContentBlocks() 中增加 DataBlock 分支,根据 source 的媒体类型(或推断类型)派发到对应的 content part。

Activity

  1. added
    bug
    on Jun 10, 2026
  2. added
    area/core/model
    on Jun 10, 2026
  3. moved this from Backlog to In progress in AgentScope Javaon Jun 13, 2026
  4. moved this from In progress to Done in AgentScope Javaon Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/core/modelbug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions