Repository navigation
Improve local chat tool call flow - #5962
Conversation
There was a problem hiding this comment.
Code Review
This pull request enhances tool call handling and streaming in the inference backends and frontend chat adapter. Key changes include tracking tool call provenance (such as whether a tool call was healed, forced, or provisional) in both the llama_cpp and safetensors backends, and refactoring the frontend chat adapter to correctly position tool calls within the assistant's response stream using a text cursor. Additionally, the tool nudge prompts have been updated to be more flexible, streaming-specific tool markup stripping has been introduced, and corresponding unit tests have been added. There are no review comments, so no further feedback is provided.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
@codex review |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a centralized ToolLoopController to manage local agentic tool loop state, handle duplicate, disabled, and one-shot tool calls, and record results or no-ops across GGUF and safetensors backends. It also refactors tool action nudges, integrates selective XML display stripping based on the auto-heal setting, and updates the frontend chat adapter to track tool call provenance and preserve correct message ordering. Extensive backend tests have been added to verify these changes. No review comments were provided for evaluation.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
Codex Review: Didn't find any major issues. Chef's kiss. ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cda66cab06
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Resolve conflicts preferring PR tool-loop semantics with main's ruff line-length 100 formatting and the unslothai#6072 exception/sandbox hardening. PR's shared tool_loop_controller, allow_incomplete parser, active_tools-gated signals, and _build_tool_action_nudge helper kept.
…text Strict mode (allow_incomplete=False, Auto-Heal disabled) bound the function body to the end of the response, so a complete call followed by trailing prose was rejected while the JSON-style <tool_call> path already tolerated it. Bind the body to the last </function> via rfind (so a literal </function> inside a code parameter value still parses) and reject only when no closing tag is present. Adds test_tool_call_parser_strict.py (function/JSON parity, trailing text, code-value close tag, incomplete-still-rejected) and test_gguf_route_cursor_reset.py (preface -> disabled-tool no-op -> final pass; final answer survives the SSE cursor reset, with a negative control).
|
Synced this branch with Also addressed the two open review comments:
Validation:
Live before/after in Studio with local GGUFs (PRE = main, POST = this branch, identical prompts, temperature 0, enable_tools), across the full model lineup including the MTP and A3B MoE builds. The clearest difference is the duplicate-call bounding: on a "compute with code then answer" prompt, main re-issued the identical python call several times and repeated the final answer, while this branch bounds it to one call and moves to the answer.
web_search, code execution and terminal still work on all seven models, with no tool-call XML leaking into the visible text on either side. Accuracy did not regress. I ran a ground-truth-checked eval (temperature 0) on the two tool types: 12 deterministic code-execution prompts and 10 stable-fact web-search prompts, across Qwen3.5-4B, Qwen3.5-9B, gemma-4-E2B and Qwen3.6-27B-MTP. Per side that is 48 code and 40 web prompts.
Both sides answer 100 percent correctly; web_search fires and returns a grounded answer on all 40. The one code tool-fire difference is Qwen3.5-4B doing 123*456 in its head on POST rather than calling python, and the answer was still correct. So the duplicate-call bounding does not cost correctness or tool firing. One unrelated observation: a thinking block leaks into the visible answer in 12 of 28 of the earlier traces, identical on PRE and POST, so it is a pre-existing display issue on main, not something this PR changes. |
Resolve conflicts in the Studio tool-call loop after main's comment-tightening (unslothai#6029/unslothai#6095/unslothai#6099) and Hub/Download Manager (unslothai#5916): - llama_cpp.py, safetensors_agentic.py: keep the shared ToolLoopController flow (prepare_call/record_result/record_noop) over main's inline duplicate detection; the controller reproduces main's status text, error prefixes, image-sentinel strip, and allowed-tool gating. - routes/inference.py: keep _build_tool_action_nudge (captures main's small-model web-tip simplification and date line) over the inline nudge. - orchestrator.py: keep the active_tools single-turn signature with main's tighter comment. - chat-adapter.ts: keep serializeAssistantReplayMessages/buildReplayContent; drop main's now-redundant collectAssistantToolCalls/collectToolResultMessages (their Gemini native_part handling lives in the PR's per-part helpers). - test_safetensors_tool_loop.py: keep the controller-based duplicate test.
This PR improves how Studio handles local chat tool calls.
It fixes the original issue where tool cards could appear in the wrong place or before the assistant text that led into them. It also makes local tool turns more stable across GGUF and safetensors models.
What changed
Why it matters
Local models do not always emit tool calls cleanly at the start of a turn. They can stream some text first. They can emit structured tool calls late. They can also repeat the same call.
Studio now treats those cases as one coherent assistant turn. The visible chat stays readable. The tool cards stay in order. The final answer is easier to follow.