@@ -95,13 +95,16 @@ def test_reduce_context_with_summarization(summarizing_manager, mock_agent):
95
95
96
96
summarizing_manager .reduce_context (mock_agent )
97
97
98
- # Should have: 1 summary message + 2 preserved recent messages + remaining from summarization
99
- assert len (mock_agent .messages ) == 4
98
+ # Should have: 1 summary prompt + 1 summary message + 2 preserved recent messages + remaining from summarization
99
+ assert len (mock_agent .messages ) == 5
100
100
101
- # First message should be the summary
102
- assert mock_agent .messages [0 ]["role" ] == "assistant"
103
- first_content = mock_agent .messages [0 ]["content" ][0 ]
104
- assert "text" in first_content and "This is a summary of the conversation." in first_content ["text" ]
101
+ # First message should be the summary prompt
102
+ assert mock_agent .messages [0 ] == {"content" : [{"text" : "Please summarize this conversation" }], "role" : "user" }
103
+ # Second message should be the summary
104
+ assert mock_agent .messages [1 ] == {
105
+ "content" : [{"text" : "This is a summary of the conversation." }],
106
+ "role" : "assistant" ,
107
+ }
105
108
106
109
# Recent messages should be preserved
107
110
assert "Message 3" in str (mock_agent .messages [- 2 ]["content" ])
@@ -434,17 +437,18 @@ def test_reduce_context_tool_pair_adjustment_works_with_forward_search():
434
437
# messages_to_summarize_count = (3 - 1) * 0.5 = 1
435
438
# But split point adjustment will move forward from the toolUse, potentially increasing count
436
439
manager .reduce_context (mock_agent )
437
- # Should have summary + remaining messages
438
- assert len (mock_agent .messages ) == 2
439
-
440
- # First message should be the summary
441
- assert mock_agent .messages [0 ]["role" ] == "assistant"
442
- summary_content = mock_agent .messages [0 ]["content" ][0 ]
443
- assert "text" in summary_content and "This is a summary of the conversation." in summary_content ["text" ]
444
-
440
+ # Should have summary prompt + summary + remaining messages
441
+ assert len (mock_agent .messages ) == 3
442
+
443
+ # First message should be the summary prompt
444
+ assert mock_agent .messages [0 ] == {"content" : [{"text" : "Please summarize this conversation" }], "role" : "user" }
445
+ # Second message should be the summary
446
+ assert mock_agent .messages [1 ] == {
447
+ "content" : [{"text" : "This is a summary of the conversation." }],
448
+ "role" : "assistant" ,
449
+ }
445
450
# Last message should be the preserved recent message
446
- assert mock_agent .messages [1 ]["role" ] == "user"
447
- assert mock_agent .messages [1 ]["content" ][0 ]["text" ] == "Latest message"
451
+ assert mock_agent .messages [2 ] == {"content" : [{"text" : "Latest message" }], "role" : "user" }
448
452
449
453
450
454
def test_adjust_split_point_exceeds_message_length (summarizing_manager ):
@@ -590,21 +594,19 @@ def test_summarizing_conversation_manager_properly_records_removed_message_count
590
594
assert manager .removed_message_count == 0
591
595
592
596
manager .reduce_context (agent )
593
- # Assert the oldest message is the sumamry message
594
597
assert manager ._summary_message ["content" ][0 ]["text" ] == "Summary"
595
598
# There are 8 messages in the agent messages array, since half will be summarized,
596
- # 4 will remain plus 1 summary message = 5
597
- assert ( len (agent .messages )) == 5
599
+ # 4 will remain plus 1 summary prompt and 1 summary message = 6
600
+ assert len (agent .messages ) == 6
598
601
# Half of the messages were summarized and removed: 8/2 = 4
599
602
assert manager .removed_message_count == 4
600
603
601
604
manager .reduce_context (agent )
602
605
assert manager ._summary_message ["content" ][0 ]["text" ] == "Summary"
603
- # After the first summary, 5 messages remain. Summarizing again will lead to:
604
- # 5 - (int(5/2)) (messages to be sumamrized) + 1 (new summary message) = 5 - 2 + 1 = 4
605
- assert (len (agent .messages )) == 4
606
- # Half of the messages were summarized and removed: int(5/2) = 2
607
- # However, one of the messages that was summarized was the previous summary message,
608
- # so we dont count this toward the total:
609
- # 4 (Previously removed messages) + 2 (removed messages) - 1 (Previous summary message) = 5
606
+ # After the first summary, 6 messages remain. Summarizing again will lead to:
607
+ # 6 - (6/2) (messages to be sumamrized) + 1 (summary prompt) + 1 (new summary message) = 6 - 3 + 1 + 1 = 5
608
+ assert len (agent .messages ) == 5
609
+ # Half of the messages were summarized and removed: (6/2) = 3
610
+ # However, the summary prompt and previous summary message was also summarized but we don't count this in the total.
611
+ # 4 (Previously removed messages) + 3 (removed messages) - 1 (summary prompt) - 1 (Previous summary message) = 5
610
612
assert manager .removed_message_count == 5
0 commit comments