Skip to content

fix(react): continue after empty model responses#2355

Open
Zbhbb wants to merge 7 commits into
agentscope-ai:mainfrom
Zbhbb:codex/empty-model-response-loop
Open

fix(react): continue after empty model responses#2355
Zbhbb wants to merge 7 commits into
agentscope-ai:mainfrom
Zbhbb:codex/empty-model-response-loop

Conversation

@Zbhbb

@Zbhbb Zbhbb commented Jul 22, 2026

Copy link
Copy Markdown

AgentScope-Java Version

2.0.1-SNAPSHOT

Description

When a model returns an empty stream or only blank/whitespace text, the ReAct loop currently ends before it can produce a final response. Continue the existing bounded loop for those genuinely empty responses while preserving thinking-only completion, tool execution, middleware-stop, and max-iteration summary behavior.

This is distinct from #1508: that change made empty result streams complete; this change continues the existing bounded ReAct loop so the model can produce a usable response.

Changes

  • Continue to the next iteration after a reasoning round accumulates no final message.
  • Continue after blank or whitespace-only text, but keep thinking-only responses as a normal terminal result.
  • Resume at the loop boundary so a recovered response passes through post-reasoning exactly once.
  • Add regression coverage for empty stream, empty text, post-reasoning invocation count, and max-iteration summary behavior.

Test Plan

  • mvn -q -T1 verify
  • mvn -pl agentscope-core -am -Dtest=ReActAgentNewLoopReplyTest,ReActAgentThinkingCumulativeTest,ReActAgentHitlTest test

Checklist

  • Code has been formatted with mvn spotless:apply
  • Relevant tests are passing
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been reviewed
  • Code is ready for review

Copilot AI review requested due to automatic review settings July 22, 2026 09:34

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 adjusts the ReActAgent loop so that when the model produces an unusable response (empty stream / empty accumulated message / thinking-only / blank text), the agent continues the bounded ReAct loop to obtain a usable final assistant message, and adds regression tests for these edge cases.

Changes:

  • Continue the ReAct iteration when a reasoning round accumulates no final message (e.g., empty stream / blank text that results in no accumulated content).
  • Continue to the next iteration when the model returns thinking-only or blank/whitespace-only text (while persisting thinking context).
  • Add regression tests covering empty stream, empty text, thinking-only, and max-iteration summary behavior.

Reviewed changes

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

File Description
agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java Updates the ReAct loop to continue iterations after unusable model responses and adds a helper to detect “no usable response” cases.
agentscope-core/src/test/java/io/agentscope/core/agent/ReActAgentNewLoopReplyTest.java Adds regression tests for empty-stream, empty-text, thinking-only, and max-iteration summary paths.

Comment thread agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java
@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 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.

2 participants