Fix/tool user followup root - #10201
Draft
tastelikefeet wants to merge 3 commits into
Draft
tastelikefeet wants to merge 3 commits into
tastelikefeet wants to merge 3 commits into
Conversation
… agent templates The pairwise encoder in Template._swift_encode assumes strict query/response alternation, so a user turn following tool results (assistant -> tool -> user -> assistant) pairs a 'tool' query with a 'user' response and hits the response_role assertion. This affects every swift-backend ChatML template, not just qwen. Add a generic Template._merge_tool_user_inputs that merges tool results and the following user turns into a single prompt-side query, preserving each native user-turn boundary via template_meta.prompt/chat_sep. Gated to agent templates that render tool results as a user turn (those exposing _get_tool_responses); ReAct-style templates are left unchanged. Add tests/utils/test_tool_user_followup.py: qwen3_5 byte-match against independent ChatML rendering (labels + no-followup no-op) and a hermes generalization check.
GLM renders each role independently, so a user turn following tool results must become a normal <|user|> turn spliced before the assistant transition that _format_tool_responses appends, otherwise the pairwise encoder hits the response_role assertion. Add regression tests for the GLM splice and port the OpenAI/native tool_call equivalence and response loss-weight checks from #10198.
tastelikefeet
marked this pull request as draft
September 20, 2026 12:45
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.
PR type
PR information
Write the detail information belongs to this PR.
Experiment results
Paste your experiment result here(if needed).