Skip to content

[Bug]:fix(ReActAgent): Tool not found should return error message instead of stopping iteration #849

@luoxiner

Description

@luoxiner

Problem Description

In ReActAgent.isFinished() method (line 755), when the model generates a tool call that doesn't exist in the toolkit, the current logic immediately terminates the ReAct loop instead of providing feedback to the model.

Current Behavior

// Line 755 in ReActAgent.java
return toolCalls.stream().noneMatch(tc -> toolkit.getTool(tc.getName()) != null);

When the model calls a non-existent tool, isFinished() returns true, causing the agent to stop without executing the acting phase.

Expected Behavior

The agent should:

  1. Continue to the acting() phase
  2. Execute the tool call and return a "tool not found" error message
  3. Add the error to memory so the model can see it in the next iteration
  4. Allow the model to correct itself or try alternative approaches

Root Cause

The isFinished() method treats "no valid tools" as a termination condition, but this prevents the model from receiving error feedback about invalid tool calls.

Suggested Solution

  1. Remove the tool existence check from isFinished() - let it only check if there are tool calls
  2. Handle non-existent tools in acting() phase by returning proper error messages
  3. The Toolkit's callTools() method should already handle this, so we may just need to remove the early termination logic

Impact

This issue prevents the model from learning and recovering from invalid tool calls, reducing agent robustness.

Location

File: agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java
Method: isFinished(Msg msg) (around line 755)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions