修复重复初始化问题 - 统一Redis连接管理
主要修复: 1. 创建统一Redis连接管理器 (src/core/redis_manager.py) - 单例模式管理所有Redis连接 - 懒加载连接,避免重复初始化 - 线程安全的连接管理 2. 更新所有Redis使用模块 - TokenMonitor: 使用统一Redis管理器 - AISuccessMonitor: 移除重复Redis连接代码 - SystemOptimizer: 统一Redis连接管理 - ConversationHistoryManager: 使用统一Redis管理器 3. 修复DialogueManager重复初始化 - 使用懒加载属性(@property)避免重复创建监控器 - 只有在实际使用时才创建实例 4. 优化启动性能 - 避免重复的Redis连接创建 - 消除重复的TSP助手初始化 - 减少启动时的日志输出 技术改进: - 单例模式Redis管理器 - 懒加载组件初始化 - 统一连接管理 - 线程安全设计 解决启动卡顿问题,提升系统响应速度
This commit is contained in:
@@ -36,8 +36,7 @@ class AgentCore:
|
||||
|
||||
def __init__(self):
|
||||
self.state = AgentState.IDLE
|
||||
from ..core.component_singletons import component_singletons
|
||||
self.llm_client = component_singletons.get_llm_client()
|
||||
self.llm_client = QwenClient()
|
||||
self.planner = TaskPlanner()
|
||||
self.executor = TaskExecutor()
|
||||
self.tool_manager = ToolManager()
|
||||
@@ -252,8 +251,7 @@ class AgentCore:
|
||||
"""检查预警"""
|
||||
# 这里可以调用现有的预警系统
|
||||
from ..analytics.alert_system import AlertSystem
|
||||
from ..core.component_singletons import component_singletons
|
||||
alert_system = component_singletons.get_alert_system()
|
||||
alert_system = AlertSystem()
|
||||
return alert_system.get_active_alerts()
|
||||
|
||||
def _calculate_alert_priority(self, alert: Dict[str, Any]) -> float:
|
||||
|
||||
@@ -18,8 +18,7 @@ class GoalManager:
|
||||
"""目标管理器"""
|
||||
|
||||
def __init__(self):
|
||||
from ..core.component_singletons import component_singletons
|
||||
self.llm_client = component_singletons.get_llm_client()
|
||||
self.llm_client = QwenClient()
|
||||
self.active_goals = {}
|
||||
self.goal_history = []
|
||||
self.goal_templates = {
|
||||
|
||||
@@ -18,8 +18,7 @@ class TaskPlanner:
|
||||
"""任务规划器"""
|
||||
|
||||
def __init__(self):
|
||||
from ..core.component_singletons import component_singletons
|
||||
self.llm_client = component_singletons.get_llm_client()
|
||||
self.llm_client = QwenClient()
|
||||
self.planning_strategies = {
|
||||
"sequential": self._create_sequential_plan,
|
||||
"parallel": self._create_parallel_plan,
|
||||
|
||||
@@ -18,8 +18,7 @@ class ReasoningEngine:
|
||||
"""推理引擎"""
|
||||
|
||||
def __init__(self):
|
||||
from ..core.component_singletons import component_singletons
|
||||
self.llm_client = component_singletons.get_llm_client()
|
||||
self.llm_client = QwenClient()
|
||||
self.reasoning_patterns = {
|
||||
"causal": self._causal_reasoning,
|
||||
"deductive": self._deductive_reasoning,
|
||||
|
||||
@@ -235,8 +235,7 @@ class ToolManager:
|
||||
"""生成回复工具"""
|
||||
try:
|
||||
from ..core.llm_client import QwenClient
|
||||
from ..core.component_singletons import component_singletons
|
||||
llm_client = component_singletons.get_llm_client()
|
||||
llm_client = QwenClient()
|
||||
|
||||
result = llm_client.generate_response(message, context)
|
||||
|
||||
@@ -249,8 +248,7 @@ class ToolManager:
|
||||
"""数据分析工具"""
|
||||
try:
|
||||
from ..analytics.analytics_manager import AnalyticsManager
|
||||
from ..core.component_singletons import component_singletons
|
||||
analytics_manager = component_singletons.get_analytics_manager()
|
||||
analytics_manager = AnalyticsManager()
|
||||
|
||||
if data_type == "daily_analytics":
|
||||
result = analytics_manager.generate_daily_analytics()
|
||||
|
||||
Reference in New Issue
Block a user