fix(session): preserve user turns in replay history

This commit is contained in:
Xubin Ren
2026-06-18 00:03:22 +08:00
parent 472c67722e
commit 09962895fb
7 changed files with 91 additions and 17 deletions
+8 -1
View File
@@ -19,6 +19,7 @@ from nanobot.utils.helpers import (
estimate_message_tokens,
find_legal_message_start,
image_placeholder_text,
recent_message_start_index,
safe_filename,
strip_think,
)
@@ -153,6 +154,7 @@ class Session:
*,
max_tokens: int = 0,
include_timestamps: bool = False,
extend_to_user: bool = False,
) -> list[dict[str, Any]]:
"""Return unconsolidated messages for LLM input.
@@ -161,7 +163,12 @@ class Session:
"""
unconsolidated = self.messages[self.last_consolidated:]
max_messages = max_messages if max_messages > 0 else 120
sliced = unconsolidated[-max_messages:]
start_idx = recent_message_start_index(
unconsolidated,
max_messages,
extend_to_user=extend_to_user,
)
sliced = unconsolidated[start_idx:]
# Avoid starting mid-turn when possible, except for proactive
# assistant deliveries that the user may be replying to.