Skip to content

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

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

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

Conversation

@Zbhbb

@Zbhbb Zbhbb commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

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!

@oss-maintainer oss-maintainer 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.

LGTM. Looks good.


Automated review by "github-manager-bot"

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core/agent Agent runtime, pipeline, hooks, plan labels Aug 11, 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 adds resilience to ReActAgent's reasoning loop when the model returns empty or blank-only responses. The agent retries by advancing to the next iteration, bounded by maxIters. The stop-requested path is correctly refactored to not trigger the retry. Good test coverage.

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

@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 adds resilience to ReActAgent's reasoning loop when the model returns empty or blank-only responses. The agent retries by advancing to the next iteration, bounded by maxIters. The stop-requested path is correctly refactored to not trigger the retry. Good test coverage.

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

@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 adds resilience to ReActAgent's reasoning loop when the model returns empty or blank-only responses. The agent retries by advancing to the next iteration, bounded by maxIters. The stop-requested path is correctly refactored to not trigger the retry. Good test coverage.

Comment thread agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java
Comment thread agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java
Comment thread agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java
@Zbhbb
Zbhbb force-pushed the codex/empty-model-response-loop branch 4 times, most recently from 7407965 to dac175a Compare August 18, 2026 12:56
@Zbhbb
Zbhbb force-pushed the codex/empty-model-response-loop branch 4 times, most recently from b433483 to 2f0ac3b Compare August 22, 2026 08:01
@Zbhbb
Zbhbb force-pushed the codex/empty-model-response-loop branch from 2f0ac3b to 4e33938 Compare August 24, 2026 03:05
@Zbhbb

Zbhbb commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

已查看失败 job 的完整日志。该次失败不是 ReActAgent 逻辑或 #2355 新增测试断言失败,而是 agentscope-harness 中既有的 JsonSessionDefaultLocationTest 在 JUnit @tempdir 清理阶段发生竞态:perUserPartitioning_viaSharedAgentRoutedByRuntimeContext 结束时报告 Failed to close extension context,根因是 Failed to delete temp directory,抑制异常为 DirectoryNotEmptyException。#2355 的改动仅涉及 agentscope-core/ReActAgent.java 及其两个测试文件,没有修改 agentscope-harness;本地执行 mvn -q -pl agentscope-harness -am test 已成功。

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