-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: include first message in condense summarization #8294
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
Conversation
- Modified summarizeConversation to include the first message when creating summary - Added test to verify first message is included in summarization content - Fixes issue where initial task context was lost after condensation Fixes #8293
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.
Self-review initiated: auditing my own code with the impartiality of a mirror judging a mirror.
| const firstMessage = messages[0] | ||
| // Get messages to summarize, excluding the first message and last N messages | ||
| const messagesToSummarize = getMessagesSinceLastSummary(messages.slice(1, -N_MESSAGES_TO_KEEP)) | ||
| // Get messages to summarize, including the first message but excluding last N 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.
P2: If N_MESSAGES_TO_KEEP === 0, slice(0, -0) yields an empty array, causing no messages to be summarized. Consider normalizing the end index to undefined when N_MESSAGES_TO_KEEP is 0 (e.g., const end = N_MESSAGES_TO_KEEP ? -N_MESSAGES_TO_KEEP : undefined; const messagesToSummarize = getMessagesSinceLastSummary(messages.slice(0, end));).
| import { summarizeConversation, getMessagesSinceLastSummary, N_MESSAGES_TO_KEEP } from "../index" | ||
|
|
||
| // Create a mock ApiHandler for testing | ||
| class MockApiHandler extends BaseProvider { |
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.
P2: This test override uses Anthropic.Messages.MessageParam[], coupling the test to a specific provider SDK. Prefer a provider-agnostic message type to reduce brittleness across providers.
Description
This PR fixes issue #8293 where the condense feature was omitting the initial user message from the summarization process, causing the task context to be lost when resuming after condensation.
Problem
When condensing a conversation:
Solution
Modified the
summarizeConversationfunction to include the first message in the content that gets summarized:messages.slice(1, -N_MESSAGES_TO_KEEP)tomessages.slice(0, -N_MESSAGES_TO_KEEP)Testing
Impact
This ensures that:
Fixes #8293
Important
Fixes issue #8293 by including the first user message in the summarization process to preserve initial task context in
summarizeConversation.summarizeConversation.messages.slice(1, -N_MESSAGES_TO_KEEP)tomessages.slice(0, -N_MESSAGES_TO_KEEP)inindex.ts.condense.spec.tsto verify inclusion of the first message in summarization.This description was created by
for c28700e. You can customize this summary. It will automatically update as commits are pushed.