Skip to content

fix: parse tool calls in streaming reasoning branch#177

Open
Thump604 wants to merge 2 commits intowaybarrios:mainfrom
Thump604:fix/streaming-reasoning-tool-coexistence-v2
Open

fix: parse tool calls in streaming reasoning branch#177
Thump604 wants to merge 2 commits intowaybarrios:mainfrom
Thump604:fix/streaming-reasoning-tool-coexistence-v2

Conversation

@Thump604
Copy link
Copy Markdown
Contributor

@Thump604 Thump604 commented Mar 18, 2026

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.py streaming handler

Test: Send a request with tools enabled and a model that uses <think> tags. Response should have both reasoning_content and tool_calls populated correctly.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant