Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pgrayy
Copy link
Member

@pgrayy pgrayy commented Aug 19, 2025

Description

Certain models (e.g., nova) require the messages array to start with a user message. The summarization manager however adds its summarization as an assistant message to the beginning of the array and thus is incompatible with certain models. To fix, I am adding the summarization prompt ("Please summarize this conversation") to the beginning of the array in front of the assistant summary message.

Related Issues

#611

Documentation PR

N/A

Type of Change

Bug fix

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare: Updated existing unit tests
  • Ran hatch test tests_integ/test_summarizing_conversation_manager_integration.py
    - Locally altered the tests to use the nova pro model to properly ensure fix works.

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The 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 Optional[list[Message]] and so I feel it should be okay to include the summary prompt. Here is an example of how the method is used.

Copy link
Member

Choose a reason for hiding this comment

The 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!

Copy link
Member

@Unshure Unshure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious if you thought about just changing the role of the summary message to user?

@pgrayy
Copy link
Member Author

pgrayy commented Aug 22, 2025

Curious if you thought about just changing the role of the summary message to user?

I did think about this yes and actually tested with it. There were 2 (minor) concerns I had though:

  1. Technically speaking, it would be a backwards incompatible change. Very likely though most customers wouldn't notice. I can't really think of a use case where they would be looking specifically at the summary message role either from their stored session or the messages array.
  2. Setting the role to user could then lead to 2 adjacent user messages in the messages array and that made me wonder if some models would reject this pattern. At least with the models I tested, this did not cause any problems. Still, I thought I would be safe and setup a conventional pattern of user message followed by assistant message.

Again these are minor concerns and so I could get behind just switching the role type. It would certainly simplify the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants