AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

[Bug] 在 QQ 使用 Sandbox 生成图片不显示

Open Kyy008 opened this issue 9 months ago • 4 comments

What happened / 发生了什么

在配置好 SandBox 沙箱环境后,我试图让 Bot 运行一段 python plt 图像生成代码并发送图像给我。通过下面的日志分析可以得知:脚本生成、下载到容器的步骤均正确,且日志无报错并使用了send_message_to_user的tool,但是 QQ 侧却接收不到图像。而如果使用同样的环境和提示词在AstrBot仪表盘的chatui中测试,便可以返回图像。

Reproduce / 如何复现?

  1. 配置好sandbox运行环境,沙箱驱动器为shipyard
  2. 在 QQ 中对 Bot 发送 “画一个y=x的函数图像并发送给我”,可以发现仅输出“图像已经发送给您”的文本
Image 3. 在AstrBot ChatUI中发送 “画一个y=x的函数图像并发送给我”,可以发现成功输出下载文件 Image

AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器

4.17.5 Astrobot Linux docker run 部署 OneBot v11 消息平台 deepseek-chat 模型供应商

OS

Linux

Logs / 报错日志

[2026-02-21 03:57:11.943] [Core] [INFO] [core.event_bus:59]: [default] [Chino_Bot(aiocqhttp)] Kyy008/3149972098: [At:3856235110] 画出y=x的函数图像并发送给我 [2026-02-21 03:57:14.400] [Core] [INFO] [respond.stage:169]: Prepare to send - Kyy008/3149972098: [引用消息] 我来为您绘制 y=x 的函数图像。 首先需要安装必要的绘图库,然后生成图像。 [2026-02-21 03:57:20.028] [Core] [INFO] [runners.tool_loop_agent_runner:532]: Agent 使用工具: ['astrbot_execute_shell'] [2026-02-21 03:57:20.028] [Core] [INFO] [runners.tool_loop_agent_runner:569]: 使用工具:astrbot_execute_shell,参数:{'command': 'pip install matplotlib numpy -q'} [2026-02-21 03:57:22.341] [Core] [INFO] [booters.shipyard:30]: Got sandbox ship: fb742137-5d1a-4a67-810c-f45b20dab772 for session: 819676d3f6d15a6eb0bffbf17f0d9531 [2026-02-21 03:57:25.091] [Core] [INFO] [runners.tool_loop_agent_runner:774]: Tool astrbot_execute_shell Result: {"success": true, "data": {"success": true, "return_code": 0, "stdout": "", "stderr": "[notice] A new release of pip is available: 25.3 -> 26.0.1\n[notice] To update, run: pip install --upgrade pip", "pid": 16, "process_id": null, "error": null}, "error": null} [2026-02-21 03:57:32.002] [Core] [INFO] [respond.stage:169]: Prepare to send - Kyy008/3149972098: [引用消息] 现在创建Python脚本来绘制函数图像: [2026-02-21 03:57:34.720] [Core] [INFO] [runners.tool_loop_agent_runner:532]: Agent 使用工具: ['astrbot_execute_ipython'] [2026-02-21 03:57:34.721] [Core] [INFO] [runners.tool_loop_agent_runner:569]: 使用工具:astrbot_execute_ipython,参数:{'code': 'import numpy as np\nimport matplotlib.pyplot as plt\n\n# 设置中文字体\nplt.rcParams['font.sans-serif'] = ['SimHei', 'DejaVu Sans']\nplt.rcParams['axes.unicode_minus'] = False\n\n# 创建数据\nx = np.linspace(-10, 10, 400)\ny = x\n\n# 创建图形\nplt.figure(figsize=(8, 6))\nplt.plot(x, y, 'b-', linewidth=2, label='y = x')\n\n# 设置图形属性\nplt.axhline(y=0, color='k', linewidth=0.5, alpha=0.5)\nplt.axvline(x=0, color='k', linewidth=0.5, alpha=0.5)\nplt.grid(True, alpha=0.3)\nplt.xlabel('x', fontsize=12)\nplt.ylabel('y', fontsize=12)\nplt.title('函数图像: y = x', fontsize=14)\nplt.legend()\nplt.axis('equal')\nplt.xlim(-10, 10)\nplt.ylim(-10, 10)\n\n# 保存图像\nplt.tight_layout()\nplt.savefig('y_equals_x.png', dpi=100, bbox_inches='tight')\nprint("图像已保存为 y_equals_x.png")'} [2026-02-21 03:57:37.371] [Core] [INFO] [runners.tool_loop_agent_runner:774]: Tool astrbot_execute_ipython Result: Image returned and cached at path='/AstrBot/data/temp/tool_images/call_00_Wr4ZdzD5xu1Pwkqi7slkqBPi_0.png'. Review the image below. Use send_message_to_user to send it to the user if satisfied, with type='image' and path='/AstrBot/data/temp/tool_images/call_00_Wr4ZdzD5xu1Pwkqi7slkqBPi_0.png'. [2026-02-21 03:57:39.810] [Core] [INFO] [respond.stage:169]: Prepare to send - Kyy008/3149972098: [引用消息] 现在让我下载这个图像文件发送给您: [2026-02-21 03:57:42.829] [Core] [INFO] [runners.tool_loop_agent_runner:532]: Agent 使用工具: ['astrbot_download_file'] [2026-02-21 03:57:42.830] [Core] [INFO] [runners.tool_loop_agent_runner:569]: 使用工具:astrbot_download_file,参数:{'remote_path': 'y_equals_x.png', 'also_send_to_user': False} [2026-02-21 03:57:42.874] [Core] [INFO] [tools.fs:177]: File y_equals_x.png downloaded from sandbox to /AstrBot/data/temp/sandbox_dee2_y_equals_x.png [2026-02-21 03:57:42.875] [Core] [INFO] [runners.tool_loop_agent_runner:774]: Tool astrbot_download_file Result: File downloaded successfully to /AstrBot/data/temp/sandbox_dee2_y_equals_x.png [2026-02-21 03:57:45.499] [Core] [INFO] [respond.stage:169]: Prepare to send - Kyy008/3149972098: [引用消息] [2026-02-21 03:57:45.499] [Core] [WARN] [v4.17.5] [respond.stage:226]: 实际消息链为空, 跳过发送阶段。header_chain: [Reply(type=<ComponentType.Reply: 'Reply'>, id='1449790358', chain=[], sender_id=0, sender_nickname='', time=0, message_str='', text='', qq=0, seq=0)], actual_chain: [] [2026-02-21 03:57:45.499] [Core] [INFO] [runners.tool_loop_agent_runner:532]: Agent 使用工具: ['send_message_to_user'] [2026-02-21 03:57:45.500] [Core] [INFO] [runners.tool_loop_agent_runner:569]: 使用工具:send_message_to_user,参数:{'messages': [{'type': 'plain', 'text': '这是 y=x 的函数图像。这是一个简单的线性函数,斜率为1,通过原点(0,0)。'}, {'type': 'image', 'path': '/AstrBot/data/temp/sandbox_dee2_y_equals_x.png'}]} [2026-02-21 03:57:45.500] [Core] [INFO] [runners.tool_loop_agent_runner:774]: Tool send_message_to_user Result: Message sent to session Chino_Bot:GroupMessage:966694930 [2026-02-21 03:57:47.189] [Plug] [INFO] [astrbot_plugin_meme_manager.main:637]: [meme_manager] 去重后的最终表情列表: [] [2026-02-21 03:57:47.194] [Core] [INFO] [respond.stage:169]: Prepare to send - Kyy008/3149972098: [引用消息] 图像已经绘制完成并发送给您了。 这是一个简单的线性函数,斜率为1,通过原点,在坐标系中是一条45度的直线。 如果您需要其他函数的图像,或者想要调整图像的范围、样式等,我也可以帮您修改。 [2026-02-21 04:00:33.451] [Core] [INFO] [routes.config:214]: Saving config, is_core=True [2026-02-21 04:00:33.453] [Core] [INFO] [respond.stage:74]: 分段回复间隔时间:[1.5, 3.5] [2026-02-21 04:01:55.540] [Core] [INFO] [core.event_bus:59]: [default] [Chino_Bot(aiocqhttp)] Kyy008/3149972098: 画一个y=x的函数图像并发送给我 [2026-02-21 04:02:02.716] [Core] [INFO] [respond.stage:169]: Prepare to send - Kyy008/3149972098: [引用消息] 我来为您绘制 y = x 的函数图像。 首先创建一个Python脚本来生成这个图像。 [2026-02-21 04:02:07.669] [Core] [INFO] [runners.tool_loop_agent_runner:532]: Agent 使用工具: ['astrbot_execute_ipython'] [2026-02-21 04:02:07.669] [Core] [INFO] [runners.tool_loop_agent_runner:569]: 使用工具:astrbot_execute_ipython,参数:{'code': 'import numpy as np\nimport matplotlib.pyplot as plt\n\n# 设置中文字体支持\nplt.rcParams['font.sans-serif'] = ['SimHei', 'Arial Unicode MS', 'DejaVu Sans']\nplt.rcParams['axes.unicode_minus'] = False\n\n# 创建x值范围\nx = np.linspace(-10, 10, 400)\ny = x\n\n# 创建图形\nplt.figure(figsize=(8, 6))\nplt.plot(x, y, 'b-', linewidth=2, label='y = x')\n\n# 添加坐标轴\nplt.axhline(y=0, color='k', linewidth=0.5)\nplt.axvline(x=0, color='k', linewidth=0.5)\n\n# 设置图形属性\nplt.title('函数图像: y = x', fontsize=14)\nplt.xlabel('x', fontsize=12)\nplt.ylabel('y', fontsize=12)\nplt.grid(True, alpha=0.3)\nplt.legend()\nplt.axis('equal')\nplt.xlim(-10, 10)\nplt.ylim(-10, 10)\n\n# 保存图像\nplt.tight_layout()\nplt.savefig('y_equals_x.png', dpi=150, bbox_inches='tight')\nprint("图像已保存为 y_equals_x.png")'} [2026-02-21 04:02:10.032] [Core] [INFO] [booters.shipyard:30]: Got sandbox ship: 0d2552b9-e325-4049-918c-9c29c21ede02 for session: 3c949866850a58a3ab66eb8674e655d0 [2026-02-21 04:02:12.747] [Core] [INFO] [runners.tool_loop_agent_runner:774]: Tool astrbot_execute_ipython Result: Image returned and cached at path='/AstrBot/data/temp/tool_images/call_00_rfe4nYVGAddYmmUVeyRPguFE_0.png'. Review the image below. Use send_message_to_user to send it to the user if satisfied, with type='image' and path='/AstrBot/data/temp/tool_images/call_00_rfe4nYVGAddYmmUVeyRPguFE_0.png'. [2026-02-21 04:02:16.026] [Core] [INFO] [respond.stage:169]: Prepare to send - Kyy008/3149972098: [引用消息] 图像已经生成好了。 现在我将把图像发送给您。 [2026-02-21 04:02:21.417] [Core] [INFO] [runners.tool_loop_agent_runner:532]: Agent 使用工具: ['send_message_to_user'] [2026-02-21 04:02:21.418] [Core] [INFO] [runners.tool_loop_agent_runner:569]: 使用工具:send_message_to_user,参数:{'messages': [{'type': 'plain', 'text': '这是 y = x 的函数图像。这是一个简单的线性函数,图像是一条通过原点的45度直线。'}, {'type': 'image', 'path': '/AstrBot/data/temp/tool_images/call_00_rfe4nYVGAddYmmUVeyRPguFE_0.png'}]} [2026-02-21 04:02:21.421] [Core] [INFO] [runners.tool_loop_agent_runner:774]: Tool send_message_to_user Result: Message sent to session Chino_Bot:FriendMessage:3149972098 [2026-02-21 04:02:23.419] [Plug] [INFO] [astrbot_plugin_meme_manager.main:637]: [meme_manager] 去重后的最终表情列表: [] [2026-02-21 04:02:23.423] [Core] [INFO] [respond.stage:169]: Prepare to send - Kyy008/3149972098: [引用消息] 图像已经发送给您了。 这是一个标准的线性函数图像,斜率为1,截距为0,所以它正好通过原点并且与x轴和y轴都成45度角。 如果您需要其他函数的图像,或者想要调整图像的范围、样式等,请告诉我。

