-
Notifications
You must be signed in to change notification settings - Fork 120
feat: implement summarizing conversation manager #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: implement summarizing conversation manager #112
Conversation
712e2ba
to
3fa3bd7
Compare
src/strands/agent/conversation_manager/summarizing_conversation_manager.py
Outdated
Show resolved
Hide resolved
src/strands/agent/conversation_manager/summarizing_conversation_manager.py
Outdated
Show resolved
Hide resolved
02bb209
to
f90af97
Compare
src/strands/agent/conversation_manager/summarizing_conversation_manager.py
Outdated
Show resolved
Hide resolved
Let me know your feedback, I'll hold on the documentation updates until we have a final version (and before merging). |
Can you add an integration test for this implementation as well? We wand to make sure it passes end to end. |
src/strands/agent/conversation_manager/summarizing_conversation_manager.py
Outdated
Show resolved
Hide resolved
src/strands/agent/conversation_manager/summarizing_conversation_manager.py
Outdated
Show resolved
Hide resolved
src/strands/agent/conversation_manager/summarizing_conversation_manager.py
Outdated
Show resolved
Hide resolved
src/strands/agent/conversation_manager/summarizing_conversation_manager.py
Outdated
Show resolved
Hide resolved
f90af97
to
9431bf7
Compare
c0b84b2
to
f1525c2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking really good, thank you for all the work here!
src/strands/agent/conversation_manager/summarizing_conversation_manager.py
Show resolved
Hide resolved
src/strands/agent/conversation_manager/summarizing_conversation_manager.py
Show resolved
Hide resolved
src/strands/agent/conversation_manager/summarizing_conversation_manager.py
Outdated
Show resolved
Hide resolved
src/strands/agent/conversation_manager/summarizing_conversation_manager.py
Outdated
Show resolved
Hide resolved
src/strands/agent/conversation_manager/summarizing_conversation_manager.py
Outdated
Show resolved
Hide resolved
tests-integ/test_summarizing_conversation_manager_integration.py
Outdated
Show resolved
Hide resolved
tests-integ/test_summarizing_conversation_manager_integration.py
Outdated
Show resolved
Hide resolved
c2ea68d
to
565f7ef
Compare
565f7ef
to
ddb29f0
Compare
@Unshure thanks for all the feedback and really appreciate your thorough review 🙏 I've pushed the changes following your comments, let me know if I addressed everything. Happy to contribute and help! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks great! I was able to pull it locally and the integ tests ran much faster as well 🪄.
Few small things to clean up, and then this is good to merge!
def _message_contains_tool_use(self, message: Message) -> bool: | ||
"""Check if a message contains a ToolUse.""" | ||
return any("toolUse" in content for content in message.get("content", [])) | ||
|
||
def _message_contains_tool_result(self, message: Message) -> bool: | ||
"""Check if a message contains a ToolResult.""" | ||
return any("toolResult" in content for content in message.get("content", [])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't used anymore
if split_point >= len(messages): | ||
return split_point |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate logic
# Verify we have tool usage in the conversation | ||
has_tool_use = False | ||
has_tool_result = False | ||
for message in agent.messages: | ||
for content in message.get("content", []): | ||
if "toolUse" in content: | ||
has_tool_use = True | ||
if "toolResult" in content: | ||
has_tool_result = True | ||
|
||
assert has_tool_use, "Conversation should contain tool usage" | ||
assert has_tool_result, "Conversation should contain tool results" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We dont need this check anymore since we manually set up the conversation
assert len(summary_text) > 30 # Should be a substantial summary | ||
|
||
# The dedicated agent should create a structured summary | ||
# (We can't assert exact content since AI responses vary, but we can check it's substantive) | ||
assert any(keyword in summary_text.lower() for keyword in ["space", "exploration", "apollo", "mission"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just remove this check for now. These have led to transient failures in tests which are really annoying to deal with. Im fine with just checking that the summary_text is not empty.
if TYPE_CHECKING: | ||
from ..agent import Agent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious what this is about?
|
||
|
||
class SummarizingConversationManager(ConversationManager): | ||
"""Extends sliding window manager with optional summarization of older messages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This no longer extends sliding window manager
Description
Tip
Follows conventional commits. Better reviewed commit-by-commit.
Introducing a new
SummarizingConversationManager
as an alternative to the existing sliding window approach. It optionally uses AI-powered summarization to retain the semantic context of older messages, rather than discarding them, while staying within model context limits.Related Issues
Closes #90
Documentation PR
strands-agents/docs#63
Type of Change
Testing
hatch fmt --linter
hatch fmt --formatter
hatch test --all
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.