Skip to content

fix(core): simplify ReActAgent pending tool and error result handling - #2666

Merged
zouyx merged 2 commits into
mainfrom
optimize-react-agent
Aug 12, 2026
Merged

zouyx merged 2 commits into
mainfrom
optimize-react-agent

Conversation

@jujn

@jujn jujn commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Simplify ReActAgent.summarizing() by directly checking the extracted pending tool calls.
  • Move tool execution error-result construction into ToolResultBlock.
  • Remove the unused stateUpdates map from applyConfirmResults.
  • Preserve the existing error state and [ERROR] marker behavior.

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 lite review requested due to automatic review settings August 11, 2026 12:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors how ReActAgent generates tool-execution error results by centralizing the error-result construction into ToolResultBlock, and simplifies max-iteration summary handling by directly inspecting extracted pending tool calls.

Changes:

  • Introduces ToolResultBlock.error(toolId, errorMessage) for tool-call-scoped runtime errors (with [ERROR] marker).
  • Replaces inlined error ToolResultBlock construction in ReActAgent with the new factory method and simplifies pending-tool handling.
  • Adds unit coverage for the new tool-call error factory behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
agentscope-core/src/test/java/io/agentscope/core/message/ToolResultBlockTest.java Adds a test ensuring the new tool-call error factory preserves tool ID and [ERROR] output marker.
agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java Switches multiple runtime error-result creation sites to ToolResultBlock.error(toolId, ...) and simplifies pending-tool summary flow.
agentscope-core/src/main/java/io/agentscope/core/message/ToolResultBlock.java Adds a new overload to construct tool-call-scoped error results with [ERROR] marker.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
...e/src/main/java/io/agentscope/core/ReActAgent.java 62.50% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core/agent Agent runtime, pipeline, hooks, plan labels Aug 12, 2026

@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 refactors error tool-result construction in ReActAgent by extracting it from a private static helper (buildErrorToolResult) into a public factory method on ToolResultBlock. It also removes an unused stateUpdates map from applyConfirmResults, simplifies summarizing() by eliminating a redundant hasPendingToolUse() guard (avoiding a double scan of context), and fixes a double [ERROR] prefix bug in maybePatchPendingToolCalls where the caller was passing [ERROR] in the message while the helper was also prepending [ERROR]. The changes are clean, well-scoped, and behavior-preserving (except for the intentional bug fix).

@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 refactors error tool-result construction in ReActAgent by extracting it from a private static helper (buildErrorToolResult) into a public factory method on ToolResultBlock. It also removes an unused stateUpdates map from applyConfirmResults, simplifies summarizing() by eliminating a redundant hasPendingToolUse() guard (avoiding a double scan of context), and fixes a double [ERROR] prefix bug in maybePatchPendingToolCalls where the caller was passing [ERROR] in the message while the helper was also prepending [ERROR]. The changes are clean, well-scoped, and behavior-preserving (except for the intentional bug fix).

@zouyx
zouyx merged commit 5dcd133 into main Aug 12, 2026
6 checks passed
@jujn
jujn deleted the optimize-react-agent branch September 24, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core/agent Agent runtime, pipeline, hooks, plan bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants