Skip to content

fix(core): handle pending tool calls when maxIters reached (#1005)#1012

Open
Fancy-hjyp wants to merge 2 commits intoagentscope-ai:mainfrom
Fancy-hjyp:fix/issue-1005-maxiters-pending-tool-calls
Open

fix(core): handle pending tool calls when maxIters reached (#1005)#1012
Fancy-hjyp wants to merge 2 commits intoagentscope-ai:mainfrom
Fancy-hjyp:fix/issue-1005-maxiters-pending-tool-calls

Conversation

@Fancy-hjyp
Copy link

fix #1005

Problem

When maxIters is reached with pending tool calls (e.g., tool execution timed
out or failed to respond), the agent enters the summarizing phase but leaves
uncompleted tool calls in memory.

This causes IllegalStateException on the next user message:
Cannot add messages without tool results when pending tool calls exist.
Pending IDs: [call_638e428da2cf48ceb8b05762]

Root Cause

The summarizing() method doesn't handle pending tool calls before generating
the summary. When the user sends a new message, doCall() detects pending
tool calls but the message doesn't contain tool results, triggering the
validation error.

Solution

In summarizing(), automatically add error ToolResultBlocks for all pending
tool calls before generating the summary. The error message indicates the
tool was cancelled due to max iterations limit.

Changes

  • ReActAgent.java: Added logic in summarizing() to handle pending tool
    calls
  • ReActAgentSummarizingTest.java: Added test case
    testSecondCallAfterMaxItersWithPendingToolCalls to verify the fix

Testing

  • ✅ All existing tests pass (39 tests)
  • ✅ New test verifies second call after maxIters doesn't throw exception
  • ✅ Compilation successful

@Fancy-hjyp Fancy-hjyp requested a review from a team March 21, 2026 14:24
@cla-assistant
Copy link

cla-assistant bot commented Mar 21, 2026

CLA assistant check
All committers have signed the CLA.

@cla-assistant
Copy link

cla-assistant bot commented Mar 21, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov
Copy link

codecov bot commented Mar 21, 2026

Codecov Report

❌ Patch coverage is 0% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...e/src/main/java/io/agentscope/core/ReActAgent.java 0.00% 18 Missing and 1 partial ⚠️

📢 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]:超过了 maxIters 次数,再次发送消息报错

1 participant