Skip to content

fix(autocontext): preserve tool pairs in current round compression#1337

Open
Alexxigang wants to merge 2 commits into
agentscope-ai:mainfrom
Alexxigang:fix/autocontext-preserve-tool-pairs
Open

fix(autocontext): preserve tool pairs in current round compression#1337
Alexxigang wants to merge 2 commits into
agentscope-ai:mainfrom
Alexxigang:fix/autocontext-preserve-tool-pairs

Conversation

@Alexxigang
Copy link
Copy Markdown
Contributor

Summary

  • preserve tool_use and tool_result structure when Strategy 6 compresses the current round
  • aggregate current-round tool calls/results into a compact assistant/tool pair instead of flattening them into a single assistant text message
  • add regression coverage for current-round compression with tool interactions

Why this fix

mergeAndCompressCurrentRoundMessages() currently offloads the whole current-round segment and rewrites it as a single plain ASSISTANT text message. When that segment contains ReAct-style tool_use / tool_result exchanges, the structural pairing is lost, so the next turn can behave as if the tool call never happened and repeat the invocation.

This change keeps Strategy 6 compact, but preserves the semantic tool-call record by retaining aggregated ToolUseBlock and ToolResultBlock content in the compressed messages.

Validation

  • mvn -pl agentscope-extensions/agentscope-extensions-autocontext-memory -am '-Dtest=AutoContextMemoryTest' test
  • mvn -pl agentscope-extensions/agentscope-extensions-autocontext-memory -am '-Dtest=AutoContextMemoryTest,AutoContextHookTest' test

Closes #1026

@Alexxigang Alexxigang force-pushed the fix/autocontext-preserve-tool-pairs branch from aa65796 to 58cf09a Compare May 4, 2026 14:42
@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

❌ Patch coverage is 84.93151% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ope/core/memory/autocontext/AutoContextMemory.java 84.93% 3 Missing and 8 partials ⚠️

📢 Thoughts on this report? Let us know!

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

1 participant