Skip to content

Commit 18150b3

Browse files
authored
Handle partial events in console launcher (google#219)
1 parent b81ab80 commit 18150b3

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

‎cmd/launcher/console/console.go‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func (l *Launcher) Run(ctx context.Context, config *adk.Config) error {
103103
streamingMode = agent.StreamingModeSSE
104104
}
105105
fmt.Print("\nAgent -> ")
106+
prevText := ""
106107
for event, err := range r.Run(ctx, userID, session.ID(), userMsg, agent.RunConfig{
107108
StreamingMode: streamingMode,
108109
}) {
@@ -112,12 +113,30 @@ func (l *Launcher) Run(ctx context.Context, config *adk.Config) error {
112113
if event.LLMResponse.Content == nil {
113114
continue
114115
}
116+
117+
text := ""
115118
for _, p := range event.LLMResponse.Content.Parts {
116-
// if its running in streaming mode, don't print the non partial llmResponses
117-
if streamingMode != agent.StreamingModeSSE || event.LLMResponse.Partial {
118-
fmt.Print(p.Text)
119-
}
119+
text += p.Text
120+
}
121+
122+
if streamingMode != agent.StreamingModeSSE {
123+
fmt.Print(text)
124+
continue
125+
}
126+
127+
// In SSE mode, always print partial responses and capture them.
128+
if !event.IsFinalResponse() {
129+
fmt.Print(text)
130+
prevText += text
131+
continue
120132
}
133+
134+
// Only print final response if it doesn't match previously captured text.
135+
if text != prevText {
136+
fmt.Print(text)
137+
}
138+
139+
prevText = ""
121140
}
122141
}
123142
}

0 commit comments

Comments
 (0)