Skip to content

fix(ReActAgent): allow tool calls to reach acting phase for proper er…#850

Merged
LearningGp merged 3 commits intoagentscope-ai:mainfrom
luoxiner:main
Mar 4, 2026
Merged

fix(ReActAgent): allow tool calls to reach acting phase for proper er…#850
LearningGp merged 3 commits intoagentscope-ai:mainfrom
luoxiner:main

Conversation

@luoxiner
Copy link
Contributor

@luoxiner luoxiner commented Mar 2, 2026

…ror feedback

When model generates tool calls that don't exist in toolkit, the isFinished() method was prematurely terminating the ReAct loop, preventing the model from receiving error feedback.

Now tool calls (even non-existent ones) proceed to the acting phase where ToolExecutor returns 'Tool not found' error. This allows the model to see the error in memory and self-correct in the next iteration.

Simplified isFinished() to only check if there are tool calls, removing the toolkit existence check since error handling is already properly implemented in ToolExecutor.executeCore().

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

…ror feedback

When model generates tool calls that don't exist in toolkit, the isFinished()
method was prematurely terminating the ReAct loop, preventing the model from
receiving error feedback.

Now tool calls (even non-existent ones) proceed to the acting phase where
ToolExecutor returns 'Tool not found' error. This allows the model to see
the error in memory and self-correct in the next iteration.

Simplified isFinished() to only check if there are tool calls, removing the
toolkit existence check since error handling is already properly implemented
in ToolExecutor.executeCore().

Change-Id: Ief1746255898fce715263b456d68f7c14d2a21d8
@luoxiner luoxiner requested review from a team and Copilot March 2, 2026 09:37
@cla-assistant
Copy link

cla-assistant bot commented Mar 2, 2026

CLA assistant check
All committers have signed the CLA.

@cla-assistant
Copy link

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

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the "ReActAgent"'s tool call processing to enhance error feedback mechanisms. By adjusting the "isFinished" method, the agent now allows all generated tool calls to reach the execution phase, ensuring that the model receives explicit "Tool not found" errors for invalid tool references. This change facilitates better self-correction capabilities for the agent.

Highlights

  • ReActAgent Tool Call Handling: Modified the "isFinished()" method in "ReActAgent" to ensure that tool calls, even those referring to non-existent tools, proceed to the acting phase. This allows the "ToolExecutor" to provide explicit "Tool not found" error feedback to the model.
  • Improved Error Feedback: Prevented premature termination of the ReAct loop when a model generates calls to non-existent tools, enabling the model to receive error messages and self-correct in subsequent iterations.
Changelog
  • agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java
    • Simplified the "isFinished()" method logic to only check for the presence of tool calls, removing the previous check for tool existence within the toolkit.
Activity
  • The author has formatted the code with "mvn spotless:apply".
  • All tests are passing after the changes.
  • Javadoc comments have been completed and follow project conventions.
  • Related documentation has been updated.
  • The code has been marked as ready for review.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@luoxiner
Copy link
Contributor Author

luoxiner commented Mar 2, 2026

#849

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes premature termination of the ReAct loop when the model emits tool calls that aren’t present in the toolkit, ensuring those calls still reach the acting phase so ToolExecutor can record a “Tool not found …” error in memory for model self-correction.

Changes:

  • Simplified ReActAgent#isFinished() to terminate only when there are no tool calls.
  • Removed the “tool must exist in toolkit” finish condition so unknown tool calls proceed to acting and produce error tool results.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a bug in the ReActAgent where the agent would prematurely terminate if a model-generated tool call was for a tool not present in the toolkit. The change modifies the isFinished method to allow all tool calls, including those for non-existent tools, to proceed to the acting phase. This ensures that the ToolExecutor can generate a 'Tool not found' error, providing crucial feedback to the model for self-correction. The logic is now simpler and correctly delegates the error handling. The change is well-implemented and effectively resolves the issue.

@codecov
Copy link

codecov bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Collaborator

@LearningGp LearningGp left a comment

Choose a reason for hiding this comment

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

LGTM

@LearningGp LearningGp merged commit 63f7e92 into agentscope-ai:main Mar 4, 2026
6 checks passed
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.

3 participants