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:
1 parent
dfc42d8583
commit
a63b9d2f97
8 files changed
+129
-20
No files matched your search
+10
-9
@@ -7,6 +7,7 @@ from colorama import Fore, Style
|
||||
|
||||
from .constants import UNIFIED_TOOL_MANAGER_AVAILABLE
|
||||
from .safety import get_safety
|
||||
from .tool_result import normalize_tool_dict, normalize_tool_text
|
||||
|
||||
|
||||
class ToolMixin:
|
||||
@@ -105,18 +106,18 @@ class ToolMixin:
|
||||
result = self.liugin_manager.execute(tool_name, args, **arguments)
|
||||
else:
|
||||
result = self.liugin_manager.execute(tool_name, args)
|
||||
return result
|
||||
# execute() 返回 ToolResult,必须归一成 dict——
|
||||
# 否则上层 result.get('result') 会报
|
||||
# "'ToolResult' object has no attribute 'get'"
|
||||
return normalize_tool_dict(result)
|
||||
|
||||
# 回退:直接调用 handler(旧逻辑)
|
||||
# 回退:直接调用 handler(旧逻辑,handler 可能返回 ToolResult/str)
|
||||
for tool in self.liugin_manager.tools:
|
||||
if tool['name'] == tool_name:
|
||||
try:
|
||||
result = tool['handler'](args)
|
||||
if result is None:
|
||||
result = "无结果"
|
||||
return {"result": result}
|
||||
return normalize_tool_dict(tool['handler'](args))
|
||||
except Exception as e:
|
||||
return {"result": f"工具执行错误: {e}"}
|
||||
return {"result": f"工具执行错误: {e}", "success": False}
|
||||
|
||||
return {"result": f"未找到工具: {tool_name}"}
|
||||
|
||||
@@ -136,7 +137,7 @@ class ToolMixin:
|
||||
return {"index": index, "result": "工具执行已取消"}
|
||||
try:
|
||||
result = self.process_tool_call(tool_data)
|
||||
tool_result = result.get('result', '无结果')
|
||||
tool_result = normalize_tool_text(result)
|
||||
with history_lock:
|
||||
self.shared_conversation_history.append({
|
||||
"role": "assistant",
|
||||
@@ -245,7 +246,7 @@ class ToolMixin:
|
||||
pass
|
||||
|
||||
tool_results = self.process_tool_call(tool_data)
|
||||
full_result = tool_results.get('result', '无结果')
|
||||
full_result = normalize_tool_text(tool_results)
|
||||
from datetime import datetime
|
||||
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
self._display_tool_result(tool_name, tool_args, full_result, current_time)
|
||||
|
||||
Reference in new issue
Block a user