Pull requests / #523
#523 serve: a tool call that opens inside thinking is an implicit think end
closed · draft · @chimpera · 0 评论 · 在 GitHub 查看
描述
## The problem The chat template opens `<think>` in the prompt, but only the model can close it. When the model goes from its reasoning straight to a tool call, it sometimes never emits `</think>` — so the entire tool call stays inside the thinking span, and `OutputParser` channels it all as `reasoning`. Through the OpenAI API surface that means the call arrives as `reasoning_content`: a client that runs tools from the content channel sees a thinking-only message with `finish_reason: stop` and nothing to execute. Observed live on a Qwen3.8-Flash-Next deployment: agents stopping silently mid-task; the transcript shows `end_turn` messages whose reasoning tail contains a complete, well-formed `<tool_call>` block (2 occurrences in one overnight session). ## The fix An `OutputParser` in the `reasoning` state that finds `<tool_call>` treats it as an implicit think end: - reasoning is emitted up to the opener (the hold-back now watches `CALL_START` too, so an opener split across deltas is not leaked as thinking), - the rest parses as a normal call — for both streamed deltas and whole completions, - a `</think>` still wins when it comes first; nothing changes for well-formed output. Two guards keep false positives harmless: - a reasoning-span *mention* of the call format that closes like a call but has no call body falls back to visible reasoning verbatim (`call_from_reasoning`) instead of raising — the historical content-span behavior of failing the stream is untouched, - an unfinished call at `finish()` is still never reported as a whole call. ## Tests `ReasoningToolCall` in `serve/test_server.py`: the opener-inside-thinking case (across chunk steps 1/7/10000 and both `stream_tools` settings), `</think>`-before-opener precedence, the malformed-mention fallback, and the unfinished-call case. Full suite: 104 tests OK (`python -m unittest serve.test_server`). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
站内延伸阅读
链到安装、模型与版本说明,便于 SEO/GEO,非官方 issue 正文。