generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 494
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Checks
- I have updated to the lastest minor and patch version of Strands
- I have checked the documentation and this is not expected behavior
- I have searched ./issues and there are no duplicates of my issue
Strands Version
1.10.0
Python Version
3.10
Operating System
Linux/X86_64
Installation Method
pip
Steps to Reproduce
- When agent is using the tool and toolResult encountered context overflow, SummarizingConversationManager will invoke reduce_context to perform summarisation.
- However, when context overflow is not from all the messages but from the latest message itself, the single toolResult, SummarizingConversationManager will throw ContextWindowOverflowException with insufficient messages as the logic is assuming the context overflow coming from "all the messages".
def reduce_context(self, agent: "Agent", e: Optional[Exception] = None, **kwargs: Any) -> None:
"""Reduce context using summarization.
Args:
agent: The agent whose conversation history will be reduced.
The agent's messages list is modified in-place.
e: The exception that triggered the context reduction, if any.
**kwargs: Additional keyword arguments for future extensibility.
Raises:
ContextWindowOverflowException: If the context cannot be summarized.
"""
try:
# Calculate how many messages to summarize
messages_to_summarize_count = max(1, int(len(agent.messages) * self.summary_ratio))
# Ensure we don't summarize recent messages
messages_to_summarize_count = min(
messages_to_summarize_count, len(agent.messages) - self.preserve_recent_messages
)
if messages_to_summarize_count <= 0:
raise ContextWindowOverflowException("Cannot summarize: insufficient messages for summarization")
# Adjust split point to avoid breaking ToolUse/ToolResult pairs
messages_to_summarize_count = self._adjust_split_point_for_tool_pairs(
agent.messages, messages_to_summarize_count
)
if messages_to_summarize_count <= 0:
raise ContextWindowOverflowException("Cannot summarize: insufficient messages for summarization")example agent.message
{
"role": "user",
"content": [
{
"text": "give me xxxx"
}
]
}
,
{
"role": "assistant",
"content": [
{
"text": "I'll get the xxxx."
},
{
"toolUse": {
"toolUseId": "tooluse_TWWIsSUfTBWFK5Rh00zSgQ",
"name": "xxx",
"input": {
....
}
}
}
]
}
,
{
"role": "user",
"content": [
{
"toolResult": {
"status": "success",
"toolUseId": "tooluse_TWWIsSUfTBWFK5Rh00zSgQ",
"content": [
{
"text": "{.....
Expected Behavior
- SummarizingConversationManager should be able to handle such case but checking the number of messages
Actual Behavior
- SummarizingConversationManager found out there is limited number of messages at the moment and then throw the ContextWindowOverflowException
Additional Context
No response
Possible Solution
Instead of message level summarization, is it possible to go deeper to the content level to generate summary from there.
Or is it recommended to have a new custom summarizing_content_manager
# Extract messages to summarize
messages_to_summarize = agent.messages[:messages_to_summarize_count]
remaining_messages = agent.messages[messages_to_summarize_count:]
Related Issues
No response
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request