Tool calling: add LFM2 / LFM2.5 pythonic tool call parser + chat template - #464
Open
mpetruc wants to merge 1 commit into
Open
Tool calling: add LFM2 / LFM2.5 pythonic tool call parser + chat template#464mpetruc wants to merge 1 commit into
mpetruc wants to merge 1 commit into
Conversation
LFM2 / LFM2.5 (Liquid AI) models emit tool calls as a Pythonic list wrapped in <|tool_call_start|> / <|tool_call_end|> sentinels rather than OpenAI-style JSON. Register a new parser that converts those into standard tool_calls. - lfm2.py: parse the pythonic call list with ast (handles strings, nesting, negatives, unicode), turning each call into a ToolCall with JSON-encoded kwargs. Recovers reserved-keyword names (from=...) and leading-zero ints via string-safe rewrites. - tools.py: register lfm2 / lfm / lfm2_5 in ALL_TOOLCALL_FORMATS. - templates/lfm2.jinja: chat template that steers the model toward the sentinel format and escapes quotes/backslashes when rendering tool-call history (fresh-session calls otherwise drift to JSON). - tests: Lfm2ToolcallFormatTests in test_stream_parser.py. - docs: note the lfm2 format and template.
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.
Problem: LFM2 / LFM2.5 (Liquid AI) models emit tool calls as a Pythonic list wrapped in
<|tool_call_start|>[...]<|tool_call_end|> sentinels, not OpenAI-style JSON. Generic parsers misread this, so tool
calls appear broken whenever an agent is swapped onto an LFM.
Why add it: enables the LFM2 family for agents/tool-calling, mirroring vllm's lfm2 tool parser. Includes
templates/lfm2.jinja which steers fresh-session calls toward the sentinel format (the stock template lists tools but
never says how to emit a call, so output drifted to JSON).
Examples: raw model output
parses to
Validated against a live lfm2.5 server: non-streaming, streaming, parallel calls (index 0/1), and content-only
responses (no false positives). Registered as tool_format: lfm2 | lfm | lfm2_5.
Additional context: new module endpoints/OAI/utils/toolcall_formats/lfm2.py (ast-based, handles reserved-keyword
params and leading-zero ints), registration in tools.py, 11 tests in test_stream_parser.py, docs row/footnote,
.gitignore tunes to ship the template.