Skip to content

fix(extensions): preserve ReAct structure in current round compression to prevent infinite loops#1027

Open
jujn wants to merge 2 commits intoagentscope-ai:mainfrom
jujn:fix_1026
Open

fix(extensions): preserve ReAct structure in current round compression to prevent infinite loops#1027
jujn wants to merge 2 commits intoagentscope-ai:mainfrom
jujn:fix_1026

Conversation

@jujn
Copy link

@jujn jujn commented Mar 22, 2026

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.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

Copilot AI review requested due to automatic review settings March 22, 2026 12:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 / ToolResult message pairs and inject the LLM summary into the last ToolResult.
  • 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.

@jujn jujn requested a review from a team March 22, 2026 14:10
@codecov
Copy link

codecov bot commented Mar 22, 2026

Codecov Report

❌ Patch coverage is 88.40580% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ope/core/memory/autocontext/AutoContextMemory.java 88.40% 2 Missing and 6 partials ⚠️

📢 Thoughts on this report? Let us know!

@LearningGp
Copy link
Collaborator

@shiyiyue1102 PTAL

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.

[Bug]:AutoContextMemory Strategy 6 breaks ReAct tool_use/tool_result structure, causing LLM to repeat tool calls infinitely

3 participants