refactor(config): make max messages default explicit

Use 120 as the config-level default and normalize zero back to that limit so session replay always receives an explicit message cap.

Made-with: Cursor
This commit is contained in:
Xubin Ren
2026-04-28 14:54:32 +08:00
committed by Xubin Ren
parent d45ffcf519
commit ad4802600e
5 changed files with 67 additions and 66 deletions
+3 -4
View File
@@ -12,15 +12,13 @@ from loguru import logger
from nanobot.config.paths import get_legacy_sessions_dir
from nanobot.utils.helpers import (
estimate_message_tokens,
ensure_dir,
estimate_message_tokens,
find_legal_message_start,
image_placeholder_text,
safe_filename,
)
HISTORY_MAX_MESSAGES = 120
FILE_MAX_MESSAGES = 2000
@@ -74,7 +72,7 @@ class Session:
def get_history(
self,
max_messages: int = HISTORY_MAX_MESSAGES,
max_messages: int = 120,
*,
max_tokens: int = 0,
include_timestamps: bool = False,
@@ -85,6 +83,7 @@ class Session:
token budget from the tail (``max_tokens``) when provided.
"""
unconsolidated = self.messages[self.last_consolidated:]
max_messages = max_messages if max_messages > 0 else 120
sliced = unconsolidated[-max_messages:]
# Avoid starting mid-turn when possible, except for proactive