Skip to main content

finalize_tool_call

Function finalize_tool_call 

Source
fn finalize_tool_call(
    body: &str,
    out: &mut ParserOutput,
    mint_id: impl FnMut() -> String,
)
Expand description

Parse the accumulated tool-call body and push the resulting ToolCalls (or a NormalizationError) onto out.

Two body shapes are accepted, in order:

  1. JSON{"name":"foo","arguments":{...}} (Qwen2/2.5 native).
  2. Inner XML — one or more back-to-back <function=NAME><parameter=KEY>VAL</parameter>...</function> blocks (Qwen3 + --jinja, Hermes-style).

JSON is tried first because it is the historical Qwen format and is unambiguous; the XML form is the documented fallback for Qwen3 chat templates that emit nested function/parameter markup inside <tool_call>.

On failure, the error kind reflects which dialect was attempted: a body that looks like it opened the XML dialect (<function=) but didn’t match its shape reports NormalizationErrorKind::MalformedFunctionXml instead of the generic JSON failure, since the two dialects fail for unrelated reasons and a log reader should not have to guess which one was in play.