fix: 调整工具调用限制 - 工作记忆链修改20次/查询30次,一般记忆查询30次/修改15次

This commit is contained in:
root
2026-04-28 19:59:13 +08:00
parent 598e03e2eb
commit bddb5498e9
2 changed files with 25 additions and 9 deletions

View File

@ -9,9 +9,10 @@ from dataclasses import dataclass
class ToolLimits: class ToolLimits:
"""工具调用限制配置""" """工具调用限制配置"""
persona_update_max: int = 1 persona_update_max: int = 1
task_update_max: int = 5 task_update_max: int = 20 # 工作记忆链修改(create/set_state/delete/link_info)
memory_query_max: int = 20 task_query_max: int = 30 # 工作记忆链查询(memory_recall 查任务相关)
memory_update_max: int = 10 memory_query_max: int = 30
memory_update_max: int = 15
@dataclass @dataclass
@ -19,6 +20,7 @@ class ToolCallCount:
"""工具调用计数""" """工具调用计数"""
persona_update: int = 0 persona_update: int = 0
task_update: int = 0 task_update: int = 0
task_query: int = 0
memory_query: int = 0 memory_query: int = 0
memory_update: int = 0 memory_update: int = 0
@ -44,6 +46,12 @@ class ToolLimiter:
return ('task', 'update') return ('task', 'update')
if tool_name == 'memory_recall': 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') return ('memory', 'query')
if tool_name == 'memory_commit': if tool_name == 'memory_commit':
@ -75,7 +83,10 @@ class ToolLimiter:
return (False, f"人设图修改次数已达上限({self.limits.persona_update_max}次)") return (False, f"人设图修改次数已达上限({self.limits.persona_update_max}次)")
elif category == 'task': 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}次)") return (False, f"工作记忆链修改次数已达上限({self.limits.task_update_max}次)")
elif category == 'memory': elif category == 'memory':
@ -96,7 +107,10 @@ class ToolLimiter:
self.counts.persona_update += 1 self.counts.persona_update += 1
elif category == 'task': 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': elif category == 'memory':
if operation == 'query': if operation == 'query':
@ -108,7 +122,8 @@ class ToolLimiter:
"""获取调用统计摘要""" """获取调用统计摘要"""
lines = [ lines = [
f"人设图: 修改{self.counts.persona_update}/{self.limits.persona_update_max}次", 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_query}/{self.limits.memory_query_max}次, "
f"修改{self.counts.memory_update}/{self.limits.memory_update_max}次" f"修改{self.counts.memory_update}/{self.limits.memory_update_max}次"
] ]

View File

@ -260,9 +260,10 @@ def main():
| 类别 | 操作 | 每轮上限 | | 类别 | 操作 | 每轮上限 |
|------|------|---------| |------|------|---------|
| 人设图 | 修改 | 1 次 | | 人设图 | 修改 | 1 次 |
| 工作记忆链 | 修改 | 5 次 | | 工作记忆链 | 查询 | 30 次 |
| 一般记忆 | 查询 | 20 次 | | 工作记忆链 | 修改 | 20 次 |
| 一般记忆 | 修改 | 10 次 | | 一般记忆 | 查询 | 30 次 |
| 一般记忆 | 修改 | 15 次 |
> 注:`memory_recall` 统一计入一般记忆查询,不再区分人设/工作记忆查询。 > 注:`memory_recall` 统一计入一般记忆查询,不再区分人设/工作记忆查询。