agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Bug]:ReActAgent.stream(...) never completes when the model returns empty assistant content

Open dragondyt opened this issue 6 months ago • 0 comments

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:

  1. Use a model implementation or mock model that streams exactly one assistant response with an empty TextBlock and no ToolUseBlock.

  2. 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();
  1. The stream does not complete. In an SSE integration, the final RUN_FINISHED or 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 Msg with 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() returns false for empty text because it checks accumulated.length() > 0.
  • ReasoningContext.buildFinalMessage() returns null when there is no text, thinking content, or tool call.
  • ReActAgent.reasoning() uses Mono.justOrEmpty(context.buildFinalMessage()), which becomes Mono.empty().
  • AgentBase.createEventStream() only calls sink.complete() in the onNext callback of the final message subscription. If the Mono is empty, no onNext is invoked and the FluxSink is 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.

dragondyt avatar May 27 '26 02:05 dragondyt