fix: 修复 'ToolResult' object has no attribute 'get'

根因: cli_tools.process_tool_call 在启用 UnifiedToolManager 时直接返回
ToolResult 对象,而 7 个调用点全部按 dict 用 result.get('result'),触发
AttributeError;FC 路径 _execute_tool_by_name 也可能把 ToolResult 透传出去,
后续 result[:5000] 会再炸 TypeError。

- tool_result.py: 新增 normalize_tool_text / normalize_tool_dict,
  统一收敛 ToolResult / dict / str / None 三种历史返回形态。
- cli_tools.process_tool_call: 统一返回 dict(附带 success/error_code/
  tool_result),回退 handler 路径同样归一。
- cli_core._execute_tool_by_name: handler / memory / scheduler 返回值
  归一成 str,保证 FC 路径可安全切片。
- openai/ollama/manual 引擎、websocket_server、cli_clawli: 取工具结果改用
  normalize_tool_text(带本地兜底实现,避免循环导入)。
- cli_clawli: 顺带修复只回传最后一个工具结果的 bug,改为汇总全部。
- 测试: 23 项全过;纯格式/讯飞 500 降级回归冒烟通过。
This commit is contained in:
shuiyu67 committed 2026-08-05 10:54:39 +08:00
1 parent dfc42d8583
commit a63b9d2f97
8 files changed
+129 -20

No files matched your search

+6 -2
View File
@@ -3,6 +3,7 @@ import time
from colorama import Fore, Style
from .constants import CLAWLI_SERVER_AVAILABLE, WEBSOCKET_AVAILABLE
from .tool_result import normalize_tool_text
try:
import clawli_server
@@ -96,6 +97,7 @@ class ClawliMixin:
tool_calls = self._extract_tool_calls(json_data)
if tool_calls:
result_texts = []
for tool_data in tool_calls:
tool_name = tool_data.get('tool', '未知工具')
tool_args = tool_data.get('args', '')
@@ -104,7 +106,8 @@ class ClawliMixin:
clawli_server.send_tool_status(tool_name, tool_args, "calling")
result = self.process_tool_call(tool_data)
result_text = result.get('result', '无结果')
result_text = normalize_tool_text(result)
result_texts.append(result_text)
if CLAWLI_SERVER_AVAILABLE and clawli_server:
clawli_server.send_tool_status(tool_name, tool_args, "success", result_text)
@@ -114,7 +117,8 @@ class ClawliMixin:
"content": response
})
tool_result_str = "\n".join([f"工具执行结果: {r}" for r in [result.get('result', '')]])
# 汇总全部工具结果(此前只回传了最后一个)
tool_result_str = "\n".join([f"工具执行结果: {r}" for r in result_texts])
self._process_clawli_user_message(f"{tool_result_str}\n请根据工具执行结果继续回答。")
return