fix: parse tool calls in streaming reasoning branch#177
Open
Thump604 wants to merge 2 commits intowaybarrios:mainfrom
Open
fix: parse tool calls in streaming reasoning branch#177Thump604 wants to merge 2 commits intowaybarrios:mainfrom
Thump604 wants to merge 2 commits intowaybarrios:mainfrom
Conversation
This was referenced Mar 21, 2026
When reasoning parsing is enabled, the streaming handler uses an if/else structure where the reasoning parser branch and tool parser branch are mutually exclusive. This means tool calls in streaming responses are never parsed when reasoning is enabled — they come through as raw XML text instead of structured tool_calls. Fix: Add tool call accumulation and parsing inside the reasoning parser branch, operating on delta_msg.content (the content portion after reasoning extraction). Handles all three tool parser outcomes: suppress (inside markup), emit structured tool_calls, or pass through content. Also fixes finish_reason to return "tool_calls" when tools were detected in the reasoning branch, matching the behavior of the standard path.
7b72f19 to
6680b18
Compare
6 tasks
This was referenced Mar 24, 2026
This was referenced Mar 30, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix streaming when both reasoning (thinking) tags and tool calls appear in the same response.
Before: reasoning parser consumed
<think>content but left artifacts that broke tool call parsing downstream.After: reasoning extraction runs first, cleaned text passed to tool parser.
Files:
server.pystreaming handlerTest: Send a request with tools enabled and a model that uses
<think>tags. Response should have bothreasoning_contentandtool_callspopulated correctly.