llm
llm copied to clipboard
Toolbox "tool {function_name} does not exist" error
Tools are working when implemented as functions but fail when implemented as part of a ToolBox. Tested with ollama llama3.2.
class CustomToolbox(llm.Toolbox):
def some_function(self, some_input:str):
"Prepend test to the input"
return f"test {some_input}"
When installed, a class like this is correctly detected but fails on execution with the following log:
### Tools
- **CustomToolbox_some_function**: `...`<br>
Prepend test to the input<br>
Arguments: {"some_input": {"type": "string"}}
### Tool results
- **some_function**: `None`<br>
Error: tool "some_function" does not exist<br>
**Error**: KeyError: 'tool "some_function" does not exist'
The lookup dict built in here uses CustomToolbox_some_function when the tool_call loop passes tool.name (i.e. just some_function) as the key.
I confirmed with a quick hack to leverage the capitalization convention but seems like there's probably a cleaner way to manage the retrieval that avoids function name collisions in the cases of multiple toolboxes.
def build_toolbox_compatible_key(tool):
"Replace classnames for Tool objects in Toolbox to match tool_call.name"
if tool.name.lower() == tool.name:
return tool.name
else:
return "_".join(tool.name.split("_")[1:])
tools_by_name = {build_toolbox_compatible_key(tool): tool for tool in self.prompt.tools}