@@ -95,16 +95,13 @@ def test_reduce_context_with_summarization(summarizing_manager, mock_agent):
9595
9696 summarizing_manager .reduce_context (mock_agent )
9797
98- # Should have: 1 summary prompt + 1 summary message + 2 preserved recent messages + remaining from summarization
99- assert len (mock_agent .messages ) == 5
98+ # Should have: 1 summary message + 2 preserved recent messages + remaining from summarization
99+ assert len (mock_agent .messages ) == 4
100100
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- }
101+ # First message should be the summary
102+ assert mock_agent .messages [0 ]["role" ] == "user"
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" ]
108105
109106 # Recent messages should be preserved
110107 assert "Message 3" in str (mock_agent .messages [- 2 ]["content" ])
@@ -437,18 +434,17 @@ def test_reduce_context_tool_pair_adjustment_works_with_forward_search():
437434 # messages_to_summarize_count = (3 - 1) * 0.5 = 1
438435 # But split point adjustment will move forward from the toolUse, potentially increasing count
439436 manager .reduce_context (mock_agent )
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- }
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" ] == "user"
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+
450445 # Last message should be the preserved recent message
451- assert mock_agent .messages [2 ] == {"content" : [{"text" : "Latest message" }], "role" : "user" }
446+ assert mock_agent .messages [1 ]["role" ] == "user"
447+ assert mock_agent .messages [1 ]["content" ][0 ]["text" ] == "Latest message"
452448
453449
454450def test_adjust_split_point_exceeds_message_length (summarizing_manager ):
@@ -594,19 +590,21 @@ def test_summarizing_conversation_manager_properly_records_removed_message_count
594590 assert manager .removed_message_count == 0
595591
596592 manager .reduce_context (agent )
593+ # Assert the oldest message is the sumamry message
597594 assert manager ._summary_message ["content" ][0 ]["text" ] == "Summary"
598595 # There are 8 messages in the agent messages array, since half will be summarized,
599- # 4 will remain plus 1 summary prompt and 1 summary message = 6
600- assert len (agent .messages ) == 6
596+ # 4 will remain plus 1 summary message = 5
597+ assert ( len (agent .messages )) == 5
601598 # Half of the messages were summarized and removed: 8/2 = 4
602599 assert manager .removed_message_count == 4
603600
604601 manager .reduce_context (agent )
605602 assert manager ._summary_message ["content" ][0 ]["text" ] == "Summary"
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 were 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
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
612610 assert manager .removed_message_count == 5
0 commit comments