[Bug]:ReActAgent.stream(...) never completes when the model returns empty assistant content
AgentScope-Java is an open-source project. To involve a broader community, we recommend asking your questions in English.
Describe the bug
When a model returns an assistant message with empty text content and no tool calls, ReActAgent.stream(...) may never complete.
In this case, the model response is effectively:
[
{
"role": "assistant",
"content": ""
}
]
The stream does not emit a final result or complete normally, so downstream integrations waiting for stream completion can hang indefinitely.
To Reproduce
Steps to reproduce the behavior:
-
Use a model implementation or mock model that streams exactly one assistant response with an empty
TextBlockand noToolUseBlock. -
Call
ReActAgent.stream(...), for example:
ReActAgent agent = ReActAgent.builder()
.name("test-agent")
.model(modelThatReturnsEmptyAssistantContent)
.build();
agent.stream(List.of(
Msg.builder()
.role(MsgRole.USER)
.textContent("hello")
.build()
)).blockLast();
- The stream does not complete. In an SSE integration, the final
RUN_FINISHEDor equivalent completion event is never sent.
Expected behavior
The stream should complete even if the model returns an empty assistant response.
Possible expected behaviors:
- Return an assistant
Msgwith empty text content and complete the stream. - Or complete the stream without a final message.
- Or throw a clear exception indicating that the model returned an invalid empty response.
In all cases, Agent.stream(...) should not hang indefinitely.
Error messages
There is no exception or error message.
The observable behavior is that the reactive stream never completes.
From source inspection, the possible cause seems to be:
TextAccumulator.hasContent()returnsfalsefor empty text because it checksaccumulated.length() > 0.ReasoningContext.buildFinalMessage()returnsnullwhen there is no text, thinking content, or tool call.ReActAgent.reasoning()usesMono.justOrEmpty(context.buildFinalMessage()), which becomesMono.empty().AgentBase.createEventStream()only callssink.complete()in theonNextcallback of the final message subscription. If theMonois empty, noonNextis invoked and theFluxSinkis never completed.
Environment (please complete the following information):
- AgentScope-Java Version: 1.1.0-RC1
- Java Version: 21
- OS: Windows 10
Additional context
This issue affects integrations that rely on Agent.stream(...) completion, such as SSE or AG-UI style adapters. If the upstream model returns an empty assistant message, the client keeps waiting because the server-side stream never reaches its normal finish logic.