不要将历史记录放在末尾

pull/1186/head
Windpicker-owo 2025-08-18 12:25:42 +08:00
parent 887d5bfd8b
commit a141e2605c
1 changed files with 18 additions and 2 deletions

View File

@ -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