Skip to content

Fix/tool user followup root - #10201

Draft
tastelikefeet wants to merge 3 commits into
mainfrom
fix/tool-user-followup-root
Draft

tastelikefeet wants to merge 3 commits into
mainfrom
fix/tool-user-followup-root

Conversation

@tastelikefeet

Copy link
Copy Markdown
Collaborator

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

Write the detail information belongs to this PR.

Experiment results

Paste your experiment result here(if needed).

… 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 tastelikefeet added the postpone We'll revisit this PR once the refactoring work is finished label Sep 20, 2026
@tastelikefeet
tastelikefeet marked this pull request as draft September 20, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

postpone We'll revisit this PR once the refactoring work is finished

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants