8000 fix: improve conversation context compaction by including user messages in sequence detection by tusharmath · Pull Request #885 · antinomyhq/forge · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: improve conversation context compaction by including user messages in sequence detection #885

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

Merged
merged 1 commit into from
Jun 2, 2025

Conversation

tusharmath
Copy link
Collaborator
@tusharmath tusharmath commented Jun 2, 2025

Summary

This PR improves the conversation context compaction algorithm by modifying the sequence detection logic to start from the first non-system message rather than the first assistant message. This enhancement allows for more efficient memory management by including user messages in compaction sequences when appropriate.

Changes

  • Modified sequence finding logic: Changed from detecting first assistant message to first non-system message in find_sequence function
  • Updated test expectations: Adjusted all test cases to reflect the new compaction behavior pattern
  • Improved compaction efficiency: User messages can now be included in compaction sequences, leading to better context optimization

Technical Details

The core change is in crates/forge_services/src/compaction.rs:

  • Line 188: Changed find logic from message.has_role(Role::Assistant) to !message.has_role(Role::System)
  • This allows compaction to include user messages that occur before assistant messages
  • All test cases updated to reflect new sequence detection patterns

Impact

  • More aggressive and effective context compaction
  • Better token usage optimization for long conversations
  • Improved memory efficiency while preserving conversation flow

@tusharmath tusharmath enabled auto-merge (squash) June 2, 2025 19:13
@tusharmath tusharmath changed the title fix: update sequence finding logic to exclude system messages and adjust expected outputs in tests feat: improve conversation context compaction by including user messages in sequence detection Jun 2, 2025
@tusharmath tusharmath changed the title feat: improve conversation context compaction by including user messages in sequence detection fix: improve conversation context compaction by including user messages in sequence detection Jun 2, 2025
@tusharmath tusharmath merged commit f6cdf7a into main Jun 2, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0