From 2a1e785a666157f6d599fdd37ff31fcb841275ba Mon Sep 17 00:00:00 2001 From: Windpicker-owo <3431391539@qq.com> Date: Tue, 19 Aug 2025 13:48:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=E8=BF=87=E6=9C=9F=E7=9A=84?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/tool_history.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/common/tool_history.py b/src/common/tool_history.py index dd873c9e..e6be7547 100644 --- a/src/common/tool_history.py +++ b/src/common/tool_history.py @@ -51,8 +51,15 @@ class ToolHistoryManager: def _clean_expired_records(self): """清理已过期的记录""" + original_count = len(self._history) self._history = [record for record in self._history if record.get("ttl_count", 0) < record.get("ttl", 5)] - self._save_history() + cleaned_count = original_count - len(self._history) + + if cleaned_count > 0: + logger.info(f"清理了 {cleaned_count} 条过期的工具历史记录,剩余 {len(self._history)} 条") + self._save_history() + else: + logger.debug("没有需要清理的过期工具历史记录") def record_tool_call(self, tool_name: str, @@ -77,6 +84,9 @@ class ToolHistoryManager: if not global_config.tool.history.enable_history or ttl <= 0: return + # 先清理过期记录 + self._clean_expired_records() + try: # 创建记录 record = { @@ -190,6 +200,8 @@ class ToolHistoryManager: Returns: 符合条件的历史记录列表 """ + # 先清理过期记录 + self._clean_expired_records() def _parse_time(time_str: Optional[Union[datetime, str]]) -> Optional[datetime]: if isinstance(time_str, datetime): return time_str