Skip to main content

Module tool_call_parser

Module tool_call_parser 

Source
Available on crate feature models only.
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|>

Provider clients call parse_declared_tool_calls and ToolCallBuffer::for_declared_tools, which accept a parse only when every call names a tool the request declared. A markdown ```json fence is ordinary model output, so the DeepSeek format also requires an arguments or parameters object.

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_declared_tool_calls
Parse text-based tool calls, accepting them only when they call declared tools.
parse_text_tool_calls
Parse text-based tool calls from model output.