Skip to content

add: lfm2/2.5 tool parser#1246

Open
jbuchananr wants to merge 1 commit intoml-explore:mainfrom
jbuchananr:add-lfm-tool-parser
Open

add: lfm2/2.5 tool parser#1246
jbuchananr wants to merge 1 commit intoml-explore:mainfrom
jbuchananr:add-lfm-tool-parser

Conversation

@jbuchananr
Copy link
Copy Markdown

Issue

LFM2 / LFM2.5 models emit tool calls as
<|tool_call_start|>[fn(args)]<|tool_call_end|>, but no parser was registered for this
format, so tool calls leaked into message.content instead of tool_calls.

The existing pythonic parser also couldn't have handled real outputs: its regex
rejects dotted names like grocery.orderIngredients and breaks on nested list/dict
args.

Changes

  • New mlx_lm/tool_parsers/lfm2.py — parses the payload with ast so dotted names,
    nested args, and multi-call lists all work.
  • _infer_tool_parser routes chat templates containing "List of tools:" to the new
    parser (matches both LFM2 and LFM2.5).

Testing

  • Added LFM-specific tool calling tests
  • Tested on internal test suite for tool calling
  • Tested locally against mlx_lm.server: single call, multi-tool selection, nested
    args, declined call, streaming, multi-turn round-trip, parallel calls

@blairhudson
Copy link
Copy Markdown

blairhudson commented May 8, 2026

I actually found that LFM 2.5 worked with the existing Pythonic function call format parser. it just wasn't being automatically mapped due to the parser inference only looking at the chat template. I extended the inference to also consider the vocab: #1260

Perhaps we should combine?

@jbuchananr
Copy link
Copy Markdown
Author

@blairhudson Yes! Let me run your PR through some of my internal tests this weekend

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.

2 participants