[PR #11386] tools: find the right tool to call #13525

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

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

State: closed
Merged: No


If a tool list has tools in which one is a substring of the other, it's possible for the wrong tool to be selected.

For example, tools=[add, get_ip_address]. If the model generates a tool call for get_ip_address, it's possible for the tool parser to incorrectly select add.

This PR avoids that by locating the earliest and longest matching tool name in the buffer.

Example failure:

#!/usr/bin/env python3

import ollama
import sys

def rm(file):
  """
    Remove a file.
    Args:
      file (str): name of file to remove.
  """
  return True

def format(file):
  """
    Format the contents of file according to the go style guide.
    Args:
      file (str): name of file to be formatted.
  """
  return True

response = ollama.chat(model="devstral", tools=[rm, format],
    messages=[{"role":"user","content":sys.argv[1]}],
    stream=False)

print(response.message.tool_calls)
$ ./11386.py 'format server/routes.go to match the style guide'
[ToolCall(function=Function(name='rm', arguments={'file': 'server/routes.go'}))]
**Original Pull Request:** https://github.com/ollama/ollama/pull/11386 **State:** closed **Merged:** No --- If a tool list has tools in which one is a substring of the other, it's possible for the wrong tool to be selected. For example, tools=[add, get_ip_address]. If the model generates a tool call for `get_ip_address`, it's possible for the tool parser to incorrectly select `add`. This PR avoids that by locating the earliest and longest matching tool name in the buffer. Example failure: ```python #!/usr/bin/env python3 import ollama import sys def rm(file): """ Remove a file. Args: file (str): name of file to remove. """ return True def format(file): """ Format the contents of file according to the go style guide. Args: file (str): name of file to be formatted. """ return True response = ollama.chat(model="devstral", tools=[rm, format], messages=[{"role":"user","content":sys.argv[1]}], stream=False) print(response.message.tool_calls) ``` ```shell $ ./11386.py 'format server/routes.go to match the style guide' [ToolCall(function=Function(name='rm', arguments={'file': 'server/routes.go'}))] ```
GiteaMirror added the pull-request label 2026-04-13 00:29:29 -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#13525