Skip to content

Commit d9f8d8a

Browse files
authored
summarization manager - add summary prompt to messages (#698)
* summarization manager - add summary prompt to messages * summarize conversation - assistant to user role * fix test * add period
1 parent aa03b3d commit d9f8d8a

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/strands/agent/conversation_manager/summarizing_conversation_manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Summarizing conversation history management with configurable options."""
22

33
import logging
4-
from typing import TYPE_CHECKING, Any, List, Optional
4+
from typing import TYPE_CHECKING, Any, List, Optional, cast
55

66
from typing_extensions import override
77

@@ -201,8 +201,7 @@ def _generate_summary(self, messages: List[Message], agent: "Agent") -> Message:
201201

202202
# Use the agent to generate summary with rich content (can use tools if needed)
203203
result = summarization_agent("Please summarize this conversation.")
204-
205-
return result.message
204+
return cast(Message, {**result.message, "role": "user"})
206205

207206
finally:
208207
# Restore original agent state

tests/strands/agent/test_summarizing_conversation_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_reduce_context_with_summarization(summarizing_manager, mock_agent):
9999
assert len(mock_agent.messages) == 4
100100

101101
# First message should be the summary
102-
assert mock_agent.messages[0]["role"] == "assistant"
102+
assert mock_agent.messages[0]["role"] == "user"
103103
first_content = mock_agent.messages[0]["content"][0]
104104
assert "text" in first_content and "This is a summary of the conversation." in first_content["text"]
105105

@@ -438,7 +438,7 @@ def test_reduce_context_tool_pair_adjustment_works_with_forward_search():
438438
assert len(mock_agent.messages) == 2
439439

440440
# First message should be the summary
441-
assert mock_agent.messages[0]["role"] == "assistant"
441+
assert mock_agent.messages[0]["role"] == "user"
442442
summary_content = mock_agent.messages[0]["content"][0]
443443
assert "text" in summary_content and "This is a summary of the conversation." in summary_content["text"]
444444

tests_integ/test_summarizing_conversation_manager_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_summarization_with_context_overflow(model):
160160

161161
# First message should be the summary (assistant message)
162162
summary_message = agent.messages[0]
163-
assert summary_message["role"] == "assistant"
163+
assert summary_message["role"] == "user"
164164
assert len(summary_message["content"]) > 0
165165

166166
# Verify the summary contains actual text content
@@ -362,7 +362,7 @@ def test_dedicated_summarization_agent(model, summarization_model):
362362

363363
# Get the summary message
364364
summary_message = agent.messages[0]
365-
assert summary_message["role"] == "assistant"
365+
assert summary_message["role"] == "user"
366366

367367
# Extract summary text
368368
summary_text = None

0 commit comments

Comments
 (0)