fix: 增强系统健壮性,优化核心组件的错误处理
在多个核心模块中增加了前置检查和更详细的错误处理逻辑,以防止因组件初始化失败或外部数据格式不符预期而导致的运行时崩溃。 主要变更: - **记忆系统:** 在执行记忆构建、融合和价值评估前,增加对相关引擎是否初始化的检查。优化了向量数据库初始化失败时的处理流程,并增强了向量搜索结果的解析安全性。 - **插件系统:** 统一并优化了LLM可用工具定义的获取方式,增加了错误捕获。调整了工具执行器以安全地解析LLM返回的工具调用请求。 - **向量数据库:** 当ChromaDB连接失败时,显式抛出 `ConnectionError`,使上层调用者能更好地捕获和处理该特定问题。
This commit is contained in:
@@ -113,10 +113,14 @@ class ToolExecutor:
|
||||
logger.debug(f"{self.log_prefix}开始LLM工具调用分析")
|
||||
|
||||
# 调用LLM进行工具决策
|
||||
response, (reasoning_content, model_name, tool_calls) = await self.llm_model.generate_response_async(
|
||||
response, llm_extra_info = await self.llm_model.generate_response_async(
|
||||
prompt=prompt, tools=tools, raise_when_empty=False
|
||||
)
|
||||
|
||||
tool_calls = None
|
||||
if llm_extra_info and isinstance(llm_extra_info, tuple) and len(llm_extra_info) == 3:
|
||||
_, _, tool_calls = llm_extra_info
|
||||
|
||||
# 执行工具调用
|
||||
tool_results, used_tools = await self.execute_tool_calls(tool_calls)
|
||||
|
||||
@@ -133,7 +137,9 @@ class ToolExecutor:
|
||||
user_disabled_tools = global_announcement_manager.get_disabled_chat_tools(self.chat_id)
|
||||
|
||||
# 获取基础工具定义(包括二步工具的第一步)
|
||||
tool_definitions = [definition for name, definition in all_tools if name not in user_disabled_tools]
|
||||
tool_definitions = [
|
||||
definition for definition in all_tools if definition.get("function", {}).get("name") not in user_disabled_tools
|
||||
]
|
||||
|
||||
# 检查是否有待处理的二步工具第二步调用
|
||||
pending_step_two = getattr(self, "_pending_step_two_tools", {})
|
||||
@@ -282,20 +288,7 @@ class ToolExecutor:
|
||||
)
|
||||
|
||||
# 检查是否是MCP工具
|
||||
try:
|
||||
from src.plugin_system.utils.mcp_tool_provider import mcp_tool_provider
|
||||
if function_name in mcp_tool_provider.mcp_tools:
|
||||
logger.info(f"{self.log_prefix}执行MCP工具: {function_name}")
|
||||
result = await mcp_tool_provider.call_mcp_tool(function_name, function_args)
|
||||
return {
|
||||
"tool_call_id": tool_call.call_id,
|
||||
"role": "tool",
|
||||
"name": function_name,
|
||||
"type": "function",
|
||||
"content": result.get("content", ""),
|
||||
}
|
||||
except Exception as e:
|
||||
logger.debug(f"检查MCP工具时出错: {e}")
|
||||
pass
|
||||
|
||||
function_args["llm_called"] = True # 标记为LLM调用
|
||||
|
||||
|
||||
Reference in New Issue
Block a user