common/chat : unify and fix LFM2/LFM2.5 tool parser#24178
Open
tdakhran wants to merge 1 commit into
Open
Conversation
LFM2 and LFM2.5 share the same tool-calling format with the only difference is that LFM2 also wraps the system tool list in <|tool_list_start|>/<|tool_list_end|>. Merge the two parsers into common_chat_params_init_lfm2(..., tool_list_tokens). Also fix and extend argument parsing: * convert Python literals True/False/None to JSON true/false/null * accept JSON-cased true/false/null in argument values * convert single-quoted strings to JSON strings * handle dotted function names, e.g. Calendar.create_event // insert image here
|
I'd love to see this merged. IMHO the conversion of the literals from Python to JSON could solve problems that many people seem to have when it comes to LFM2.5 tool calling. As described in this issue over at HF. |
|
Related: #24071 |
pwilkin
approved these changes
Jun 5, 2026
Member
pwilkin
left a comment
There was a problem hiding this comment.
I swear everything just operates in cycles - back in the day we had a full python dict parser in the autoparser code, but we removed it because we figured nobody uses that syntax anymore... ;)
Contributor
|
CC @aldehir if you can do a quick review |
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.
Overview
LFM2 and LFM2.5 share the same pythonic style tool-calling format, with the only difference being that LFM2 also wraps the system tool list in <|tool_list_start|>/<|tool_list_end|>.
Two parsers are merged into
common_chat_params_init_lfm2(..., tool_list_tokens)and share logic.Also fix and extend argument parsing:
Calendar.create_eventAdditional information
The parser was tested against the reference implementation and recovers tool-calling capabilities across different LFM2/LFM2.5 models. Interactive HTML with comparison attached below.
lfm2_tool_calling_7fe2ae45a_vs_71b74a408.html
Requirements