Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -2166,7 +2167,10 @@ private void emitBlockEvents(
blockLifecycle.startText(events);
if (tb.getText() != null && !tb.getText().isEmpty()) {
events.add(
new TextBlockDeltaEvent(blockLifecycle.replyId, "text", tb.getText()));
new TextBlockDeltaEvent(
blockLifecycle.replyId,
blockLifecycle.textBlockId(),
tb.getText()));
}
} else if (block instanceof ThinkingBlock tb) {
blockLifecycle.startThinking(events);
Expand Down Expand Up @@ -2203,6 +2207,8 @@ private final class ModelCallBlockLifecycle {
private final AtomicBoolean textStarted = new AtomicBoolean(false);
private final AtomicBoolean thinkingStarted = new AtomicBoolean(false);
private final Map<String, String> startedToolCalls = new ConcurrentHashMap<>();
private final AtomicInteger textBlockCounter = new AtomicInteger(0);
private volatile String currentTextBlockId;

private ModelCallBlockLifecycle(String replyId) {
this.replyId = replyId;
Expand All @@ -2211,10 +2217,15 @@ private ModelCallBlockLifecycle(String replyId) {
private void startText(List<AgentEvent> events) {
flushThinking(events);
if (textStarted.compareAndSet(false, true)) {
events.add(new TextBlockStartEvent(replyId, "text"));
currentTextBlockId = replyId + "_text_" + textBlockCounter.incrementAndGet();
events.add(new TextBlockStartEvent(replyId, currentTextBlockId));
}
}

String textBlockId() {
return currentTextBlockId;
}

private void startThinking(List<AgentEvent> events) {
if (thinkingStarted.compareAndSet(false, true)) {
events.add(new ThinkingBlockStartEvent(replyId, "thinking"));
Expand All @@ -2236,7 +2247,7 @@ private void startToolCall(String toolId, String toolName, List<AgentEvent> even

private void flushText(List<AgentEvent> events) {
if (textStarted.compareAndSet(true, false)) {
events.add(new TextBlockEndEvent(replyId, "text"));
events.add(new TextBlockEndEvent(replyId, currentTextBlockId));
}
}

Expand Down Expand Up @@ -3130,7 +3141,8 @@ private Flux<AgentEvent> summaryModelCallStream(
new TextBlockDeltaEvent(
blockLifecycle
.replyId,
"text",
blockLifecycle
.textBlockId(),
tb.getText()));
}
} else if (block
Expand Down
Loading