Skip to content

Commit 174cec0

Browse files
authored
fix(stream): respect StreamOptions config for event emission (#411)
1 parent 6486596 commit 174cec0

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

agentscope-core/src/main/java/io/agentscope/core/agent/AgentBase.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -685,12 +685,14 @@ private Flux<Event> createEventStream(StreamOptions options, Supplier<Mono<Msg>>
685685
})
686686
.subscribe(
687687
finalMsg -> {
688-
Event finalEvent =
689-
new Event(
690-
EventType.AGENT_RESULT,
691-
finalMsg,
692-
true);
693-
sink.next(finalEvent);
688+
if (options.shouldStream(EventType.AGENT_RESULT)) {
689+
Event finalEvent =
690+
new Event(
691+
EventType.AGENT_RESULT,
692+
finalMsg,
693+
true);
694+
sink.next(finalEvent);
695+
}
694696

695697
// Complete the stream
696698
sink.complete();

agentscope-core/src/main/java/io/agentscope/core/agent/StreamingHook.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,16 @@ public <T extends HookEvent> Mono<T> onEvent(T event) {
6363
PostReasoningEvent e = (PostReasoningEvent) event;
6464
// postReasoning is called after streaming completes
6565
// This is the last/complete message
66-
if (options.shouldStream(EventType.REASONING)) {
66+
if (options.shouldStream(EventType.REASONING)
67+
&& options.shouldIncludeReasoningEmission(false)) {
6768
emitEvent(EventType.REASONING, e.getReasoningMessage(), true);
6869
}
6970
return Mono.just(event);
7071
} else if (event instanceof ReasoningChunkEvent) {
7172
ReasoningChunkEvent e = (ReasoningChunkEvent) event;
7273
// This is an intermediate chunk
73-
if (options.shouldStream(EventType.REASONING)) {
74+
if (options.shouldStream(EventType.REASONING)
75+
&& options.shouldIncludeReasoningEmission(true)) {
7476
// Use incremental or accumulated based on StreamOptions
7577
Msg msgToEmit =
7678
options.isIncremental() ? e.getIncrementalChunk() : e.getAccumulated();

0 commit comments

Comments
 (0)