feat(amazonq): add auto compaction feature#2623
Draft
laileni-aws wants to merge 1 commit intoaws:feature/auto-compactionfrom
Draft
feat(amazonq): add auto compaction feature#2623laileni-aws wants to merge 1 commit intoaws:feature/auto-compactionfrom
laileni-aws wants to merge 1 commit intoaws:feature/auto-compactionfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feature/auto-compaction #2623 +/- ##
===========================================================
- Coverage 60.52% 60.39% -0.14%
===========================================================
Files 279 279
Lines 65790 65915 +125
Branches 4180 4179 -1
===========================================================
- Hits 39821 39807 -14
- Misses 25887 26025 +138
- Partials 82 83 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the context window is exceeded during agentic chat, users see an "Improperly formed request" or "Input is too long" error and must manually run
/compactthen re-ask their question.Solution
Automatically detect context window overflow errors and run compaction + retry transparently, using a single boolean flag (
didAutoCompactOnOverflow) to allow one automatic compaction per user turn (preventing infinite loops).Auto-compaction is handled at two levels:
Mid-loop (inside
#runAgentLoop): WhengetChatResponse()throws a context overflow error, the agent loop compacts conversation history andcontinues from the current iteration — preserving in-progress state and tool execution context.Outer catch (in
onChatPrompt): Catches overflow errors from request preparation, compaction itself, or result handling. Compacts and retries the fullonChatPromptcall.The flag is reset at the start of each new user message, so:
false→true)true)falseLicense
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.