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

Closed
opened 2026-04-23 00:10:41 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/11386
Author: @rick-github
Created: 7/12/2025
Status: Closed

Base: mainHead: tool-match


📝 Commits (2)

  • 82fec5c Find the longest match for a tool name.
  • 213e26d Find the earliest tool match, and then the longest.

📊 Changes

1 file changed (+15 additions, -3 deletions)

View changed files

📝 tools/tools.go (+15 -3)

📄 Description

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'}))]

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/11386 **Author:** [@rick-github](https://github.com/rick-github) **Created:** 7/12/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `tool-match` --- ### 📝 Commits (2) - [`82fec5c`](https://github.com/ollama/ollama/commit/82fec5c4ec117c411befd75b1fe22f0e718d2b7b) Find the longest match for a tool name. - [`213e26d`](https://github.com/ollama/ollama/commit/213e26d5887f29e136b54fbf23047cea20f29d06) Find the earliest tool match, and then the longest. ### 📊 Changes **1 file changed** (+15 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `tools/tools.go` (+15 -3) </details> ### 📄 Description 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'}))] ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-23 00:10: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#39398