-
Notifications
You must be signed in to change notification settings - Fork 706
fix(agent): complete stream when result is empty #1508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,10 +20,13 @@ | |
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import io.agentscope.core.ReActAgent; | ||
| import io.agentscope.core.agent.test.MockModel; | ||
| import io.agentscope.core.interruption.InterruptContext; | ||
| import io.agentscope.core.message.Msg; | ||
| import io.agentscope.core.message.MsgRole; | ||
| import io.agentscope.core.message.TextBlock; | ||
| import io.agentscope.core.model.ChatResponse; | ||
| import java.time.Duration; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
@@ -248,4 +251,38 @@ void testStreamEventCount() { | |
| // Should have at least one event (the agent result) | ||
| assertTrue(eventCount.get() >= 1); | ||
| } | ||
|
|
||
| @Test | ||
| void testReActAgentStreamCompletesWhenModelReturnsEmptyText() { | ||
| MockModel model = | ||
| new MockModel( | ||
| messages -> | ||
| List.of( | ||
| ChatResponse.builder() | ||
| .id("empty-msg") | ||
| .content( | ||
| List.of( | ||
| TextBlock.builder() | ||
| .text("") | ||
| .build())) | ||
| .build())); | ||
| ReActAgent agent = ReActAgent.builder().name("test-agent").model(model).build(); | ||
|
|
||
| Msg inputMsg = | ||
| Msg.builder() | ||
| .name("user") | ||
| .role(MsgRole.USER) | ||
| .content(List.of(TextBlock.builder().text("hello").build())) | ||
| .build(); | ||
|
|
||
| StepVerifier.create(agent.stream(List.of(inputMsg))) | ||
| .expectNextMatches( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] The test relies on at least one |
||
| event -> | ||
| event.getType() == EventType.REASONING | ||
| && !event.isLast() | ||
| && event.getMessage() != null) | ||
| .thenConsumeWhile(event -> true) | ||
| .expectComplete() | ||
| .verify(Duration.ofSeconds(2)); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[minor] Consider also emitting a synthetic
AGENT_RESULT(or at least a placeholder empty assistantMsg) when the upstreamMonocompletes empty, so downstream SSE / AG-UI adapters that key offAGENT_RESULTas the terminal event still receive a final marker. The current fix correctly unblocks completion, but consumers that loop until they observe anAGENT_RESULTwill now silently terminate without one. If keeping the current behavior intentionally, please document it in the Javadoc ofcreateEventStream(e.g. "if the agent call produces no final message, the stream completes without emitting an AGENT_RESULT event").