fix: 增强系统健壮性,优化核心组件的错误处理
在多个核心模块中增加了前置检查和更详细的错误处理逻辑,以防止因组件初始化失败或外部数据格式不符预期而导致的运行时崩溃。 主要变更: - **记忆系统:** 在执行记忆构建、融合和价值评估前,增加对相关引擎是否初始化的检查。优化了向量数据库初始化失败时的处理流程,并增强了向量搜索结果的解析安全性。 - **插件系统:** 统一并优化了LLM可用工具定义的获取方式,增加了错误捕获。调整了工具执行器以安全地解析LLM返回的工具调用请求。 - **向量数据库:** 当ChromaDB连接失败时,显式抛出 `ConnectionError`,使上层调用者能更好地捕获和处理该特定问题。
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from typing import Any
|
||||
from src.common.logger import get_logger
|
||||
from src.plugin_system.base.base_tool import BaseTool
|
||||
from src.plugin_system.base.component_types import ComponentType
|
||||
@@ -20,13 +21,22 @@ def get_tool_instance(tool_name: str) -> BaseTool | None:
|
||||
return tool_class(plugin_config) if tool_class else None
|
||||
|
||||
|
||||
def get_llm_available_tool_definitions():
|
||||
def get_llm_available_tool_definitions() -> list[dict[str, Any]]:
|
||||
"""获取LLM可用的工具定义列表
|
||||
|
||||
Returns:
|
||||
List[Tuple[str, Dict[str, Any]]]: 工具定义列表,为[("tool_name", 定义)]
|
||||
list[dict[str, Any]]: 工具定义列表
|
||||
"""
|
||||
from src.plugin_system.core import component_registry
|
||||
|
||||
llm_available_tools = component_registry.get_llm_available_tools()
|
||||
tool_definitions = []
|
||||
for tool_name, tool_class in llm_available_tools.items():
|
||||
try:
|
||||
# 调用类方法 get_tool_definition 获取定义
|
||||
definition = tool_class.get_tool_definition()
|
||||
tool_definitions.append(definition)
|
||||
except Exception as e:
|
||||
logger.error(f"获取工具 {tool_name} 的定义失败: {e}")
|
||||
return tool_definitions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user