diff --git a/agentscope-core/src/main/java/io/agentscope/core/agent/EventType.java b/agentscope-core/src/main/java/io/agentscope/core/agent/EventType.java index 431ef16518..3810866168 100644 --- a/agentscope-core/src/main/java/io/agentscope/core/agent/EventType.java +++ b/agentscope-core/src/main/java/io/agentscope/core/agent/EventType.java @@ -67,13 +67,17 @@ public enum EventType { * Final result event - The agent's complete response. * *

This is the message returned by {@link Agent#call(io.agentscope.core.message.Msg)}. - * By default, this event is NOT included in the stream to avoid duplication since it's the return value. + * In streaming APIs, this event is emitted whenever {@link StreamOptions} includes + * {@link #AGENT_RESULT} explicitly or uses {@link #ALL}. Since the default + * {@link StreamOptions} configuration uses {@link #ALL}, {@code AGENT_RESULT} is streamed + * by default. * *

Characteristics: *

*/ AGENT_RESULT, @@ -91,7 +95,7 @@ public enum EventType { SUMMARY, /** - * Special value to stream all event types (except {@link #AGENT_RESULT}). + * Special value to stream all event types, including {@link #AGENT_RESULT}. * *

Use this in {@link StreamOptions} to receive all events without filtering. */ diff --git a/agentscope-core/src/test/java/io/agentscope/core/agent/AgentStreamingTest.java b/agentscope-core/src/test/java/io/agentscope/core/agent/AgentStreamingTest.java index 79e90657b4..e8327197fd 100644 --- a/agentscope-core/src/test/java/io/agentscope/core/agent/AgentStreamingTest.java +++ b/agentscope-core/src/test/java/io/agentscope/core/agent/AgentStreamingTest.java @@ -114,6 +114,29 @@ void testStreamWithIncludeAgentResult() { assertNotNull(lastEvent.getMessage()); } + @Test + void testStreamWithAllIncludesAgentResult() { + TestStreamingAgent agent = new TestStreamingAgent("test-agent"); + agent.setResponseText("Response"); + + Msg inputMsg = + Msg.builder() + .name("user") + .role(MsgRole.USER) + .content(List.of(TextBlock.builder().text("Test").build())) + .build(); + + StreamOptions options = StreamOptions.builder().eventTypes(EventType.ALL).build(); + + List events = new ArrayList<>(); + agent.stream(inputMsg, options).doOnNext(events::add).blockLast(); + + assertFalse(events.isEmpty()); + Event lastEvent = events.get(events.size() - 1); + assertEquals(EventType.AGENT_RESULT, lastEvent.getType()); + assertTrue(lastEvent.isLast()); + } + @Test void testStreamWithSpecificEventTypes() { TestStreamingAgent agent = new TestStreamingAgent("test-agent"); diff --git a/docs/v1/en/docs/task/streaming.md b/docs/v1/en/docs/task/streaming.md index 3931b702de..d30c33757f 100644 --- a/docs/v1/en/docs/task/streaming.md +++ b/docs/v1/en/docs/task/streaming.md @@ -43,8 +43,8 @@ Flux events = agent.stream(msgs, StreamOptions.defaults(), ctx); | `TOOL_RESULT` | After each tool execution | `ToolResultBlock` (tool name, id, output) | | `HINT` | After RAG / memory retrieval | Context text injected into the model | | `SUMMARY` | When `maxIters` is reached | Iteration summary text | -| `AGENT_RESULT` | Final reply ready | Same as `call()` return value; **not included** in stream by default | -| `ALL` | Placeholder for all the above (except `AGENT_RESULT`) | — | +| `AGENT_RESULT` | Final reply ready | Same as `call()` return value | +| `ALL` | Placeholder for all event types | - | ### Subscribe to specific types only @@ -153,7 +153,7 @@ serialize `event.getSource()` as well — see [Harness Subagent Streaming](../ha ```java StreamOptions options = StreamOptions.builder() - // Event types to receive (default: ALL, excluding AGENT_RESULT) + // Event types to receive (default: ALL) .eventTypes(EventType.REASONING, EventType.TOOL_RESULT, EventType.AGENT_RESULT) // Incremental mode: true = push deltas (default), false = push full accumulated text diff --git a/docs/v1/zh/docs/task/streaming.md b/docs/v1/zh/docs/task/streaming.md index aa23d71b94..686770eeb7 100644 --- a/docs/v1/zh/docs/task/streaming.md +++ b/docs/v1/zh/docs/task/streaming.md @@ -43,8 +43,8 @@ Flux events = agent.stream(msgs, StreamOptions.defaults(), ctx); | `TOOL_RESULT` | 每次工具执行完毕后 | `ToolResultBlock`(含工具名、id、输出) | | `HINT` | RAG / 记忆检索注入后 | 注入模型的上下文文本 | | `SUMMARY` | 达到 `maxIters` 上限时 | 迭代摘要文本 | -| `AGENT_RESULT` | 最终回复就绪 | 与 `call()` 返回值相同,默认**不在**流中 | -| `ALL` | 占位符,代表全部(不含 `AGENT_RESULT`) | — | +| `AGENT_RESULT` | 最终回复就绪 | 与 `call()` 返回值相同 | +| `ALL` | 占位符,代表全部事件类型 | - | ### 只订阅指定类型 @@ -151,7 +151,7 @@ public Flux> chat(@RequestParam String message) { ```java StreamOptions options = StreamOptions.builder() - // 订阅的事件类型(默认 ALL,不含 AGENT_RESULT) + // 订阅的事件类型(默认 ALL) .eventTypes(EventType.REASONING, EventType.TOOL_RESULT, EventType.AGENT_RESULT) // 增量模式(默认 true)