Skip to content

fix: skip compressed assistant tool calls#1487

Open
guslegend0510 wants to merge 7 commits into
agentscope-ai:mainfrom
guslegend0510:fix/issue-1482-autocontext-loop
Open

fix: skip compressed assistant tool calls#1487
guslegend0510 wants to merge 7 commits into
agentscope-ai:mainfrom
guslegend0510:fix/issue-1482-autocontext-loop

Conversation

@guslegend0510

Copy link
Copy Markdown

背景

在 AutoContext 压缩场景下,assistant 消息会带有 _compress_meta 标记。原有逻辑在提取最近工具调用时,可能把这些压缩后的消息当成新的工具调用上下文,导致后续轮次恢复出的工具调用不正确,甚至出现重复执行风险。

修改内容

  • MessageUtils.extractRecentToolCalls() 中跳过带 _compress_meta 的 assistant 消息。
  • 避免压缩消息污染“最近工具调用”的提取结果。
  • 保持普通 assistant 消息和原有工具调用处理逻辑不变。

验证

  • mvn -pl agentscope-core -am -Dtest=MessageUtilsTest test

Fixes #1482

@guslegend0510 guslegend0510 requested a review from a team May 25, 2026 10:19
@CLAassistant

CLAassistant commented May 25, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented May 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ain/java/io/agentscope/core/util/MessageUtils.java 75.00% 0 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@LearningGp

Copy link
Copy Markdown
Member
image

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core Core library: agentscope-core (general) labels May 28, 2026
@guslegend0510

Copy link
Copy Markdown
Author

@LearningGp 麻烦审核一下,谢谢

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 AI Review

This PR fixes a bug where MessageUtils.extractRecentToolCalls() could pick up tool calls from compressed assistant messages (those carrying _compress_meta metadata), leading to incorrect or duplicate tool call extraction in the AutoContext compression scenario. The fix is clean and well-scoped: it adds a continue guard to skip compressed messages when scanning backwards, and includes a new test class covering the main cases. The logic is correct and aligns with the issue description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Core library: agentscope-core (general) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AutoContextMemory导致工具重复调用,直到maxIters才结束,触发压缩后有概率出现这个问题

5 participants