Skip to content

Conversation

@skoob13
Copy link
Contributor

@skoob13 skoob13 commented Oct 19, 2025

Problem

The window compaction manager now only handles the single case: Inserting the summary message before the initiator human message. However, there are three cases in fact:

  • The messages preserving the agent's trajectory are below 2000 tokens and 16 messages in total having the start message–perfect case. We should insert the summary message before the initiator message.
  • The messages preserving the agent's trajectory are below 2000 tokens and 16 messages in total NOT having the start message–insert the context message and copy the initiator message to the end of sequence.
  • The messages preserving the agent's trajectory cannot be used because it doesn't have an assistant or human messages or the sequence has too many tokens–insert the context message and copy the initiator message to the end of sequence.

Related trace

Changes

  • Implement new logic.
  • More tests.

How did you test this code?

Unit tests & manual testing

@skoob13 skoob13 requested a review from a team October 20, 2025 08:17
@skoob13 skoob13 marked this pull request as ready for review October 20, 2025 08:17
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

6 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@denakorita denakorita left a comment

Choose a reason for hiding this comment

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

Looks good to me!


def find_start_message_idx(messages: Sequence[AssistantMessageUnion], start_id: str | None = None) -> int:
for idx, msg in enumerate(messages):
for idx in range(len(messages) - 1, -1, -1):
Copy link
Contributor

Choose a reason for hiding this comment

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

lol, I've never seen this before

@skoob13 skoob13 enabled auto-merge (squash) October 20, 2025 15:03
@skoob13 skoob13 force-pushed the fix/improve-compaction branch from 9bb69d5 to fcf94e1 Compare October 22, 2025 09:44
@skoob13 skoob13 merged commit d8b4be1 into master Oct 22, 2025
162 of 163 checks passed
@skoob13 skoob13 deleted the fix/improve-compaction branch October 22, 2025 10:01
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.

4 participants