Repository navigation
fix(core): simplify ReActAgent pending tool and error result handling - #2666
Conversation
There was a problem hiding this comment.
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
ReActAgentwith 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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 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
left a comment
There was a problem hiding this comment.
🤖 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).
Summary
ReActAgent.summarizing()by directly checking the extracted pending tool calls.ToolResultBlock.stateUpdatesmap fromapplyConfirmResults.[ERROR]marker behavior.Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)