// field note · 2026-09-28

Why your local LLM's tool calls break in agent loops, and how to fix it.

You ran a prompt through your local model and got garbage tool calls. The agent hung. You debugged and found mixed bracket variants, malformed JSON arguments, and functions that don't exist in your schema. The model worked fine for chat. What changed? The issue isn't new, and the fix exists — but it's hidden in how the model's chat template was converted, and you're probably not setting it.

// the short version

  • Tool-calling in agent loops is stricter than chat: the model must emit well-formed JSON that matches the schema, or the agent can stall.
  • GGUF conversions often carry a stale or broken chat template from the original training, silently breaking tool calls even though the model weights are fine.
  • Mixed or inconsistent bracket formats in the raw output are a common tell that the embedded template does not match what the model expects.
  • The fix: override the template at launch with a known-good one, then verify with a raw completion test before trusting the model in production.
  • Reasoning-mode tokens ( blocks) can make the problem worse by eating context and sometimes causing premature EOS mid-function call.

Chat vs. agent loops — why tool calls matter more

When you run a prompt through a chat interface, the model can hedge, rephrase, or emit sloppy JSON and nobody cares. A human reads it and understands. But in an agent loop, there is no human in the loop. The agent's code parses the tool-call JSON, looks up the function, checks the arguments against the schema, and executes. If the model emits:

tartarus · ~/lab
# # The model output:
  [call read_file]
  path: /etc/passwd
  [/call]

That is not valid JSON. A chat user might figure out what the model meant. Your agent's JSON parser throws an exception, the agent dies, and the whole task fails.

Agent loops need the model to emit tool calls so precisely that they parse as JSON, validate against schema, and execute without human interpretation. Chat just needs to be roughly correct.

How a GGUF conversion breaks tool calling silently

When a model is converted to GGUF, the weights are frozen at that instant. But the conversion process also bakes in a chat template — a Jinja2 string that tells the inference server how to format the prompt for the model's training distribution. This template came from the original model card, and it describes the token format for the tool calls.

The problem: if that template was stale (baked from an intermediate checkpoint, or from a training run that predates the current tool-calling standard), the model's weights might expect a different bracket format than what the embedded template produces. The model learned one format. The template is set to emit another. And the server just trusts the template because it has no way to know they're out of sync.

Result: the model works perfectly for chat (where sloppiness is tolerated) and fails completely for agent loops (where precision is required).

The diagnostic: mixed brackets tell you exactly what's wrong

When you run a tool-call prompt and the model outputs:

tartarus · ~/lab
# # Model output (broken):
  <tool>read_file path=/etc/passwd</tool>
# 
# # vs. expected (OpenAI std):
  tool_calls: [{"type": "function", "function": {"name": "read_file", "arguments": "{...}"}}]

You are seeing the embedded (stale) template format being emitted instead of the current standard. This is the #1 diagnostic. When you see:

  • → Square brackets mixing with other bracket or tag styles
  • → Arguments inline instead of in a nested JSON field
  • → Function names as attributes instead of inside a JSON object
  • → Multiple tool calls but inconsistent bracket nesting

…you have a template mismatch. The model weights are fine. The template is wrong.

The fix: override the template and verify with a raw test

Modern inference servers support passing a --chat-template-file flag that overrides the embedded template at launch. Point it at a known-good template (e.g., the current OpenAI-compatible standard, or a reference from the original model's official repo), and the server will use that instead of the stale one baked into the GGUF.

tartarus · ~/lab
$ your-inference-server \
    --model your-model.gguf \
    --chat-template-file ./your-model.jinja \
    --host 127.0.0.1 --port 8080
# # Now all tool calls will use the template you specified, not the GGUF's embedded one

After the server is up, verify with a raw completion test before you trust it to an agent:

tartarus · ~/lab
$ curl -X POST http://127.0.0.1:8080/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{"model":"your-model","messages":[{"role":"user","content":"call function read_file with path=/etc/passwd"}],"tools":[{"type":"function","function":{"name":"read_file","parameters":{"type":"object","properties":{"path":{"type":"string"}},"required":["path"]}}}]}'
# 
# # Check the response:
✓ tool_calls array present?
✓ brackets all square, properly nested?
✓ arguments field is valid JSON?
✓ function name matches schema?

Only after you see canonical OpenAI-format tool calls in the response should you wire it to an agent loop.

Why reasoning-mode tokens make it worse

Some models support a reasoning or thinking mode where the model emits <think> blocks before its response. This is useful for complex logic, but in agent loops, every token counts:

  • → Context tax: A thinking block can consume 10-50% of your context budget before a single tool call is emitted.
  • → Premature EOS: Sometimes a model hits its end-of-sequence token mid-function-call while still thinking, truncating the output.
  • → Template confusion: If reasoning mode is on, some templates get confused about when to apply tool-call formatting (before or after the thinking block?).

Recommendation: disable reasoning mode explicitly when launching the server for agent work. Your inference server's documentation will specify the setting (the name varies by server and version).

Pre-production checklist: verifying tool-calling before deployment

Before you point your agent at a local model, work through this checklist:

  1. 1. Launch with an explicit template file. Don't rely on the GGUF's embedded one. Point the server at a known-good template from the original model repo or a public reference.
  2. 2. Disable reasoning mode. Add the appropriate flag to the launcher so the model doesn't waste context or hit early EOS mid-function-call.
  3. 3. Test with a raw completion call. Use curl or your HTTP client to hit the inference endpoint directly with a simple tool-calling prompt. Don't go through an agent framework yet.
  4. 4. Verify the output format. Check that the tool_calls array is present, brackets are square and nested correctly, function names match your schema, and arguments are valid JSON.
  5. 5. Test 5–10 different prompts. Don't test just one. Try variations: different function names, missing arguments, multiple tool calls in one response. See if the model ever falls back to broken brackets.
  6. 6. Run a lightweight agent scenario. Build a tiny agent that calls a dummy function 5–10 times. Let it loop. If it dies, you'll know before production.
  7. 7. Monitor the first live runs. Log every tool_call the agent emits. If the model suddenly reverts to broken brackets under load, you'll catch it in the logs before it causes real damage.

// skip the setup

A hosted model with tool calling that works out of the box.

No template files to manage and no GPU to babysit. Tool calling is supported through an OpenAI-compatible API, though any model can still emit a bad call now and then, so keep your agent loop defensive.

See plans →