From bddb5498e9435debe703b4cddb82c073e1788500 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 28 Apr 2026 19:59:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E9=99=90=E5=88=B6=20-=20=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E8=AE=B0=E5=BF=86=E9=93=BE=E4=BF=AE=E6=94=B920=E6=AC=A1/?= =?UTF-8?q?=E6=9F=A5=E8=AF=A230=E6=AC=A1=EF=BC=8C=E4=B8=80=E8=88=AC?= =?UTF-8?q?=E8=AE=B0=E5=BF=86=E6=9F=A5=E8=AF=A230=E6=AC=A1/=E4=BF=AE?= =?UTF-8?q?=E6=94=B915=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/tool_limiter.py | 27 +++++++++++++++++++++------ docs/zh/architecture.md | 7 ++++--- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/core/tool_limiter.py b/core/tool_limiter.py index 5bc9707..ec8516d 100644 --- a/core/tool_limiter.py +++ b/core/tool_limiter.py @@ -9,9 +9,10 @@ from dataclasses import dataclass class ToolLimits: """工具调用限制配置""" persona_update_max: int = 1 - task_update_max: int = 5 - memory_query_max: int = 20 - memory_update_max: int = 10 + task_update_max: int = 20 # 工作记忆链修改(create/set_state/delete/link_info) + task_query_max: int = 30 # 工作记忆链查询(memory_recall 查任务相关) + memory_query_max: int = 30 + memory_update_max: int = 15 @dataclass @@ -19,6 +20,7 @@ class ToolCallCount: """工具调用计数""" persona_update: int = 0 task_update: int = 0 + task_query: int = 0 memory_query: int = 0 memory_update: int = 0 @@ -44,6 +46,12 @@ class ToolLimiter: return ('task', 'update') if tool_name == 'memory_recall': + # 尝试区分工作记忆链查询 vs 一般记忆查询 + query = (arguments.get('queryIntent', '') + ' ' + ' '.join( + arguments.get('seedEntities', []))).strip().lower() + task_keywords = ['task', '任务', '工作记忆', '当前轮', '会话', '过程', '流程'] + if any(kw in query for kw in task_keywords): + return ('task', 'query') return ('memory', 'query') if tool_name == 'memory_commit': @@ -75,7 +83,10 @@ class ToolLimiter: return (False, f"人设图修改次数已达上限({self.limits.persona_update_max}次)") elif category == 'task': - if self.counts.task_update >= self.limits.task_update_max: + if operation == 'query': + if self.counts.task_query >= self.limits.task_query_max: + return (False, f"工作记忆链查询次数已达上限({self.limits.task_query_max}次)") + elif self.counts.task_update >= self.limits.task_update_max: return (False, f"工作记忆链修改次数已达上限({self.limits.task_update_max}次)") elif category == 'memory': @@ -96,7 +107,10 @@ class ToolLimiter: self.counts.persona_update += 1 elif category == 'task': - self.counts.task_update += 1 + if operation == 'query': + self.counts.task_query += 1 + else: + self.counts.task_update += 1 elif category == 'memory': if operation == 'query': @@ -108,7 +122,8 @@ class ToolLimiter: """获取调用统计摘要""" lines = [ f"人设图: 修改{self.counts.persona_update}/{self.limits.persona_update_max}次", - f"工作记忆链: 修改{self.counts.task_update}/{self.limits.task_update_max}次", + f"工作记忆链: 查询{self.counts.task_query}/{self.limits.task_query_max}次, " + f"修改{self.counts.task_update}/{self.limits.task_update_max}次", f"一般记忆: 查询{self.counts.memory_query}/{self.limits.memory_query_max}次, " f"修改{self.counts.memory_update}/{self.limits.memory_update_max}次" ] diff --git a/docs/zh/architecture.md b/docs/zh/architecture.md index 5b5da75..e4bff15 100644 --- a/docs/zh/architecture.md +++ b/docs/zh/architecture.md @@ -260,9 +260,10 @@ def main(): | 类别 | 操作 | 每轮上限 | |------|------|---------| | 人设图 | 修改 | 1 次 | -| 工作记忆链 | 修改 | 5 次 | -| 一般记忆 | 查询 | 20 次 | -| 一般记忆 | 修改 | 10 次 | +| 工作记忆链 | 查询 | 30 次 | +| 工作记忆链 | 修改 | 20 次 | +| 一般记忆 | 查询 | 30 次 | +| 一般记忆 | 修改 | 15 次 | > 注:`memory_recall` 统一计入一般记忆查询,不再区分人设/工作记忆查询。