Skip to content

Conversation

rick-github
Copy link
Collaborator

@rick-github rick-github commented Jul 12, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants