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
-4
@@ -812,7 +812,13 @@ multi 操作支持一次修改多处:
|
||||
return None
|
||||
|
||||
def _execute_tool_by_name(self, tool_name: str, tool_args: str) -> str:
|
||||
"""根据名称执行工具(FC 调用路径)"""
|
||||
"""根据名称执行工具(FC 调用路径)
|
||||
|
||||
注意:插件 handler 可能返回 ToolResult / dict / str,
|
||||
这里统一归一成 str,保证调用方能安全做切片与拼接。
|
||||
"""
|
||||
from .tool_result import normalize_tool_text
|
||||
|
||||
# 安全检查
|
||||
safety = get_safety()
|
||||
allowed, msg = safety.check(tool_name, tool_args)
|
||||
@@ -823,20 +829,20 @@ multi 操作支持一次修改多处:
|
||||
tool = self.liugin_manager.get_tool_by_name(tool_name)
|
||||
if tool and 'handler' in tool:
|
||||
try:
|
||||
return tool['handler'](tool_args)
|
||||
return normalize_tool_text(tool['handler'](tool_args), default="执行完成")
|
||||
except Exception as e:
|
||||
return f"工具执行失败: {e}"
|
||||
|
||||
# memory 内置工具
|
||||
if tool_name == 'memory' and hasattr(self, 'memory_manager'):
|
||||
return self.memory_manager.handle_tool(tool_args)
|
||||
return normalize_tool_text(self.memory_manager.handle_tool(tool_args), default="执行完成")
|
||||
|
||||
# scheduler 内置工具
|
||||
if tool_name == 'scheduler':
|
||||
for t in self.liugin_manager.tools:
|
||||
if t.get('name') == 'scheduler' and 'handler' in t:
|
||||
try:
|
||||
return t['handler'](tool_args)
|
||||
return normalize_tool_text(t['handler'](tool_args), default="执行完成")
|
||||
except Exception as e:
|
||||
return f"工具执行失败: {e}"
|
||||
|
||||
|
||||
Reference in new issue
Block a user