Expand description
Parsing model-emitted tool / function calls into structured form.
Models emit tool calls in a few conventions; this module recognizes the
common ones and returns {name, arguments} (mirroring mlx-lm’s
tool_parsers/). All host-side string work — no model/runtime coupling.
Formats:
- Hermes / Qwen —
<tool_call>{"name": …, "arguments": {…}}</tool_call>(possibly several blocks). - JSON — the whole text is an object (or array of objects) with
name+arguments/parameters. - Pythonic —
[fn(a="x", b=2)](optionally wrapped in tags).
Structs§
- Tool
Call - A parsed tool call: function name + a JSON object of arguments.
Enums§
- Tool
Format - Known tool-call output formats.
Functions§
- detect_
and_ parse - Try each known format, in order of specificity, and return the first that yields calls. Useful when the chat template’s format isn’t known up front.
- parse
- Parse tool calls from
textin a knownfmt. Returns an empty vec when nothing parses (a plain assistant message, not a tool call).