Skip to content

Commit 034bfdb

Browse files
committed
test: add test case
1 parent a558433 commit 034bfdb

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

agentscope-core/src/test/java/io/agentscope/core/tool/subagent/SubAgentToolTest.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,67 @@ void testEventForwardingEnabled() {
317317
assertTrue(metadata.containsKey("subagent_session_id"));
318318
}
319319

320+
@Test
321+
@DisplayName("Should forward event with default text block when content is empty")
322+
void testEventForwardingWithEmptyContent() {
323+
Agent mockAgent = mock(Agent.class);
324+
when(mockAgent.getName()).thenReturn("EmptyEventAgent");
325+
when(mockAgent.getDescription()).thenReturn("Agent that yields empty events");
326+
327+
// Create a message with NO content (null or empty list)
328+
Msg emptyResponseMsg =
329+
Msg.builder()
330+
.role(MsgRole.ASSISTANT)
331+
// Intentionally not setting content
332+
.build();
333+
334+
Event stateEvent = new Event(EventType.REASONING, emptyResponseMsg, false);
335+
336+
Msg finalMsg =
337+
Msg.builder()
338+
.role(MsgRole.ASSISTANT)
339+
.content(TextBlock.builder().text("Done").build())
340+
.build();
341+
Event endEvent = new Event(EventType.SUMMARY, finalMsg, true);
342+
343+
when(mockAgent.stream(any(List.class), any(StreamOptions.class)))
344+
.thenReturn(Flux.just(stateEvent, endEvent));
345+
346+
SubAgentConfig config = SubAgentConfig.builder().forwardEvents(true).build();
347+
SubAgentTool tool = new SubAgentTool(() -> mockAgent, config);
348+
349+
List<ToolResultBlock> emittedChunks = new ArrayList<>();
350+
ToolEmitter testEmitter = emittedChunks::add;
351+
352+
Map<String, Object> input = new HashMap<>();
353+
input.put("message", "Trigger");
354+
ToolUseBlock toolUse =
355+
ToolUseBlock.builder().id("1").name("call_emptyeventagent").input(input).build();
356+
357+
tool.callAsync(
358+
ToolCallParam.builder()
359+
.toolUseBlock(toolUse)
360+
.input(input)
361+
.emitter(testEmitter)
362+
.build())
363+
.block();
364+
365+
// We expect 2 chunks emitted
366+
assertEquals(2, emittedChunks.size());
367+
368+
// Verify the first chunk (the empty one)
369+
ToolResultBlock emptyChunk = emittedChunks.get(0);
370+
assertNotNull(emptyChunk.getOutput());
371+
assertEquals(1, emptyChunk.getOutput().size(), "Should insert a default empty block");
372+
assertTrue(emptyChunk.getOutput().get(0) instanceof TextBlock);
373+
assertEquals(
374+
"",
375+
((TextBlock) emptyChunk.getOutput().get(0)).getText(),
376+
"Default block should contain empty string");
377+
assertEquals(
378+
EventType.REASONING.name(), emptyChunk.getMetadata().get("subagent_event_type"));
379+
}
380+
320381
@Test
321382
@DisplayName("Should not use streaming when forwardEvents is false")
322383
void testEventForwardingDisabled() {

0 commit comments

Comments
 (0)