Black Friday week: local AI hardware on sale. See the list.
← All guides

Local LLM Tool Calls Printed, Not Run? Check Context

A local assistant is not reliable because it sounds smart. It is reliable when every write, save, update, and tool call can be validated outside the model.

Jump to 10 sections
  1. The core rule
  2. Your agent prints the tool call but nothing happens
  3. Claude Code shows “API error, retrying” with a local model
  4. Why small local assistants fail
  5. The reliable local assistant architecture
  6. Minimal schema pattern
  7. Quantization test before you trust the model
  8. Guardrails that matter more than prompt wording
  9. Hardware advice for assistants
  10. Next steps
Estimator path

Trying to run a Telegram, voice, project-management, or life-management assistant locally? Check whether your model can fit at a reliable quant before designing the rails.

Check local assistant setup

The core rule

Do not let the model be the source of truth.

For a local assistant, the model should propose an action. Your application should decide whether that action is valid, execute it, verify it, and then report the result.

If the model says “saved” before the database, filesystem, calendar, or task API proves it, the assistant is lying by architecture.

Your agent prints the tool call but nothing happens

Symptoms: the model writes </tool_call: write_file> or [write: Create hello.txt] as plain text, says a file was created when it was not, or forgets your previous message. Check these in order.

1. Check the context length first. Ollama picks the default from your VRAM. Under 24 GiB you get 4k, 24 to 48 GiB gets 32k, and 48 GiB or more gets 256k. Ollama says coding tools and agents should have at least 64,000 tokens (context length docs). A 16 GB graphics card therefore starts at 4k.

OLLAMA_CONTEXT_LENGTH=64000 ollama serve
ollama ps    # read the CONTEXT and PROCESSOR columns

If the Ollama app already runs the server, change the context slider in its settings instead. A longer context needs more memory. If PROCESSOR shows a CPU share, the model now spills into system RAM and runs slower. Check the fit at 64K before you pick a model. One CloudYeti viewer on a 32 GB M1 Max reported that OLLAMA_CONTEXT_LENGTH=65536 made file creation work, but very slowly. That is one report, not our test.

2. Test the model without the agent. Send one request with one tool:

curl -s http://localhost:11434/api/chat -d '{
  "model": "YOUR_MODEL", "stream": false,
  "messages": [{"role": "user", "content": "What is the temperature in New York?"}],
  "tools": [{"type": "function", "function": {"name": "get_temperature",
    "description": "Get the current temperature for a city",
    "parameters": {"type": "object", "required": ["city"],
      "properties": {"city": {"type": "string"}}}}}]
}'

A working reply has a message.tool_calls field. If the call arrives as text inside message.content, change the model or its chat template before you debug the agent. If tool_calls is there, test the agent: ask it to create hello.txt, then run cat hello.txt yourself.

3. Set the context in the agent too. OpenCode requires 64k or higher (Ollama’s OpenCode page). In Cline, set the Context Window field to at least 32K (Ollama’s Cline page). So a small model that chats well in ollama run can still fail in OpenCode: a short chat fits in 4k and an agent session does not. ollama launch opencode and ollama launch claude set up the connection.

4. Using llama-server? Tool use needs Jinja templates. Current llama.cpp turns --jinja on by default, so check that nothing passes --no-jinja. If the model’s template has no tool support, pass a correct one with --chat-template-file (function calling docs).

Claude Code shows “API error, retrying” with a local model

Claude Code retries transient failures up to 10 times (error reference), so the retry counter hides the real error. Point it at Ollama like this (Ollama’s Claude Code page):

export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model YOUR_MODEL

The base URL has no /v1 at the end. Use the exact model name from ollama list. Then call the endpoint directly:

curl -s http://localhost:11434/v1/messages \
  -H "content-type: application/json" -H "anthropic-version: 2023-06-01" \
  -d '{"model": "YOUR_MODEL", "max_tokens": 64,
       "messages": [{"role": "user", "content": "Say hi"}]}'

If this fails, the message names the server problem; read the Ollama server log. If it works and Claude Code still retries, note your claude --version, ollama --version, model name and the server log line. Ollama supports only part of the Anthropic API, and its compatibility page lists what is missing.

Why small local assistants fail

Small models are attractive because they fit on 8GB VRAM and can run quickly alongside Whisper, a Telegram bot, or a local web UI. The failure mode is not usually raw conversation quality. It is operational correctness.

