Skip to content

common/chat : unify and fix LFM2/LFM2.5 tool parser#24178

Open
tdakhran wants to merge 1 commit into
ggml-org:masterfrom
tdakhran:tarek/fix/lfm2.5-tool-calling
Open

common/chat : unify and fix LFM2/LFM2.5 tool parser#24178
tdakhran wants to merge 1 commit into
ggml-org:masterfrom
tdakhran:tarek/fix/lfm2.5-tool-calling

Conversation

@tdakhran
Copy link
Copy Markdown
Contributor

@tdakhran tdakhran commented Jun 5, 2026

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:

  • convert Python literals True/False/None to JSON true/false/null
  • accept JSON-cased true/false/null in argument values (parser helps the model)
  • convert single-quoted strings to JSON strings
  • handle dotted function names, e.g. Calendar.create_event

Additional 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.

image

lfm2_tool_calling_7fe2ae45a_vs_71b74a408.html

Requirements

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
@tdakhran tdakhran requested review from a team and pwilkin as code owners June 5, 2026 11:51
@github-actions github-actions Bot added the testing Everything test related label Jun 5, 2026
@liebedan
Copy link
Copy Markdown

liebedan commented Jun 5, 2026

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.

@Dev-iL
Copy link
Copy Markdown

Dev-iL commented Jun 5, 2026

Related: #24071

Copy link
Copy Markdown
Member

@pwilkin pwilkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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... ;)

@ngxson
Copy link
Copy Markdown
Contributor

ngxson commented Jun 5, 2026

CC @aldehir if you can do a quick review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants