#9771·AstrBot

[Bug] DeepSeek 视觉模型在工具循环中因不支持的图片格式报 400 unsupported image

Author: unknowbugCreated Aug 22, 2026Updated Sep 15, 2026
Labelsarea:provider

问题描述

AstrBot 在工具循环(tool_loop_agent_runner)中使用 DeepSeek 视觉模型 deepseek/deepseek-v4-flash-vision-exp 时,会偶发/持续返回 400:

.messages[67].image[0]: You have uploaded an unsupported image. Please make sure your image is valid and has one of the following formats: webp, png, jpeg, and gif.

同一个会话在某个时间点之前可以正常回复;之后一旦上下文中进入一张 DeepSeek 不支持的图片,后续所有请求都会失败。

根因:

  • AstrBot 在 OpenAI 兼容适配器的 _resolve_image_part / _transform_content_part 中,对图片解析失败时仍保留原始 image_url 块(return resolved_part or part),导致不支持的格式仍被发送给 DeepSeek。
  • tool_loop_agent_runner 在工具返回图片后会按 cached_img.mime_type 原样拼接 data:{mime_type};base64,... 追加为 user 消息;tool_image_cache 允许 image/svg+xmlimage/bmpimage/tiffimage/avif 等 MIME。DeepSeek 视觉模型只接受 webp/png/jpeg/gif

本地已用临时补丁验证:在发送前将非白名单格式的图片转换为 JPEG/PNG,无法解析的 SVG 替换为文本占位,问题不再出现。

如何复现

  1. 配置 DeepSeek 视觉模型 deepseek-v4-flash-vision-exp 为默认模型,modalities 包含 text/image/tool_use
  2. 在一个群聊/会话中让 Agent 的工具返回一张非 webp/png/jpeg/gif 的图片(例如 SVG、BMP、TIFF、AVIF),或者让历史上下文中存在 PIL 无法正确解析的图片。
  3. 下一次调用该视觉模型时,DeepSeek 返回上面的 400 错误,Agent 进入 ERROR 状态。
  4. 由于该问题图片会留在会话上下文中,后续同一会话的请求会持续报错。

AstrBot 版本

v4.27.4

操作系统

Windows

部署方式

uv tool 安装,数据目录在 D:\Program Files\AstrBot

使用的消息平台适配器

aiocqhttp(OneBot v11)

错误日志

2026-08-22 19:26:36.383] [Core] [DBUG] [pipeline.scheduler:97]: pipeline execution completed.
[2026-08-22 19:26:36.772] [Core] [WARN] [runners.tool_loop_agent_runner:616]: Chat Model deepseek/deepseek-v4-flash-vision-exp request error: Error code: 400 - {'error': {'message': '.messages[67].image[0]: You have uploaded an unsupported image. Please make sure your image is valid and has one of the following formats: webp, png, jpeg, and gif.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}
Traceback (most recent call last):
  File "...\astrbot\core\agent\runners\tool_loop_agent_runner.py", line 529, in _iter_llm_responses
    resp = await self._await_or_stop(self.provider.text_chat(**payload))
  ...
openai.BadRequestError: Error code: 400 - {'error': {'message': '.messages[67].image[0]: You have uploaded an unsupported image. Please make sure your image is valid and has one of the following formats: webp, png, jpeg, and gif.', ...}}
[2026-08-22 19:26:37.060] [Core] [DBUG] [runners.base:64]: Agent state transition: AgentState.RUNNING -> AgentState.ERROR

辅助信息

相关代码位置:

  • astrbot/core/provider/sources/openai_source.py_resolve_image_part_transform_content_part
  • astrbot/core/agent/runners/tool_loop_agent_runner.py:工具图片缓存后的 user 消息构造(约 1021-1056 行)
  • astrbot/core/agent/tool_image_cache.py:允许的 MIME 扩展映射(含 svg/bmp)

建议修复方向:

  1. _resolve_image_part 中对 DeepSeek 等视觉模型做格式白名单处理:webp/png/jpeg/gif 保留;BMP/TIFF/AVIF 等转为 JPEG/PNG;SVG 等 PIL 无法解析的格式替换为纯文本占位,不再发送原始 image_url
  2. 修改 _transform_content_part:图片解析失败时不要 return resolved_part or part,而是直接替换为文本占位或丢弃。
  3. tool_loop_agent_runner 的 cached image 路径中同样按白名单过滤/转换 MIME。

检查清单

  • 我已在 Issue 列表中搜索过相关问题仍无法解决,或该问题从未被报告过。
  • 我已尝试过禁用所有插件,排除了可能是因插件导致的问题。
  • 我报告的问题与 AstrBot 本体相关,而非在报告某一插件的问题。
  • 我已阅读并同意本项目的贡献者行为准则
  • (可选)我愿意提交 PR 以帮助修复该问题。