[PR #11030] tools: loosen tool parsing to allow for more formats #13416

Closed
opened 2026-04-13 00:26:41 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/ollama/ollama/pull/11030

State: closed
Merged: Yes


Several new models such as DeepSeek-R1-0528 output tool calls in a new format that uses special tokens to separate function names from arguments. This PRs loosens tool call parsing by using the fact that we know the names of the tools and arguments/parameters that can be provided. It also provides a path towards python tool calling (all that would remain is detecting python kwargs)

  1. First look for the tool calling tag/prefix (e.g. <tool_call>)
  2. Then look for the tool name (e.g. get_weather)
  3. Then look for an object representing the tool call arguments (e.g. {"city": "Toronto"})

Once both 2 and 3 are found, the tool call is returned from parser.Add()

I've moved away from the static templates, as they are cumbersome we only need the content in the {{ if .ToolCalls }} portion of the template, which this can be provided inline.

Follow ups:

  • Use the new encoding/json package in Go 1.25 to escape sooner if we begin parsing a json object yet it turns out to not be arguments or valid json (should improve the case where the inferred tag is { or [
**Original Pull Request:** https://github.com/ollama/ollama/pull/11030 **State:** closed **Merged:** Yes --- Several new models such as DeepSeek-R1-0528 output tool calls in a new format that uses special tokens to separate function names from arguments. This PRs loosens tool call parsing by using the fact that we know the names of the tools and arguments/parameters that can be provided. It also provides a path towards python tool calling (all that would remain is detecting python kwargs) 1. First look for the tool calling tag/prefix (e.g. `<tool_call>`) 2. Then look for the tool name (e.g. `get_weather`) 3. Then look for an object representing the tool call arguments (e.g. `{"city": "Toronto"}`) Once both 2 and 3 are found, the tool call is returned from `parser.Add()` I've moved away from the static templates, as they are cumbersome we only need the content in the `{{ if .ToolCalls }}` portion of the template, which this can be provided inline. Follow ups: - [ ] Use the new `encoding/json` package in Go 1.25 to escape sooner if we begin parsing a json object yet it turns out to not be arguments or valid json (should improve the case where the inferred tag is `{` or `[`
GiteaMirror added the pull-request label 2026-04-13 00:26:41 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#13416