Home / use case

Fixing silent tool-call failures caused by Ollama's 4,096-token default context

At a glance
Models & engines
A local model served by Ollama that reports a 262,144-token context in its model info
Key gotcha
The context length in model info and the context actually used at load time are not necessarily the same.

What they built

orca forge's app passes 29 tools to a model served by Ollama and expected a 16,384-token context window. Tools weren't being invoked and responses were cut off midway, and none of the usual signals explained why.

The app had earlier learned to react to a 400 error when the context was exceeded by trimming tools and old results. This time no 400 ever arrived, so that recovery never started, and the investigation ended up in how the request path set the context window.

Setup

  • A local model served by Ollama that reports a 262,144-token context in its model info
  • An app that estimates the window as the smaller of the model info and 16,384, and sends 29 tool definitions

How it works

  1. Requests went through the OpenAI-compatible /v1/chat/completions endpoint, which didn't apply the expected window when loading the model, so it ran at the default 4,096.
  2. When input exceeded the window, Ollama truncated it from the beginning instead of returning a 400.
  3. The fix sends tool calls to /api/chat with options.num_ctx set to 16,384, converting arguments and history to that format, and avoids tool_choice: required, which Ollama doesn't support.

Results & numbers

  • After the change there were zero 400 errors, all 29 tools were passed, and logs showed the full flow from tool call through search and retrieval to the final response.
  • The author notes this fixes window handling, not the model's answer quality or speed.

Gotchas

  • The context length in model info and the context actually used at load time are not necessarily the same.
  • The absence of an error is not evidence that the whole input arrived.
  • Moving only regular chat to the new route and leaving tool calls on the old one would keep the bug.
“The absence of an error was not evidence that the entire input had arrived.”— orca forge

Do it yourself

  1. Check the context length in your model's info.
  2. Check the context_length Ollama actually uses when the model loads.
  3. Send tool calls to /api/chat and set options.num_ctx explicitly.
  4. Don't rely on tool_choice: required with Ollama.
  5. After the change, track the 400 count and confirm logs show tool calls reaching a final response.
Source: orca forge (DEV Community) · Published 2026-10-22 · Added 2026-10-23. This write-up summarizes the original source; see it for full details.

Similar setups

Cutting a local Qwen coding agent's wait on a 16GB Mac with a memory hook

A developer running a coding agent on qwen3.5:9b through Ollama replaced its always-loaded memory index with a hook that attaches only relevant memory lines, and cut median answer time from 90.4s to 56.4s.

DEV Community (JustJinoIT) · 2026-12-02

Getting OpenCode to work with a local Ollama model by fixing the 4,096-token context

OpenCode on a local Ollama model ignored files, invented tasks or looped, because each ~23k-token request was silently cut to fit Ollama's default 4,096-token context on a 16 GB GPU.

DEV Community (Davidrs) · 2026-11-27

Testing a reasoning-effort fix on a local Qwen 27B for build-fix tasks

A developer ran a pre-registered overnight test on a local Qwen3.8 27B in Ollama to see if dropping a hidden reasoning-effort paragraph from the prompt helps it patch failing builds; the run was valid but scored 4/10 against a 5/10 bar.

DEV Community (hexisteme) · 2026-11-25

PatchPal TinyAgent: a coding agent on a 4B model and a 6GB laptop GPU

WiseProbe adapted its PatchPal coding agent to run Gemma 4 E4B or Qwen3.5 4B through Ollama on a 6GB RTX A1000, using handoff-note compaction and capped file reads to work inside a 16K or 32K window.

WiseProbe Blog · 2026-11-25