From 11282c769f93e53a02f4f33e2e14e9da899385ad Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Tue, 7 Apr 2026 21:32:11 +0800 Subject: [PATCH] feat: enhance tool prompt formatting and add escaped text decoding for file editing --- astrbot/core/astr_main_agent.py | 2 +- astrbot/core/computer/tools/fs.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/astrbot/core/astr_main_agent.py b/astrbot/core/astr_main_agent.py index 5de8f38d4..18383394f 100644 --- a/astrbot/core/astr_main_agent.py +++ b/astrbot/core/astr_main_agent.py @@ -1350,7 +1350,7 @@ async def build_main_agent( ) if config.computer_use_runtime == "local": - tool_prompt += f"Current workspace you can use: `{os.path.join(get_astrbot_workspaces_path(), event.unified_msg_origin)}`\n" + tool_prompt += f"\nCurrent workspace you can use: `{os.path.join(get_astrbot_workspaces_path(), event.unified_msg_origin)}`\n" req.system_prompt += f"\n{tool_prompt}\n" diff --git a/astrbot/core/computer/tools/fs.py b/astrbot/core/computer/tools/fs.py index 18940769c..0d21d0d68 100644 --- a/astrbot/core/computer/tools/fs.py +++ b/astrbot/core/computer/tools/fs.py @@ -151,6 +151,16 @@ def _normalize_rw_path( return normalized_path +def _decode_escaped_text(value: str) -> str: + """Decode common escaped control sequences used in tool arguments.""" + return ( + value.replace("\\r\\n", "\n") + .replace("\\n", "\n") + .replace("\\r", "\r") + .replace("\\t", "\t") + ) + + @dataclass class FileReadTool(FunctionTool): name: str = "astrbot_file_read_tool" @@ -359,14 +369,16 @@ class FileEditTool(FunctionTool): ) if not normalized_path: raise ValueError("`path` must be a non-empty string.") + normalized_old = _decode_escaped_text(old) + normalized_new = _decode_escaped_text(new) sb = await get_booter( context.context.context, context.context.event.unified_msg_origin, ) result = await sb.fs.edit_file( path=normalized_path, - old_string=old, - new_string=new, + old_string=normalized_old, + new_string=normalized_new, replace_all=replace_all, encoding="utf-8", )