-
Notifications
You must be signed in to change notification settings - Fork 845
修改streamEvents的输出顺序 #1758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
修改streamEvents的输出顺序 #1758
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2107,24 +2107,59 @@ private void emitBlockEvents( | |
| List<AgentEvent> events) { | ||
|
|
||
| if (block instanceof TextBlock tb) { | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] Multiple consecutive blank lines (here lines 2110–2111, 2117–2118, 2160–2162) hurt readability. Run |
||
|
|
||
| if (textStarted.compareAndSet(false, true)) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [minor] Missing test coverage: This PR changes the event-ordering state machine (a correctness-critical contract), but the existing
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [minor] Missing test coverage: This PR changes the event-ordering state machine (a correctness-critical contract), but the existing
|
||
| 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()) { | ||
| events.add(new TextBlockDeltaEvent(replyId, "text", tb.getText())); | ||
| } | ||
| } 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(); | ||
| Map<String, String> preStartToolCalls = new HashMap<>(startedToolCalls); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [minor] Minor inefficiency:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [minor] Minor inefficiency: |
||
| 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); | ||
| } | ||
| for (Map.Entry<String, String> tc : preStartToolCalls.entrySet()) { | ||
| events.add( | ||
| new ToolCallEndEvent( | ||
| replyId, tc.getKey(), tc.getValue())); | ||
| startedToolCalls.remove(tc.getKey()); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [major] Bug: After emitting This cannot happen with today's sequential tool-call streaming (OpenAI, Anthropic), but it is a latent correctness bug that will surface the moment any provider interleaves tool-call chunks. Fix: Use a separate Set<String> closedToolCalls = new HashSet<>();
// ...
for (Map.Entry<String, String> tc : preStartToolCalls.entrySet()) {
if (closedToolCalls.add(tc.getKey())) {
events.add(new ToolCallEndEvent(replyId, tc.getKey(), tc.getValue()));
}
}Keep
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [major] Bug: After emitting This cannot happen with today's sequential tool-call streaming (OpenAI, Anthropic), but it is a latent correctness bug that will surface the moment any provider interleaves tool-call chunks. Fix: Use a separate Set<String> closedToolCalls = new HashSet<>();
// ...
for (Map.Entry<String, String> tc : preStartToolCalls.entrySet()) {
if (closedToolCalls.add(tc.getKey())) {
events.add(new ToolCallEndEvent(replyId, tc.getKey(), tc.getValue()));
}
}Keep |
||
| } | ||
|
|
||
|
|
||
|
|
||
| events.add(new ToolCallStartEvent(replyId, toolId, toolName)); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] Multiple consecutive blank lines (here lines 2110–2111, 2117–2118, 2160–2162) hurt readability. Run
mvn spotless:applyto normalize formatting — the PR checklist item is unchecked.