Skip to content

[Bug] 工具响应过长自动转换为文件,沙箱读取的文件出错 #8978

Description

@restyboy

What happened / 发生了什么

使用工具查询的数据过长自动转换为文件,在启用沙箱的情况下,读取报错,猜测:1、 文件没有上传至沙箱;2、 文件已上传,但是路径没有转换。

Reproduce / 如何复现?

  1. 使用沙箱模式,沙箱环境驱动为shipyard_neo;
  2. agent会话使用工具获取数据,且数据行数超600行;
  3. 数据自动写入文件,调用沙箱读取。

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

  • v4.9.2 docker
  • dsv4f
  • ghcr.io/astrbotdevs/shipyard-neo-bay:latest

OS

Linux

Logs / 报错日志

响应自动转换为文件日志:

Truncated tool output preview shown above. The tool output was too large to include directly and was written to `/tmp/.astrbot/call_3b70fca02a9848a686331776_23b19bd0.txt`. Use `astrbot_file_read_tool` to inspect it. Use a narrower window when reading large files.', 'tool_call_id': 'call_3b70fca02a9848a686331776'
Image

读取文件报错日志:

{'role': 'tool', 'content': 'error: \x1b[31m---------------------------------------------------------------------------\x1b[39m\n\x1b[31mFileNotFoundError\x1b[39m                         Traceback (most recent call last)\n\x1b[36mCell\x1b[39m\x1b[36m \x1b[39m\x1b[32mIn[5]\x1b[39m\x1b[32m, line 4\x1b[39m\n\x1b[32m      1\x1b[39m \x1b[38;5;28;01mimport\x1b[39;00m\x1b[38;5;250m \x1b[39m\x1b[34;01mjson\x1b[39;00m\n\x1b[32m      3\x1b[39m \x1b[38;5;66;03m# Read the raw data file\x1b[39;00m\n\x1b[32m----> \x1b[39m\x1b[32m4\x1b[39m \x1b[38;5;28;01mwith\x1b[39;00m \x1b[38;5;28;43mopen\x1b[39;49m\x1b[43m(\x1b[49m\x1b[33;43m\'\x1b[39;49m\x1b[33;43m/tmp/.astrbot/call_3b70fca02a9848a686331776_23b19bd0.txt\x1b[39;49m\x1b[33;43m\'\x1b[39;49m\x1b[43m,\x1b[49m\x1b[43m \x1b[49m\x1b[33;43m\'\x1b[39;49m\x1b[33;43mr\x1b[39;49m\x1b[33;43m\'\x1b[39;49m\x1b[43m)\x1b[49m \x1b[38;5;28;01mas\x1b[39;00m f:\n\x1b[32m      5\x1b[39m     raw_text = f.read()\n\x1b[32m      7\x1b[39m \x1b[38;5;66;03m# Parse the "data" array from the text\x1b[39;00m\n\x1b[32m      8\x1b[39m \x1b[38;5;66;03m# The data should be a list of dicts, let\'s extract the JSON\x1b[39;00m\n\n\x1b[36mFile \x1b[39m\x1b[32m/usr/local/lib/python3.13/site-packages/IPython/core/interactiveshell.py:343\x1b[39m, in \x1b[36m_modified_open\x1b[39m\x1b[34m(file, *args, **kwargs)\x1b[39m\n\x1b[32m    336\x1b[39m \x1b[38;5;28;01mif\x1b[39;00m file \x1b[38;5;129;01min\x1b[39;00m {\x1b[32m0\x1b[39m, \x1b[32m1\x1b[39m, \x1b[32m2\x1b[39m}:\n\x1b[32m    337\x1b[39m     \x1b[38;5;28;01mraise\x1b[39;00m \x1b[38;5;167;01mValueError\x1b[39;00m(\n\x1b[32m    338\x1b[39m         \x1b[33mf\x1b[39m\x1b[33m"\x1b[39m\x1b[33mIPython won\x1b[39m\x1b[33m\'\x1b[39m\x1b[33mt let you open fd=\x1b[39m\x1b[38;5;132;01m{\x1b[39;00mfile\x1b[38;5;132;01m}\x1b[39;00m\x1b[33m by default \x1b[39m\x1b[33m"\x1b[39m\n\x1b[32m    339\x1b[39m         \x1b[33m"\x1b[39m\x1b[33mas it is likely to crash IPython. If you know what you are doing, \x1b[39m\x1b[33m"\x1b[39m\n\x1b[32m    340\x1b[39m         \x1b[33m"\x1b[39m\x1b[33myou can use builtins\x1b[39m\x1b[33m\'\x1b[39m\x1b[33m open.\x1b[39m\x1b[33m"\x1b[39m\n\x1b[32m    341\x1b[39m     )\n\x1b[32m--> \x1b[39m\x1b[32m343\x1b[39m \x1b[38;5;28;01mreturn\x1b[39;00m \x1b[43mio_open\x1b[49m\x1b[43m(\x1b[49m\x1b[43mfile\x1b[49m\x1b[43m,\x1b[49m\x1b[43m \x1b[49m\x1b[43m*\x1b[49m\x1b[43margs\x1b[49m\x1b[43m,\x1b[49m\x1b[43m \x1b[49m\x1b[43m*\x1b[49m\x1b[43m*\x1b[49m\x1b[43mkwargs\x1b[49m\x1b[43m)\x1b[49m\n\n\x1b[31mFileNotFoundError\x1b[39m: [Errno 2] No such file or directory: \'/tmp/.astrbot/call_3b70fca02a9848a686331776_23b19bd0.txt\'', 'tool_call_id': 'call_c4965ab555e0479781bc6dfe'}, {'role': 'assistant', 'content': None, 'tool_calls': [{'type': 'function', 'id': 'call_2b276602d38142debd98f957', 'function': {'name': 'astrbot_file_read_tool', 'arguments': '{"path": "/tmp/.astrbot/call_3b70fca02a9848a686331776_23b19bd0.txt", "offset": 0, "limit": 20}'}}]}, {'role': 'tool', 'content': 'Error reading file: file probe failed: \x1b[31m---------------------------------------------------------------------------\x1b[39m\n\x1b[31mFileNotFoundError\x1b[39m                         Traceback (most recent call last)\n\x1b[36mCell\x1b[39m\x1b[36m \x1b[39m\x1b[32mIn[6]\x1b[39m\x1b[32m, line 6\x1b[39m\n\x1b[32m      3\x1b[39m \x1b[38;5;28;01mfrom\x1b[39;00m\x1b[38;5;250m \x1b[39m\x1b[34;01mpathlib\x1b[39;00m\x1b[38;5;250m \x1b[39m\x1b[38;5;28;01mimport\x1b[39;00m Path\n\x1b[32m      5\x1b[39m path = Path(\x1b[33m\'\x1b[39m\x1b[33m/tmp/.astrbot/call_3b70fca02a9848a686331776_23b19bd0.txt\x1b[39m\x1b[33m\'\x1b[39m)\n\x1b[32m----> \x1b[39m\x1b[32m6\x1b[39m \x1b[38;5;28;01mwith\x1b[39;00m \x1b[43mpath\x1b[49m\x1b[43m.\x1b[49m\x1b[43mopen\x1b[49m\x1b[43m(\x1b[49m\x1b[33;43m"\x1b[39;49m\x1b[33;43mrb\x1b[39;49m\x1b[33;43m"\x1b[39;49m\x1b[43m)\x1b[49m \x1b[38;5;28;01mas\x1b[39;00m file_obj:\n\x1b[32m      7\x1b[39m     sample = file_obj.read(\x1b[32m512\x1b[39m)\n\x1b[32m      8\x1b[39m \x1b[38;5;28mprint\x1b[39m(\n\x1b[32m      9\x1b[39m     json.dumps(\n\x1b[32m     10\x1b[39m         {\n\x1b[32m   (...)\x1b[39m\x1b[32m     14\x1b[39m     )\n\x1b[32m     15\x1b[39m )\n\n\x1b[36mFile \x1b[39m\x1b[32m/usr/local/lib/python3.13/pathlib/_local.py:537\x1b[39m, in \x1b[36mPath.open\x1b[39m\x1b[34m(self, mode, buffering, encoding, errors, newline)\x1b[39m\n\x1b[32m    535\x1b[39m \x1b[38;5;28;01mif\x1b[39;00m \x1b[33m"\x1b[39m\x1b[33mb\x1b[39m\x1b[33m"\x1b[39m \x1b[38;5;129;01mnot\x1b[39;00m \x1b[38;5;129;01min\x1b[39;00m mode:\n\x1b[32m    536\x1b[39m     encoding = io.text_encoding(encoding)\n\x1b[32m--> \x1b[39m\x1b[32m537\x1b[39m \x1b[38;5;28;01mreturn\x1b[39;00m \x1b[43mio\x1b[49m\x1b[43m.\x1b[49m\x1b[43mopen\x1b[49m\x1b[43m(\x1b[49m\x1b[38;5;28;43mself\x1b[39;49m\x1b[43m,\x1b[49m\x1b[43m \x1b[49m\x1b[43mmode\x1b[49m\x1b[43m,\x1b[49m\x1b[43m \x1b[49m\x1b[43mbuffering\x1b[49m\x1b[43m,\x1b[49m\x1b[43m \x1b[49m\x1b[43mencoding\x1b[49m\x1b[43m,\x1b[49m\x1b[43m \x1b[49m\x1b[43merrors\x1b[49m\x1b[43m,\x1b[49m\x1b[43m \x1b[49m\x1b[43mnewline\x1b[49m\x1b[43m)\x1b[49m\n\n\x1b[31mFileNotFoundError\x1b[39m: [Errno 2] No such file or directory: \'/tmp/.astrbot/call_3b70fca02a9848a686331776_23b19bd0.txt\'', 'tool_call_id': 'call_2b276602d38142debd98f957'}
Image

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

  • Yes!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreThe bug / feature is about astrbot's core, backendbugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions