From 7dcc24573fb4cdb6e0ec19fbf5d1abd415254c38 Mon Sep 17 00:00:00 2001 From: alexsand1 <51639043+alexsand1@users.noreply.github.com> Date: Sun, 14 Jun 2026 19:55:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9streamEvents=E7=9A=84?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/agentscope/core/ReActAgent.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java b/agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java index 0fd76fed6..489ed88dd 100644 --- a/agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java +++ b/agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java @@ -2107,7 +2107,15 @@ private void emitBlockEvents( List events) { if (block instanceof TextBlock tb) { + + if (textStarted.compareAndSet(false, true)) { + if (thinkingStarted.get()) { + events.add(new ThinkingBlockEndEvent(replyId, "thinking")); + thinkingStarted.set(false); + } + + events.add(new TextBlockStartEvent(replyId, "text")); } if (tb.getText() != null && !tb.getText().isEmpty()) { @@ -2115,16 +2123,33 @@ private void emitBlockEvents( } } else if (block instanceof ThinkingBlock tb) { if (thinkingStarted.compareAndSet(false, true)) { + + if (textStarted.get()) { + events.add(new TextBlockEndEvent(replyId, "text")); + textStarted.set(false); + } + events.add(new ThinkingBlockStartEvent(replyId, "thinking")); } if (tb.getThinking() != null && !tb.getThinking().isEmpty()) { events.add(new ThinkingBlockDeltaEvent(replyId, "thinking", tb.getThinking())); } } else if (block instanceof ToolUseBlock tub) { + String toolId = resolveToolCallId(tub, context); String toolName = tub.getName(); if (toolId != null && startedToolCalls.putIfAbsent(toolId, toolName) == null) { if (toolName != null && !toolName.startsWith("__")) { + + if (thinkingStarted.get()) { + events.add(new ThinkingBlockEndEvent(replyId, "thinking")); + thinkingStarted.set(false); + } + + if (textStarted.get()) { + events.add(new TextBlockEndEvent(replyId, "text")); + textStarted.set(false); + } events.add(new ToolCallStartEvent(replyId, toolId, toolName)); } } From b2c29efb544b61e290f44eee75cbb32a74295ff8 Mon Sep 17 00:00:00 2001 From: alexsand1 <51639043+alexsand1@users.noreply.github.com> Date: Sun, 14 Jun 2026 20:38:47 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9streamEvents=E7=9A=84?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/io/agentscope/core/ReActAgent.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java b/agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java index 489ed88dd..d5d2f6f8a 100644 --- a/agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java +++ b/agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java @@ -2138,6 +2138,7 @@ private void emitBlockEvents( String toolId = resolveToolCallId(tub, context); String toolName = tub.getName(); + Map preStartToolCalls = new HashMap<>(startedToolCalls); if (toolId != null && startedToolCalls.putIfAbsent(toolId, toolName) == null) { if (toolName != null && !toolName.startsWith("__")) { @@ -2150,6 +2151,15 @@ private void emitBlockEvents( events.add(new TextBlockEndEvent(replyId, "text")); textStarted.set(false); } + for (Map.Entry tc : preStartToolCalls.entrySet()) { + events.add( + new ToolCallEndEvent( + replyId, tc.getKey(), tc.getValue())); + startedToolCalls.remove(tc.getKey()); + } + + + events.add(new ToolCallStartEvent(replyId, toolId, toolName)); } }