Keep assistant tool_calls and tool messages on the MLLM chat path#611
Open
waybarrios wants to merge 2 commits into
Open
Keep assistant tool_calls and tool messages on the MLLM chat path#611waybarrios wants to merge 2 commits into
waybarrios wants to merge 2 commits into
Conversation
Owner
Author
|
Full test logs from the branch: Regression tests (verbose) — 8 passedMLLM + server suites — 250 passedFull fast suite — 2185 passed, 0 failedLive repro verification (Qwen3-VL-8B-Instruct-4bit, M4 Max)On main, probe B renders byte-identical to probe A (166 tokens) and re-issues the same tool call. |
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.
Summary
Fixes #608. On the MLLM path,
_build_mllm_chat_messagesrebuilt every message as{role, content}and dropped any message without renderable text. An OpenAI assistant message withcontent: null+tool_callswas removed entirely, androle:"tool"messages lost theirtool_call_id. The rendered continuation prompt came out byte-identical to the fresh prompt, so agent clients looped on the same tool call forever.What changed
All in
_build_mllm_chat_messages(shared bychat()andstream_chat(), so both routes are covered with no call-site changes):tool_callssurvive even with empty text. Arguments are normalized str -> mapping via the samenormalize_messages_for_chat_templatehelper the batched engine path wraps, so both paths render identically.reasoning_contentis forwarded when present.role:"tool"messages keep theirtool_call_id. Empty tool results (legit for action tools) survive withcontent: ""instead of being dropped, so template forward-scans can still pair calls to responses.SUPPORTS_NATIVE_TOOL_FORMATonGemma4ToolParser(issue suggestion 3) is intentionally left out of scope.Tests
5 new regression tests in
tests/test_mllm_message_ordering.py(written first, 3 failed on main for the exact bug reasons):{content: null, tool_calls}survives with normalized argumentstool_call_id+ contenttool_callsare still droppedLive verification (issue repro)
Served
mlx-community/Qwen3-VL-8B-Instruct-4bitwith--mllm --enable-auto-tool-choice --tool-call-parser hermes, M4 Max:prompt_tokens = 166prompt_tokens = 213 > 166(history now contributes tokens), no repeated tool_call, final answer uses the tool result: "The weather in Paris is currently 19°C with sunny conditions."On main, probe B renders the same prompt as probe A and re-issues the identical tool call.