Image

Are you willing to submit a PR? / 你愿意提交 PR 吗?

  • [ ] Yes!

Code of Conduct

Kyy008 avatar Feb 20 '26 20:02 Kyy008

Hi @Kyy008! I'm Dosu and I’m helping the AstrBot team.

这是一个已知问题。send_message_to_user 工具在发送图片到 QQ 平台时存在缺陷。

根本原因:当 LLM 使用 send_message_to_user 发送图片时,消息链在校验阶段发现图片组件的 file 字段为空,被判定为无效组件,导致实际消息链为空并跳过发送。ChatUI 能显示是因为它不依赖完整的平台发送流程。

相关 Issue:#4951 已报告类似问题 - 用户无法通过 send_message_to_user 成功发送文件。

临时解决方案:如果是插件开发者,可使用 await event.send(chain) 方法替代:

import astrbot.api.message_components as Comp
from astrbot.api.event import MessageChain

chain = MessageChain(chain=[
    Comp.Plain("已生成图片!"),
    Comp.Image.fromFileSystem(str(img_path))
])
await event.send(chain)

建议关注或在 #4951 补充此场景信息,以帮助开发者定位修复。

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about AstrBot with Dosu Add Dosu to your team

dosubot[bot] avatar Feb 20 '26 20:02 dosubot[bot]

暂时没法复现,最新版本也是这样吗

Clhikari avatar Feb 21 '26 10:02 Clhikari

最新的 4.18.1 有这个问题吗?

Image

有配置过这个吗

Soulter avatar Feb 24 '26 14:02 Soulter

之前已经询问过新版本是否仍能复现,但一直没有收到进一步反馈。 考虑到这个 Issue 已经很久没有更新,目前也缺少足够的信息继续定位,这里就先关闭了。 如果最新版本中仍然存在这个问题,欢迎带上新的日志和复现步骤重新提交。感谢反馈! We previously asked whether this could still be reproduced on newer versions, but haven't received any further updates. Since this issue has been inactive for quite some time and we don't have enough information to investigate further, I'll close it for now. If the problem still occurs on the latest version, feel free to open a new issue with updated logs and reproduction steps. Thanks for the report!

anka-afk avatar Oct 15 '26 11:10 anka-afk