Fix streaming tool calls when reasoning parser is active#93
Open
janhilgard wants to merge 1 commit intowaybarrios:mainfrom
Open
Fix streaming tool calls when reasoning parser is active#93janhilgard wants to merge 1 commit intowaybarrios:mainfrom
janhilgard wants to merge 1 commit intowaybarrios:mainfrom
Conversation
The reasoning parser branch in stream_chat_completion() was missing tool call parsing entirely. When both --reasoning-parser and --tool-call-parser were enabled, streaming responses would emit raw tool call markup (e.g. <tool_call><function=...>) as plain content text instead of structured tool_calls objects. This adds tool call parsing to the reasoning parser branch, mirroring the existing logic in the standard (non-reasoning) path. Tool calls are now correctly detected, buffered during accumulation, and emitted as structured tool_calls with finish_reason="tool_calls". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
--reasoning-parseris enabledstream_chat_completion()was skipping tool call parsing entirely, causing<tool_call>markup to leak intocontentinstead of being parsed into structuredtool_callsobjectsProblem
When both
--reasoning-parser deepseek_r1and--tool-call-parser hermesare enabled, streaming responses emit raw tool call markup as plain text:{"delta": {"content": "<tool_call>\n<function=get_weather>\n<parameter=location>\nPrague\n</parameter>\n</function>\n</tool_call>", "tool_calls": null}, "finish_reason": "stop"}Fix
After this change, tool calls are correctly parsed and emitted:
{"delta": {"tool_calls": [{"index": 0, "id": "call_4b99a63b", "type": "function", "function": {"name": "get_weather", "arguments": "{\"location\": \"Prague\"}"}}]}, "finish_reason": "tool_calls"}Test plan
--reasoning-parser deepseek_r1 --tool-call-parser hermesreturns structuredtool_callsfinish_reasonis"tool_calls"(not"stop")blackformatting passes🤖 Generated with Claude Code