初始化多智能体系统 Args: config_path: 配置文件路径
(self, config_path: str = "config/config.yaml")
| 33 | """多智能体系统 - 主入口类""" |
| 34 | |
| 35 | def __init__(self, config_path: str = "config/config.yaml"): |
| 36 | """初始化多智能体系统 |
| 37 | |
| 38 | Args: |
| 39 | config_path: 配置文件路径 |
| 40 | """ |
| 41 | self.config = self._load_config(config_path) |
| 42 | self.llm = self._init_llm() |
| 43 | self.db_path = self.config["database"]["path"] |
| 44 | |
| 45 | # 记忆配置 |
| 46 | memory_config = self.config.get("memory", {}) |
| 47 | memory_db_path = memory_config.get("long_term_db", "./data/long_term_memory.db") |
| 48 | short_term_max_tokens = memory_config.get("short_term_max_tokens", 1000) |
| 49 | |
| 50 | # 联网搜索配置 |
| 51 | search_config = self.config.get("search", {}) |
| 52 | tavily_api_key = search_config.get("tavily_api_key", "") |
| 53 | |
| 54 | # 初始化主智能体(内部会初始化三个子智能体:SQL、Analysis、Search) |
| 55 | self.master_agent = MasterAgent( |
| 56 | llm=self.llm, |
| 57 | db_path=self.db_path, |
| 58 | num_examples=self.config["nl2sql"]["num_examples"], |
| 59 | memory_db_path=memory_db_path, |
| 60 | short_term_max_tokens=short_term_max_tokens, |
| 61 | tavily_api_key=tavily_api_key |
| 62 | ) |
| 63 | |
| 64 | # 用户登录状态 |
| 65 | self.user_id = None # 当前登录用户 |
| 66 | self.session_id = None # 当前会话ID |
| 67 | |
| 68 | def _load_config(self, config_path: str) -> Dict[str, Any]: |
| 69 | """加载配置文件""" |
nothing calls this directly
no test coverage detected