fix(extensions): preserve ReAct structure in current round compression to prevent infinite loops#1027
Open
jujn wants to merge 2 commits intoagentscope-ai:mainfrom
Open
fix(extensions): preserve ReAct structure in current round compression to prevent infinite loops#1027jujn wants to merge 2 commits intoagentscope-ai:mainfrom
jujn wants to merge 2 commits intoagentscope-ai:mainfrom
Conversation
…n to prevent infinite loops
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses AutoContextMemory Strategy 6 (“current round” compression) breaking ReAct semantics by ensuring tool-use/tool-result structure is preserved during compression, preventing repeated tool calls (infinite loops).
Changes:
- Updates Strategy 6 replacement logic to keep
ToolUse/ToolResultmessage pairs and inject the LLM summary into the lastToolResult. - Adjusts and adds unit tests to assert ReAct structure preservation and that the summary/offload hint lands in the final
ToolResult.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| agentscope-extensions/agentscope-extensions-autocontext-memory/src/main/java/io/agentscope/core/memory/autocontext/AutoContextMemory.java | Reworks Strategy 6 message replacement to preserve tool message structure and inject summary into last tool result. |
| agentscope-extensions/agentscope-extensions-autocontext-memory/src/test/java/io/agentscope/core/memory/autocontext/AutoContextMemoryTest.java | Updates existing assertions and adds a dedicated test to verify ReAct tool structure is preserved under Strategy 6. |
...utocontext-memory/src/main/java/io/agentscope/core/memory/autocontext/AutoContextMemory.java
Show resolved
Hide resolved
...utocontext-memory/src/main/java/io/agentscope/core/memory/autocontext/AutoContextMemory.java
Show resolved
Hide resolved
...utocontext-memory/src/main/java/io/agentscope/core/memory/autocontext/AutoContextMemory.java
Show resolved
Hide resolved
...utocontext-memory/src/main/java/io/agentscope/core/memory/autocontext/AutoContextMemory.java
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Collaborator
|
@shiyiyue1102 PTAL |
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.
Description
Close #1026
This PR fixes an issue where Strategy 6 compression destroyed the ReAct structure by squashing tool calls into a single text message, causing the LLM to fall into an infinite loop. It now preserves the ToolUse and ToolResult pairs using token-saving placeholders, safely injecting the final summary into the last tool result through a streamlined ContentBlock extraction.
Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)