2626from swarms .utils .generate_id import generate_id
2727
2828
29- # Joins messages in the rendered history. Truncation measures each message
30- # together with this separator, so the two must stay in sync.
29+ # Truncation measures each message with this separator, so keep them in sync.
3130MESSAGE_SEPARATOR = "\n \n "
3231
3332
@@ -1565,11 +1564,8 @@ def _dynamic_auto_chunking_worker(self):
15651564 if not messages :
15661565 return ""
15671566
1568- # Keep whole messages, newest first, while they fit. Each message is
1569- # measured with the separator that will FOLLOW it, which the newest
1570- # kept message never has. Measured that way the chunks concatenate to
1571- # exactly the joined result, so — since splitting a string can only
1572- # hold or raise its token count — the running total is an upper bound
1567+ # Whole messages, newest first. Each is measured with the separator
1568+ # that follows it, so the running total is an upper bound on the join
15731569 # and the result cannot exceed context_length.
15741570 budget = self .context_length
15751571 kept = 0
@@ -1589,8 +1585,7 @@ def _dynamic_auto_chunking_worker(self):
15891585 kept += 1
15901586
15911587 if kept == 0 :
1592- # The newest message alone overflows the window, so there is no
1593- # boundary to cut on — fall back to trimming inside it.
1588+ # The newest message alone overflows: no boundary to cut on.
15941589 return self ._truncate_to_context_length (messages [- 1 ])
15951590
15961591 return MESSAGE_SEPARATOR .join (
0 commit comments