@@ -95,13 +95,16 @@ def test_reduce_context_with_summarization(summarizing_manager, mock_agent):
9595
9696 summarizing_manager .reduce_context (mock_agent )
9797
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
100100
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+ }
105108
106109 # Recent messages should be preserved
107110 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():
434437 # messages_to_summarize_count = (3 - 1) * 0.5 = 1
435438 # But split point adjustment will move forward from the toolUse, potentially increasing count
436439 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+ }
445450 # 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" }
448452
449453
450454def test_adjust_split_point_exceeds_message_length (summarizing_manager ):
@@ -590,21 +594,19 @@ def test_summarizing_conversation_manager_properly_records_removed_message_count
590594 assert manager .removed_message_count == 0
591595
592596 manager .reduce_context (agent )
593- # Assert the oldest message is the sumamry message
594597 assert manager ._summary_message ["content" ][0 ]["text" ] == "Summary"
595598 # 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
598601 # Half of the messages were summarized and removed: 8/2 = 4
599602 assert manager .removed_message_count == 4
600603
601604 manager .reduce_context (agent )
602605 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 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
610612 assert manager .removed_message_count == 5
0 commit comments