feat(agent): enhance event routing for reasoning and answers in streaming
- Introduced new tests to ensure correct routing of reasoning and answer content during streaming, addressing UX issues where answers appeared under the Thinking phase before transitioning. - Implemented a ThinkStreamSplitter to separate inline reasoning from answer text, allowing for real-time updates to the UI without duplication. - Updated the event emission logic to prevent re-emission of answers that were already streamed live, ensuring a seamless user experience. - Enhanced the ChatResponse struct to include flags for streamed answers, improving the handling of final answer events. - Added comprehensive unit tests for the ThinkStreamSplitter to validate its functionality across various scenarios.
This commit is contained in:
@@ -54,6 +54,19 @@ type ChatResponse struct {
|
||||
ToolCalls []LLMToolCall `json:"tool_calls,omitempty"`
|
||||
FinishReason string `json:"finish_reason,omitempty"`
|
||||
Usage TokenUsage `json:"usage"`
|
||||
|
||||
// AnswerStreamed reports whether the user-facing answer text was already
|
||||
// streamed live to the final-answer UI area during this round (i.e. the
|
||||
// model answered with plain content rather than via the final_answer
|
||||
// tool). When true, the natural-stop branch must only emit the closing
|
||||
// Done marker for AnswerEventID instead of re-emitting the whole answer —
|
||||
// otherwise the answer would render twice and "jump" at end of stream.
|
||||
// Transient, never persisted.
|
||||
AnswerStreamed bool `json:"-"`
|
||||
// AnswerEventID is the EventBus event ID under which the live answer
|
||||
// chunks were streamed, so the natural-stop branch can close the same
|
||||
// stream with a Done marker. Empty when AnswerStreamed is false.
|
||||
AnswerEventID string `json:"-"`
|
||||
}
|
||||
|
||||
// Response type
|
||||
|
||||
Reference in New Issue
Block a user