Skip to content

common : gpt-oss handle builtins and unsolicited tool calls#21213

Merged
pwilkin merged 1 commit intoggml-org:masterfrom
aldehir:gpt-oss-add-builtins
Mar 31, 2026
Merged

common : gpt-oss handle builtins and unsolicited tool calls#21213
pwilkin merged 1 commit intoggml-org:masterfrom
aldehir:gpt-oss-add-builtins

Conversation

@aldehir
Copy link
Copy Markdown
Contributor

@aldehir aldehir commented Mar 31, 2026

Overview

Add parsing rules for builtin functions and unsolicited tool calls. This will prevent the parsing from failing and instead returns empty content since there is no good way to handle this edge case.

ref: #20650 (comment)

Additional information

Occasionally, gpt-oss will try to invoke a builtin function even if it isn't enabled in the system prompt. An easy test is to enable the builtin python tool and confirm that it returns an empty string:

{
  "messages": [
    {
      "role": "user",
      "content": "Can you run print('hello') in python."
    }
  ],
  "stream": false,
  "chat_template_kwargs": {"builtin_tools": ["python"]}
}
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "",
        "reasoning_content": "User asks: \"Can you run print('hello') in python.\" They want to see output. As ChatGPT, we can execute python code using tool. So we should run print('hello') and show output. Provide result."
      }
    }
  ],
  "model": "gpt-oss-120b-F16.gguf",
  "id": "chatcmpl-VtCPiEeOxStFwd66nQiR9YWAXj6nfbOE",
  "__verbose": {
    "content": "<|channel|>analysis<|message|>User asks: \"Can you run print('hello') in python.\" They want to see output. As ChatGPT, we can execute python code using tool. So we should run print('hello') and show output. Provide result.<|end|><|start|>assistant<|channel|>commentary to=python code<|message|>print('hello')",
  }
}

Requirements

@aldehir aldehir requested review from a team and pwilkin as code owners March 31, 2026 07:05
@github-actions github-actions Bot added the testing Everything test related label Mar 31, 2026
Copy link
Copy Markdown
Member

@ggerganov ggerganov left a comment

Choose a reason for hiding this comment

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

With this patch, I am not seeing anymore errors in the AIME25 evals.

@pwilkin pwilkin merged commit 624733d into ggml-org:master Mar 31, 2026
44 of 45 checks passed
slartibardfast pushed a commit to slartibardfast/llama.cpp that referenced this pull request Apr 12, 2026
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
rsenthilkumar6 pushed a commit to rsenthilkumar6/llama.cpp that referenced this pull request May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants