Commit 8e64653
committed
fix(streaming): align finish_reason logic with non-streaming path
The streaming path (ChatCompletionsStreamingAdapter) now correctly maps
TOOL_SUSPENDED and MAX_ITERATIONS to finish_reason, matching the behavior
of the non-streaming path (ChatCompletionsResponseBuilder).
Previously, the streaming path only checked for ToolUseBlock presence,
which could lead to inconsistent behavior:
- TOOL_SUSPENDED was typically unaffected (ToolUseBlock always present)
- MAX_ITERATIONS would incorrectly return 'stop' instead of 'length'
Changes:
- Check event.getMessage().getGenerateReason() in isLast branch
- Map TOOL_SUSPENDED -> 'tool_calls'
- Map MAX_ITERATIONS -> 'length'
- Fall back to ToolUseBlock check for other cases
This ensures consistent finish_reason behavior between streaming and
non-streaming responses.
Resolves review comment from LearningGp.1 parent cfbe7d0 commit 8e64653
1 file changed
Lines changed: 18 additions & 3 deletions
File tree
- agentscope-extensions/agentscope-extensions-chat-completions-web/src/main/java/io/agentscope/core/chat/completions/streaming
Lines changed: 18 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
250 | 251 | | |
251 | 252 | | |
252 | 253 | | |
253 | | - | |
254 | | - | |
255 | | - | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
256 | 271 | | |
257 | 272 | | |
258 | 273 | | |
| |||
0 commit comments