Skip to content

Commit 668508c

Browse files
wehosHongzhi Wen
andauthored
Tune memory compression and review cadence (#1247)
Co-authored-by: Hongzhi Wen <cartabio.coder1@gmail.com>
1 parent 53890f3 commit 668508c

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ def translate_value(val):
906906
- 互动:和 RECENT_COMPRESS_THRESHOLD_ITEMS 配对——压缩后保留 N 条 +
907907
Stage-1 summary 1 条 = N+1 条进入下次压缩计数。"""
908908

909-
RECENT_COMPRESS_THRESHOLD_ITEMS = 15
909+
RECENT_COMPRESS_THRESHOLD_ITEMS = 20
910910
"""触发 LLM 压缩的条数阈值。
911911
- 用途:当某 lanlan 的 user_histories 累积到 > 此值时调一次
912912
compress_history。

memory_server.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ async def release_character_resources(lanlan_name: str):
342342
_last_activity_time: datetime = datetime.now() # 最后一次对话活动时间
343343
IDLE_CHECK_INTERVAL = 40 # 空闲检查轮询间隔(秒)
344344
IDLE_THRESHOLD = 10 # 多少秒无活动视为空闲(匹配最低 proactive 间隔)
345-
REVIEW_MIN_INTERVAL = 30 # review 最短间隔(秒)。配合 active 时 ×2 + 消息门 双重限流
345+
REVIEW_MIN_INTERVAL = 60 # review 最短间隔(秒)。配合消息门双重限流
346346
REVIEW_SKIP_HISTORY_LEN = 8 # 历史不足此数的角色跳过 review
347347
MIN_NEW_MSGS_FOR_REVIEW = 5 # 自上次 review cutoff 起累积 ≥ N 条 user msg 才允许触发新一轮
348348

@@ -1109,8 +1109,8 @@ async def _periodic_idle_maintenance_loop():
11091109

11101110
# ── 子任务1: 历史记录压缩(有需要就跑,不受全局开关控制) ──
11111111
# 门槛对齐 update_history 内部的真实触发条件 `len > compress_threshold`
1112-
# (默认 15)。用 max_history_length(默认 10,压缩后保留条数)会让
1113-
# 11~15 区间持续触发 IdleMaint 但 update_history 实际不压缩,形成
1112+
# (默认 20)。用 max_history_length(默认 10,压缩后保留条数)会让
1113+
# 11~20 区间持续触发 IdleMaint 但 update_history 实际不压缩,形成
11141114
# 每 IDLE_CHECK_INTERVAL 一次的空转日志。
11151115
if history_len > recent_history_manager.compress_threshold:
11161116
logger.info(
@@ -2220,7 +2220,7 @@ async def maybe_spawn_review(name: str) -> None:
22202220
1. 已有 review 在跑(in-flight)
22212221
2. ``review_enabled``(``recent_memory_auto_review`` flag)
22222222
3. 历史长度 < ``REVIEW_SKIP_HISTORY_LEN``
2223-
4. 距上次 review 完成 < ``REVIEW_MIN_INTERVAL``(活跃时 ×2)
2223+
4. 距上次 review 完成 < ``REVIEW_MIN_INTERVAL``
22242224
5. 自上次 review cutoff 起累积 user msg < ``MIN_NEW_MSGS_FOR_REVIEW``
22252225
"""
22262226
async with _get_review_spawn_lock(name):
@@ -2240,12 +2240,12 @@ async def maybe_spawn_review(name: str) -> None:
22402240
# Gate 3: history 长度
22412241
if len(history) < REVIEW_SKIP_HISTORY_LEN:
22422242
return
2243-
# Gate 4: min interval (active doubled)
2243+
# Gate 4: min interval
22442244
last_review = _maint_state.get(name, {}).get('last_review_ts')
22452245
if last_review:
22462246
try:
22472247
elapsed = (datetime.now() - datetime.fromisoformat(last_review)).total_seconds()
2248-
effective_min = REVIEW_MIN_INTERVAL * (2 if not _is_idle() else 1)
2248+
effective_min = REVIEW_MIN_INTERVAL
22492249
if elapsed < effective_min:
22502250
return
22512251
except (ValueError, TypeError):

0 commit comments

Comments
 (0)