Skip to main content

Module tool_parse

Module tool_parse 

Source
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§

ToolCall
A parsed tool call: function name + a JSON object of arguments.

Enums§

ToolFormat
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 text in a known fmt. Returns an empty vec when nothing parses (a plain assistant message, not a tool call).