From a141e2605c46740d42b35a531cd11f03fe3a2caf Mon Sep 17 00:00:00 2001 From: Windpicker-owo <3431391539@qq.com> Date: Mon, 18 Aug 2025 12:25:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E5=B0=86=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=94=BE=E5=9C=A8=E6=9C=AB=E5=B0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chat/utils/prompt_builder.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/chat/utils/prompt_builder.py b/src/chat/utils/prompt_builder.py index ca94d542..3f725453 100644 --- a/src/chat/utils/prompt_builder.py +++ b/src/chat/utils/prompt_builder.py @@ -169,10 +169,26 @@ class PromptManager: if name in ['action_prompt', 'replyer_prompt', 'planner_prompt', 'tool_executor_prompt']: tool_history = get_tool_history_prompt(message_id) - # 如果有工具历史,添加到提示词末尾 + # 获取基本格式化结果 result = prompt.format(**kwargs) + + # 如果有工具历史,插入到适当位置 if tool_history: - result = f"{result}\n\n{tool_history}" + # 查找合适的插入点 + # 在人格信息和身份块之后,但在主要内容之前 + identity_end = result.find("```\n现在,你说:") + if identity_end == -1: + # 如果找不到特定标记,尝试在第一个段落后插入 + first_double_newline = result.find("\n\n") + if first_double_newline != -1: + # 在第一个双换行后插入 + result = f"{result[:first_double_newline + 2]}{tool_history}\n{result[first_double_newline + 2:]}" + else: + # 如果找不到合适的位置,添加到开头 + result = f"{tool_history}\n\n{result}" + else: + # 在找到的位置插入 + result = f"{result[:identity_end]}\n{tool_history}\n{result[identity_end:]}" return result