Repository navigation
chat : Allow K2 Horizon tool call during thought - #32993
Merged
Merged
Conversation
Allow tool calls that would otherwise appear inside reasoning/thinking blocks for K2 Horizon. K2 Horizon models can emit tool calls without closing the thinking block. Without this fix the parser would only stop on explicit end tag, and the tool call was lost without executing. With this PR we now end reasoning before the tool call starts. In short, when reasoning mentions `<ifm|tool_calls>`, we end reasoning there. My tests cover this case at medium and high effort. This fixes ggml-org#32972, and is the same pattern as ggml-org#32232 (Gemma4) and ggml-org#32271 (Ministral-3). - I have read and agree with the [contributing guidelines](https://github.com/ggml-org/llama.cpp/blob/master/CONTRIBUTING.md) I have used Opus to run and score benchmarks, help find the K2 parser, draft the fix and test, and see how others have resolved this for other models. I have carefully examined all changes and tested with my local benchmarks. I have used Sol to code review twice. Assisted-by: Claude Opus 5.5 Assisted-by: GPT 6.2 Sol
pwilkin
approved these changes
Nov 28, 2026
3 tasks
edwardyoon
pushed a commit
to edwardyoon/focus-llama
that referenced
this pull request
Dec 1, 2026
Allow tool calls that would otherwise appear inside reasoning/thinking blocks for K2 Horizon. K2 Horizon models can emit tool calls without closing the thinking block. Without this fix the parser would only stop on explicit end tag, and the tool call was lost without executing. With this PR we now end reasoning before the tool call starts. In short, when reasoning mentions `<ifm|tool_calls>`, we end reasoning there. My tests cover this case at medium and high effort. This fixes ggml-org#32972, and is the same pattern as ggml-org#32232 (Gemma4) and ggml-org#32271 (Ministral-3). - I have read and agree with the [contributing guidelines](https://github.com/ggml-org/llama.cpp/blob/master/CONTRIBUTING.md) I have used Opus to run and score benchmarks, help find the K2 parser, draft the fix and test, and see how others have resolved this for other models. I have carefully examined all changes and tested with my local benchmarks. I have used Sol to code review twice. Assisted-by: Claude Opus 5.5 Assisted-by: GPT 6.2 Sol (cherry picked from commit f16e79d)
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.
Overview
Allow tool calls that would otherwise appear inside reasoning/thinking blocks for K2 Horizon.
K2 Horizon models can emit tool calls without closing the thinking block. Without this
fix the parser would only stop on explicit end tag, and the tool call was lost without
executing. With this PR we now end reasoning before the tool call starts.
In short, when reasoning mentions
<ifm|tool_calls>, we end reasoning there.My tests cover this case at medium and high effort.
This fixes #32972, and is the same pattern as #32232 (Gemma4) and #32271 (Ministral-3).
Additional information
#30335: the K2 medium-effort fix says this unclosed case "is not covered".
#30246: K2 Horizon: low/medium effort leaves final text and tool calls in reasoning_content
Requirements
I have used Claude Opus 5.5 to run and score benchmarks, help find the K2 parser, draft
the fix and test, and see how others have resolved this for other models. I have carefully
examined all changes and tested with my local benchmarks.
I have used GPT 6.2 Sol to code review twice.