[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+xml、image/bmp、image/tiff、image/avif等 MIME。DeepSeek 视觉模型只接受webp/png/jpeg/gif。
本地已用临时补丁验证:在发送前将非白名单格式的图片转换为 JPEG/PNG,无法解析的 SVG 替换为文本占位,问题不再出现。
如何复现
- 配置 DeepSeek 视觉模型
deepseek-v4-flash-vision-exp为默认模型,modalities包含text/image/tool_use。 - 在一个群聊/会话中让 Agent 的工具返回一张非
webp/png/jpeg/gif的图片(例如 SVG、BMP、TIFF、AVIF),或者让历史上下文中存在 PIL 无法正确解析的图片。 - 下一次调用该视觉模型时,DeepSeek 返回上面的 400 错误,Agent 进入
ERROR状态。 - 由于该问题图片会留在会话上下文中,后续同一会话的请求会持续报错。
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_partastrbot/core/agent/runners/tool_loop_agent_runner.py:工具图片缓存后的 user 消息构造(约 1021-1056 行)astrbot/core/agent/tool_image_cache.py:允许的 MIME 扩展映射(含 svg/bmp)
建议修复方向:
- 在
_resolve_image_part中对 DeepSeek 等视觉模型做格式白名单处理:webp/png/jpeg/gif保留;BMP/TIFF/AVIF等转为 JPEG/PNG;SVG等 PIL 无法解析的格式替换为纯文本占位,不再发送原始image_url。 - 修改
_transform_content_part:图片解析失败时不要return resolved_part or part,而是直接替换为文本占位或丢弃。 - 在
tool_loop_agent_runner的 cached image 路径中同样按白名单过滤/转换 MIME。
检查清单
Source: AstrBotDevs/AstrBot