Add tool use MVP to MLX models - #20
Open
thomasantony wants to merge 4 commits into
Open
Conversation
thomasantony
force-pushed
the
feature/tool_usage
branch
from
June 3, 2025 06:49
015651e to
8e9362c
Compare
Owner
|
I'd rather not include the custom tools system prompt stuff just because of the added complexity and future maintenance burden. I'm really interested in exploring that kind of thing separate though. I'd love to be able to offer prompt-driven tool support in LLM core that works with any model (from any plugin) that doesn't have its own tool support. I haven't figured out what shape that would take yet. |
thomasantony
force-pushed
the
feature/tool_usage
branch
from
June 4, 2025 01:17
8e9362c to
be3b7ca
Compare
Author
|
I have removed the commit with the injected template and fixed a couple of bugs. |
Author
|
Hey @simonw, did you get a chance to review this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is an MVP for tool usage support for MLX-based models. It uses
apply_chat_templateto add tool definitions to the chat template (assuming the model already has a tool call template). The plugin tries to detect the tool format. And if it cannot identify it, it adds a generic tool calling prompt of its own to the system prompt (this is admittedly a bit janky and can be removed if deemed too unpolished).Tool parsing is done based on the detected tool format and a set of fixed rules.
Tool results are added to the conversation using the template.
It also works with thinking models like qwen3. Multiple tool calls in a single request is supported.
This has been tested so far with the following models:
Some models struggle if asked for more than one tool call at once. I have had good results with the Qwen3-8b model listed above.