Skip to content

fix: handle tool execution timeout/error causing IllegalStateExceptio…#956

Open
chensk0601 wants to merge 1 commit intoagentscope-ai:mainfrom
chensk0601:fix/951-react-agent-tool-execution-error-handling
Open

fix: handle tool execution timeout/error causing IllegalStateExceptio…#956
chensk0601 wants to merge 1 commit intoagentscope-ai:mainfrom
chensk0601:fix/951-react-agent-tool-execution-error-handling

Conversation

@chensk0601
Copy link

…n (#951)

ReActAgent throws IllegalStateException when tool calls timeout or fail, because no tool result is written to memory, leaving orphaned pending tool call states that crash the agent on subsequent requests.

Root cause:

  • Tool execution timeout/error propagates without writing results to memory
  • Pending tool call state remains, blocking subsequent doCall() invocations
  • validateAndAddToolResults() throws when user message has no tool results

Changes:

  • doCall(): detect pending tool calls without user-provided results and auto-generate error results to clear the pending state
  • executeToolCalls(): add onErrorResume to catch tool execution failures and generate error tool results instead of propagating exceptions
  • Add generateAndAddErrorToolResults() helper to create error results for orphaned pending tool calls

This ensures the agent recovers gracefully from tool failures instead of crashing, and the model receives proper error feedback to continue processing.

Closes #951

AgentScope-Java Version

[The version of AgentScope-Java you are working on, e.g. 1.0.9, check your pom.xml dependency version or run mvn dependency:tree | grep agentscope-parent:pom(only mac/linux)]

Description

[Please describe the background, purpose, changes made, and how to test this PR]

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

@chensk0601 chensk0601 requested a review from a team March 14, 2026 06:38
@cla-assistant
Copy link

cla-assistant bot commented Mar 14, 2026

CLA assistant check
All committers have signed the CLA.

@cla-assistant
Copy link

cla-assistant bot commented Mar 14, 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.


凡勇 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

agentscope-ai#951)

ReActAgent throws IllegalStateException when tool calls timeout or fail,
because no tool result is written to memory, leaving orphaned pending
tool call states that crash the agent on subsequent requests.

Root cause:
- Tool execution timeout/error propagates without writing results to memory
- Pending tool call state remains, blocking subsequent doCall() invocations
- validateAndAddToolResults() throws when user message has no tool results

Changes:
- doCall(): detect pending tool calls without user-provided results and
  auto-generate error results to clear the pending state
- executeToolCalls(): add onErrorResume to catch tool execution failures
  and generate error tool results instead of propagating exceptions
- Add generateAndAddErrorToolResults() helper to create error results
  for orphaned pending tool calls

This ensures the agent recovers gracefully from tool failures instead of
crashing, and the model receives proper error feedback to continue
processing.

Closes agentscope-ai#951
@chensk0601 chensk0601 force-pushed the fix/951-react-agent-tool-execution-error-handling branch from f3080ad to 86c49aa Compare March 14, 2026 07:00
@codecov
Copy link

codecov bot commented Mar 14, 2026

Codecov Report

❌ Patch coverage is 61.40351% with 22 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...e/src/main/java/io/agentscope/core/ReActAgent.java 61.40% 19 Missing and 3 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]: java.lang.IllegalStateException: Cannot add messages without tool results when pending tool calls exist. Pending IDs: [call_xxx]

1 participant