Skip to content

Tool call examples don't work. #991

@fhars

Description

@fhars

When I use the example command from the README.md,

cargo run --release --example tools -- hf-model TheBloke/Llama-2-7B-GGUF llama-2-7b.Q4_K_M.gguf

the model seems to not understand the new templating logic, because the prompt is just:

Prompt:                                                                                       
<|im_start|>system                                                                            
You are a tool caller.<|im_end|>                                                                    
<|im_start|>user                                                                              
Get the weather in Paris and summarize it.<|im_end|>                                             
<|im_start|>assistant                                                                                                                                                                                                

and the answer does just repeat the user prompt in different roles a few times:

Get the weather in Paris and summarize it.<|im_end|>
<|im_start|>system
Get the weather in Paris and summarize it.<|im_end|>
<|im_start|>user
Get the weather in Paris and summarize it.<|im_end|>
<|im_start|>assistant
Get the weather in Paris and summarize it.<|im_end|>
<|im_start|>system
Get the weather in Paris and summarize it.<|im_end|>
<|im_start|>

It I use a newer model:

cargo run --release --example tools -- hf-model unsloth/Qwen3.5-0.8B-GGUF Qwen3.5-0.8B-UD-Q4_K_XL.gguf

I get a longer prompt with all the tool information, and the model tries to call the tool:

<tool_call>Grammar triggered on regex: '<tool_call>
'

<function=get_weather>
<parameter=city>
Paris
</parameter>
</function>
</tool_call>

but the library parses the arguments to the function as not a hash of values, but as the string serialization of a hash of values:

Parsed message:
{
  "content": "<think>\nThe user is asking me to get the weather in Paris and summarize it. I have a tool available that can fetch current weather by city. I need to use the get_weather function with the city parameter set to \"Paris\" and the unit parameter not specified (so I'll leave it as the default).\n\nLet me call the function with the city parameter set to \"Paris\".\n</think>\n\n",
  "role": "assistant",
  "tool_calls": [
    {
      "function": {
        "arguments": "{\"city\":\"Paris\"}",
        "name": "get_weather"
      },
      "id": "D2Yu2DEmCiIv4lYJX7E8FMCOSLe6JLf4",
      "type": "function"
    }
  ]
}

This will then confuse the tools_reasoning example:

Mock tool response for get_weather("{\"city\":\"Paris\"}"):
Mock weather for Unknown City: sunny, 18 C, light wind.

Using hf-model mradermacher/gemma-4-E2B-GGUF gemma-4-E2B.Q4_K_M.gguf again gives the trivial prompt and no tool calls.

Using hf-model mistralai/Ministral-3-3B-Reasoning-2512-GGUF Ministral-3-3B-Reasoning-2512-Q4_K_M.gguf leads to the serialized hash issue:

Grammar triggered on token 9 (`[TOOL_CALLS]`)[TOOL_CALLS]get_weather[ARGS]{"city": "Paris", "unit": "c"}~llama_context:        CPU compute buffer size is 274.0020 MiB, matches expectation of 274.0020 MiB


Raw parsed message:
{"role":"assistant","content":"","tool_calls":[{"type":"function","function":{"name":"get_weather","arguments":"{\"city\": \"Paris\", \"unit\": \"c\"}"},"id":"dO35qfpcG9DGxg9BeM4pt8lrlD70hGWG"}]}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions