Skip to main content

Module tool_call_parser

Module tool_call_parser 

Source
Expand description

Text-based tool call parser for models that emit tool calls as text tags.

Some models emit tool calls as text tags instead of structured tool_calls JSON when served through endpoints that don’t support native tool calling (e.g., HuggingFace TGI without --enable-auto-tool-choice).

This module detects and parses these text-based tool calls, converting them to proper Part::FunctionCall entries so the agent pipeline works regardless of the serving backend.

§Supported Formats

  • Qwen/Hermes: <tool_call>{"name":"...", "arguments":{...}}</tool_call>
  • Qwen function tag: <tool_call><function=NAME>ARGS</function></tool_call>
  • Llama: <|python_tag|>{"name":"...", "parameters":{...}}
  • Mistral Nemo: [TOOL_CALLS][{"name":"...", "arguments":{...}}]
  • DeepSeek: ```json\n{"name":"...","arguments":{...}}\n``` with <|tool▁call▁end|>
  • Gemma 4: <|tool_call>call:NAME{key:<|"|>value<|"|>}<tool_call|>
  • Action tags: <|action_start|>JSON<|action_end|>

Structs§

ToolCallBuffer
Streaming buffer that accumulates tokens and detects tool call boundaries.

Enums§

BufferAction
Action returned by ToolCallBuffer::push().

Functions§

contains_tool_call_tag
Check if text contains a tool call tag that should be parsed.
parse_text_tool_calls
Parse text-based tool calls from model output.