Skip to content

Commit 622db6f

Browse files
committed
trim comments to the load-bearing lines
1 parent 887f48d commit 622db6f

2 files changed

Lines changed: 6 additions & 13 deletions

File tree

swarms/structs/conversation.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
from 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.
3130
MESSAGE_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(

tests/structs/test_conversation.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,7 @@ def test_dynamic_chunking_keeps_whole_messages():
937937
conv = _overflowing_conversation(messages=60)
938938
result = conv.return_history_as_string()
939939

940-
# time_enabled prefixes every complete message with its [timestamp],
941-
# so a fragment at the front means the cut landed mid-message.
940+
# Every complete message starts with its [timestamp] under time_enabled.
942941
for line in result.split("\n\n"):
943942
assert line.startswith("[")
944943

@@ -967,8 +966,7 @@ def recording(text, *args, **kwargs):
967966
_overflowing_conversation(messages=240).return_history_as_string()
968967
large = sum(tokenized)
969968

970-
# An 8x longer transcript trims into the same size window, so the
971-
# characters tokenized should stay flat rather than scale with it.
969+
# 8x the transcript, same window: tokenized characters should stay flat.
972970
assert large < small * 2
973971

974972

0 commit comments

Comments
 (0)