feat: 插件内存管理 - TTL自动淘汰 + 懒加载

新增 plugin_memory_manager.py:
- 后台线程定期扫描空闲插件,超过TTL自动从内存卸载
- AI调用已卸载插件时自动重新加载(懒加载)
- 核心插件(tool_search)可钉住永不淘汰
- 可配置: TTL(300s), 最大空闲数(10), 扫描间隔(60s), 钉住列表

改造 unified_tool_manager.py:
- 集成 PluginMemoryManager
- execute/mcp_call/search_tools/get_tool 统一走 _ensure_loaded
- search_tools 可搜索已卸载插件(使用缓存信息)
- 新增 get_all_tools_info/get_tool_by_name/memory_manager 属性

改造 tui.py:
- /status 命令显示内存管理详细状态
- 侧栏显示已加载/已卸载工具数
This commit is contained in:
OpenClaw committed 2026-05-08 00:40:01 +08:00
1 parent 038fbe24c8
commit fb41c79b14
4 files changed
+761 -74

No files matched your search

+20 -5
View File
@@ -562,6 +562,14 @@ if TEXTUAL_AVAILABLE:
status_container.mount(Static(f" 工具: {len(self.bridge.tools())} 个", classes="tool-item"))
status_container.mount(Static(f" 引擎: {len(self.bridge.engines())} 个", classes="tool-item"))
# 内存管理状态
if hasattr(self.cli, 'liugin_manager') and hasattr(self.cli.liugin_manager, 'memory_manager'):
mgr = self.cli.liugin_manager.memory_manager
s = mgr.get_status()
status_container.mount(Static(f" 已加载: {s['loaded']}", classes="tool-item"))
if s['unloaded'] > 0:
status_container.mount(Static(f" 已卸载: {s['unloaded']}", classes="tool-item"))
def _update_status(self, text: str):
bar = self.query_one("#status-bar")
engine = self.bridge.current_engine()
@@ -807,11 +815,18 @@ if TEXTUAL_AVAILABLE:
self._system('\n'.join(lines))
def _show_status(self):
self._system(f""" 系统状态:
引擎: {self.bridge.current_engine()}
引擎数: {len(self.bridge.engines())}
工具数: {len(self.bridge.tools())}
对话数: {len(self.bridge.history())}""")
status_lines = [
f" 系统状态:",
f" 引擎: {self.bridge.current_engine()}",
f" 引擎数: {len(self.bridge.engines())}",
f" 工具数: {len(self.bridge.tools())}",
f" 对话数: {len(self.bridge.history())}",
]
# 内存管理状态
if hasattr(self.cli, 'liugin_manager') and hasattr(self.cli.liugin_manager, 'memory_manager'):
mgr = self.cli.liugin_manager.memory_manager
status_lines.append(mgr.format_status())
self._system('\n'.join(status_lines))
# ── AI 生成 ──