Repository navigation
Conversation
…as a call A reasoning model can write its tool call before it closes its reasoning block, which Qwen3 models do in long, multi-turn contexts. Only text outside reasoning reached the tool call parser, so the call was returned as reasoning_content, with finish_reason stop and no tool_calls, and nothing ran. ThinkTagParser takes exit markers: markers that end a tag-pair reasoning block as the close does but stay in the text that follows, so the tool call parser sees the call whole. A partial exit marker at the end of a delta is held back, and a close the model writes after the call is dropped rather than shown. llm-server passes its tool call format's open marker when a request offers tools, in both the streaming and non-streaming paths. CoreAILanguageModel does the same when the request enables tools. A request without tools keeps a <tool_call> in its reasoning as reasoning.
… arguments is kept The exit marker ended the reasoning wherever the open marker appeared, so a model that only mentioned `<tool_call>` while thinking lost the rest of its reasoning and its answer: the tool call parser held everything after the unclosed marker. And the late close was dropped anywhere after the exit, including inside the call's arguments. An exit marker now names the call's close as well as its open. The parser holds the text from the open marker until it can tell: the call is real when it closes and no close of the reasoning comes before another open marker. A close that comes first means a mention, and the reasoning goes on to it. A call the stream cuts off before it closes is reasoning, as it was. After a real call, a late close is dropped only outside a call, so the calls' arguments pass through untouched.
…h tests through the server - ServerState.parsesToolCalls(for:) decides whether a reply is parsed for tool calls: the request carries tools and the model has a format. The streaming path parsed every reply and the non-streaming one only a request with tools; both now follow it, and the reasoning's exit markers follow it too, so a reply splits the same way streamed or not. - ThinkTagParser.ExitMarker.forToolCalls(_:offered:) is the one place the markers come from, for the server and CoreAILanguageModel alike. - The server tests run a reply that writes its call before </think> through runChatCompletion and runStreamingLoop, and check the call comes back as a tool call with none of it in the reasoning.
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.
Adding New Models
N/A: no new model.
Type of Change
Motivation and Context
In long agent sessions, models sometimes write a tool call before they close their reasoning.
llm-serverthen returns the call as text inreasoning_content, withfinish_reason: stopand notool_calls, so the agent has nothing to run and the userhas to prompt again:
Why it happens: reasoning and tool calls are parsed in series, and only text outside reasoning reaches the tool call parser.
<think>\n, so the whole reply counts as reasoning until the model writes</think>.ThinkTagParseronly knows<think>and</think>, so a<tool_call>before the close is just more reasoning, andToolCallParsernever sees it.CoreAILanguageModelchains the same two parsers the same way.The fix: when a request offers tools, a tool call's open marker also ends the reasoning.
ThinkTagParsertakesexitMarkers. They end a reasoning block as the close does, but stay in the text, soToolCallParsergets the whole call.<tool_thencall>) is held back, not emitted as reasoning.</think>written after the call closes nothing, so it's dropped rather than shown as content.llm-server(streaming and non-streaming) andCoreAILanguageModelpass the tool format's open marker only when the request has tools. Without tools, nothing changes.Testing
Tested locally
Added/updated tests
Added/updated docs
New
ThinkTagParserTestssuite. It feeds the model's output through both parsers in the server's order:bashcall with the rightcommand;</think>is dropped and the text after it kept;New
ReasoningExitMarkerTests(LLMServerTests): only a request with tools gets the marker.Existing suites: the
ThinkTagParserandToolCallParsertests pass.