Skip to content

chat: enable tool call in thinking for DS4 - #26269

Merged
aldehir merged 1 commit into
ggml-org:masterfrom
pwilkin:ds4-tool-call-in-thinking
Aug 1, 2026
Merged

aldehir merged 1 commit into
ggml-org:masterfrom
pwilkin:ds4-tool-call-in-thinking

Conversation

@pwilkin

@pwilkin pwilkin commented Jul 29, 2026

Copy link
Copy Markdown
Member

Overview

Mirror to #26252 - allows tool calls in reasoning for DS4

Requirements

@pwilkin
pwilkin requested a review from a team as a code owner July 29, 2026 10:39
@github-actions github-actions Bot added testing Everything test related examples labels Jul 29, 2026
Comment thread common/chat.cpp
Comment on lines +2078 to +2080
reasoning = p.optional(THINK_START + p.reasoning(p.until(THINK_END)) + THINK_END);
reasoning_with_tc = THINK_START + p.reasoning(p.until_one_of({ FC_START, THINK_END })) + obligatory_tool_calls;
allow_reasoning_with_tc = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it's cleaner if you terminate thinking with a p.literal(THINK_END) | p.peek(p.literal(FC_START)). Then you don't need this "tool call in reasoning logic."

@kallewoof

Copy link
Copy Markdown
Contributor

Not seeing any XML failures on this branch. Been chugging along for an hour or so.

@pwilkin

pwilkin commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

@ggml-org/maintainers need 1 more approval please

@ServeurpersoCom ServeurpersoCom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on my server with DeepSeek V4 Flash, both paths work: classic think close + tool call, and forced tool call inside an open think via continuation prefill, clean parse every time.

One nit, grammar_lazy = has_tools && !require_tools skips response_format enforcement when tools and json_schema coexist with auto tool choice, worth a && !has_response_format

@am17an

am17an commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

@aldehir good to merge?

@aldehir

aldehir commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Yes, special consideration needs to be taken for response_format since it's natively supported by DSv4. We can address that in another PR, right now tool calling is more important.

@aldehir
aldehir merged commit ddd4ec1 into ggml-org:master Aug 1, 2026
21 of 26 checks passed
@tarruda

tarruda commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Follow up to make encoding match the reference implementation: #26398

huaxel pushed a commit to huaxel/CachyLLama that referenced this pull request Aug 2, 2026
satindergrewal pushed a commit to satindergrewal/llama.cpp that referenced this pull request Aug 12, 2026
thecodacus pushed a commit to thecodacus/llama.cpp that referenced this pull request Sep 7, 2026
zbrad pushed a commit to zbrad/llama.cpp that referenced this pull request Sep 10, 2026
pl752 pushed a commit to pl752/llama.cpp that referenced this pull request Sep 15, 2026
frostyautumnleaf pushed a commit to frostyautumnleaf/llama.cpp that referenced this pull request Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

examples testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants