Repository navigation
fix(server): convert Anthropic tool_use and tool_result blocks - #791
Merged
Merged
Conversation
/v1/messages kept only text blocks. An assistant turn of tool_use blocks rendered empty, and so did a user turn of tool_result blocks, so the model never saw its own call or its result and Claude Code re-issued the same first tool call forever. - tool_use ids go through tool memory like OpenAI tool_calls; ids the server no longer remembers fall back to the Qwen template's <tool_call> rendering. - Each tool_result becomes a tool message (string or text-block content); the user's own text in that turn follows them. - Claude Code ends every request with a system note, so a request "ends with a tool result" when the last message other than a system note is one. The agent-turn prefix snapshot (#775) depends on it.
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.
Problem
/v1/messageskept only thetextblocks of each message. An assistant turn made oftool_useblocks rendered as an empty turn, and so did a user turn made oftool_resultblocks, so the model never saw its own tool call or the result.Measured with Claude Code against Qwen3.8-27B + DFlash2 on lucebox7 (R9700): on main it re-issued the same first
Readcall 50 times in two minutes, each prompt 33 tokens longer (an empty assistant turn, an empty user turn and a new system note per round).Claude Code also ends every request with a
systemmessage (a token budget note), soends_with_tool_resultwas always false for it and the agent-turn prefix snapshot from #775 never took the deep cut.Change
tool_useblocks: their ids go through tool memory, like OpenAItool_calls, so the turn replays the text the model generated. Ids the server no longer remembers (restart, eviction) fall back to the Qwen template's own<tool_call>rendering instead of disappearing.tool_resultblocks: each becomes atoolmessage (string content or the text blocks of an array). The user's own text in that turn follows them.http_detail::ends_with_tool_result(): the last message other than asystemnote decides.Validation (lucebox7, Qwen3.8-27B UD-IQ4_XS + DFlash2, qualified launcher flags)
Not in this PR
Registering Anthropic replies in
remember_agent_turn(which would let the prefix cache reuse the generated turn for Claude Code) is left out on purpose: it renders past tool-call turns with the empty<think></think>the model generated after, and with the current greedy default for Qwen3.8 that history made Claude Code loop on a failing edit in 5 of 6 runs. It belongs with sampling defaults for Qwen3.8.