Common failures:

  • drops a tool call
  • emits malformed JSON
  • picks the wrong task for “mark that one done”
  • invents a save confirmation
  • truncates arguments after a long prompt
  • burns tokens in reasoning mode and returns no usable content
  • handles obvious references but fails ambiguous references

The fix is not always “use a bigger model.” Bigger models can spill out of VRAM, run slowly, and still mishandle references without a better control layer.

The reliable local assistant architecture

Use this shape:

  1. Intent extraction. Convert the user message into a proposed operation.
  2. Schema validation. Reject malformed or underspecified arguments.
  3. Clarification gate. Ask a follow-up when the target is ambiguous.
  4. Write-ahead log. Record the requested mutation before executing it.
  5. Tool execution. Perform the save/update/delete outside the model.
  6. Readback verification. Query the target system to prove the result exists.
  7. Confirmation. Only now tell the user what happened.

This is boring engineering. That is the point.

Minimal schema pattern

For a task assistant, avoid free-form tool payloads. Use constrained objects:

{
  "action": "create_task | update_task | complete_task | log_note | ask_clarification",
  "target_id": "string or null",
  "title": "string or null",
  "body": "string or null",
  "confidence": 0.0,
  "clarification_question": "string or null"
}

Rules:

  • If confidence is low, do not mutate state.
  • If target_id is missing for an update/delete, ask a clarification question.
  • If the output does not validate, retry once with the validation error.
  • If it fails twice, fall back to manual confirmation.

Ollama supports tool calling and structured outputs, but you still need application-level validation. Schema support reduces failure rate; it does not remove the need to verify writes.

Quantization test before you trust the model

For strict JSON, test the exact quant you will run daily.

Small models are more likely to lose formatting reliability at low precision because they have less redundancy. A 4B or 12B model that seems fine in chat can fail structured output at Q4 or Q6.

Test matrix:

Model sizeTest firstFall back to
1B to 4BQ8larger model or stricter scaffolding
7B to 12BQ8, then Q4/Q5schema retry + readback
20B to 35BQ4/Q5Q6/Q8 for tool-heavy flows
MoE modelschosen quant plus loop testsdense model fallback

Guardrails that matter more than prompt wording

  • Idempotency keys: repeated saves should not create duplicates.
  • Read-after-write: confirm by querying the database, not by trusting the model.
  • Ambiguity thresholds: “that one” should require a recent unique referent.
  • Dry-run mode: for deletes, payments, file edits, and external sends.
  • Audit log: every model-proposed action, validation error, executed tool call, and final confirmation.
  • Tool result injection: the final answer must be based on the tool result, not the original model intent.

Hardware advice for assistants

For an 8GB VRAM assistant, choose speed and reliability over size. A small model with strong rails can beat a larger model that spills into system RAM and makes the interaction feel dead.

Upgrade hardware when:

  • your model fails schema tests at Q8
  • Whisper plus the LLM leaves too little VRAM headroom
  • the assistant needs long context and voice always loaded
  • you need a 20B+ model for reliable tool output

The used RTX 3090 remains a practical NVIDIA path because 24GB VRAM buys room for stronger local tool models. A 32GB AMD card buys more VRAM, but the runtime stack can be more variable. Use the R9700 vs RTX 3090 guide before buying.

Next steps

Was this guide useful?

Read next

Fix OpenClaw / Ollama Out of Memory: "killed", OOM, Model Won't Load
Fix out-of-memory errors running local models in OpenClaw: process "killed", CUDA out of memory, model won't load. Free memory now, or step up to a rig that fits the model.
OpenClaw Tool Calling Not Working: NO_REPLY, "Model Is Not Allowed", SYSTEM_RUN_DENIED
Fix OpenClaw tool calling: NO_REPLY, "Model is not allowed", and SYSTEM_RUN_DENIED approval errors. Check models status, fix provider/model format, pick a model that tool-calls.
Pi Local Model Setup (2026): One models.json Block
Run Pi with a local model: the models.json block for llama.cpp or Ollama, memory for Qwen 27B at 256K context, diff-only edits, and a clean-profile fix.
Your Local Model Says It Wrote the File — It Didn't: Fixing Tool Calling for Local LLMs (2026)
Local models that print tool calls as text or claim they edited a file without touching it. The five real causes — broken chat template, wrong sampler params, tiny context, undersized model, wrong harness — and the fix for each.