Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions astrbot/core/provider/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,21 @@ def _next_unit_bounds() -> tuple[int, int] | None:
return idx, end_idx
return None

# Removal policy: try to remove around TARGET_RECORDS messages,
# but allow up to MAX_RECORDS to keep tool-call/message units atomic.
TARGET_RECORDS = 2
MAX_RECORDS = 3

removed = 0
while removed < 2:
while removed < TARGET_RECORDS:
next_unit = _next_unit_bounds()
if next_unit is None:
break
start_idx, end_idx = next_unit
next_unit_count = end_idx - start_idx + 1
# Keep behavior close to the old "pop around 2 records" strategy,
# while still preserving tool-call atomicity.
if removed > 0 and removed + next_unit_count > 3:
if removed > 0 and removed + next_unit_count > MAX_RECORDS:
break
del context[start_idx : end_idx + 1]
removed += next_unit_count
Expand Down