fix: 修复 context_rewrite 工具调用问题并优化系统提示词
1. 修复 context_rewrite 导致的 API 错误 - 删除错误的 tool 结果消息添加逻辑 - 添加 context_compressed 标记让 AI 识别压缩结果 - 将 context_rewrite 记录到 tool_calls 以便 TUI 显示 2. 优化系统提示词 - 添加强制触发条件:每5次记忆工具调用必须调用 context_rewrite - 强化指代词处理规则:必须通过工作记忆链解析 - 扩展时间指代词:添加刚刚 - 更新执行检查清单 Generated with CodeArts Agent
This commit is contained in:
@ -243,19 +243,23 @@ class BackendServer:
|
||||
result = execute_tool(self._graph, tool_call.function.name, args)
|
||||
result_data = json.loads(result)
|
||||
|
||||
# 记录到 tool_calls,让 TUI 显示这个工具调用
|
||||
tool_calls.append({
|
||||
"name": tool_call.function.name,
|
||||
"arguments": args,
|
||||
"result": result
|
||||
})
|
||||
|
||||
if result_data.get("status") == "success":
|
||||
user_msg = messages_history[0]
|
||||
# 添加特殊标记,让 AI 知道这是上下文压缩的结果
|
||||
compressed_content = f"<context_compressed>\n{result_data['summary']}\n</context_compressed>"
|
||||
messages_history[:] = [
|
||||
user_msg,
|
||||
{"role": "assistant", "content": result_data["summary"]}
|
||||
{"role": "assistant", "content": compressed_content}
|
||||
]
|
||||
|
||||
tool_result_msg = {
|
||||
"role": "tool",
|
||||
"tool_call_id": tool_call.id,
|
||||
"content": result
|
||||
}
|
||||
current_tool_results.append(tool_result_msg)
|
||||
# context_rewrite 压缩上下文后,不需要添加 tool 结果消息
|
||||
# 因为 messages_history 已经被重写为压缩后的状态
|
||||
continue
|
||||
|
||||
result = execute_tool(self._graph, tool_call.function.name, args)
|
||||
|
||||
Reference in New Issue
Block a user