-
Notifications
You must be signed in to change notification settings - Fork 314
summarization manager - add summary prompt to messages #698
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ def __init__( | |
self.summarization_agent = summarization_agent | ||
self.summarization_system_prompt = summarization_system_prompt | ||
self._summary_message: Optional[Message] = None | ||
self._summary_prompt: Message = {"content": [{"text": "Please summarize this conversation"}], "role": "user"} | ||
|
||
@override | ||
def restore_from_session(self, state: dict[str, Any]) -> Optional[list[Message]]: | ||
|
@@ -94,7 +95,7 @@ def restore_from_session(self, state: dict[str, Any]) -> Optional[list[Message]] | |
""" | ||
super().restore_from_session(state) | ||
self._summary_message = state.get("summary_message") | ||
return [self._summary_message] if self._summary_message else None | ||
return [self._summary_prompt, self._summary_message] if self._summary_message else None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the one change I am somewhat worried about. The return type is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohh this is clever! At first I didnt think this would work since we only store a single message in the conversation manager state (ref), but since this message is static it should be fine! |
||
|
||
def get_state(self) -> dict[str, Any]: | ||
"""Returns a dictionary representation of the state for the Summarizing Conversation Manager.""" | ||
|
@@ -152,15 +153,15 @@ def reduce_context(self, agent: "Agent", e: Optional[Exception] = None, **kwargs | |
|
||
# Keep track of the number of messages that have been summarized thus far. | ||
self.removed_message_count += len(messages_to_summarize) | ||
# If there is a summary message, don't count it in the removed_message_count. | ||
# If there is a summary message, don't count it or the summary prompt in the removed_message_count. | ||
if self._summary_message: | ||
self.removed_message_count -= 1 | ||
self.removed_message_count -= 2 | ||
|
||
# Generate summary | ||
self._summary_message = self._generate_summary(messages_to_summarize, agent) | ||
|
||
# Replace the summarized messages with the summary | ||
agent.messages[:] = [self._summary_message] + remaining_messages | ||
agent.messages[:] = [self._summary_prompt, self._summary_message] + remaining_messages | ||
|
||
except Exception as summarization_error: | ||
logger.error("Summarization failed: %s", summarization_error) | ||
|
@@ -200,8 +201,7 @@ def _generate_summary(self, messages: List[Message], agent: "Agent") -> Message: | |
summarization_agent.messages = messages | ||
|
||
# Use the agent to generate summary with rich content (can use tools if needed) | ||
result = summarization_agent("Please summarize this conversation.") | ||
|
||
result = summarization_agent(self._summary_prompt["content"]) | ||
return result.message | ||
|
||
finally: | ||
|
Uh oh!
There was an error while loading. Please reload this page.