Skip to content

Per-model Ollama context-window and token defaults - #251

Merged
TheGreatAxios merged 5 commits into
mainfrom
cl-6204-inference-adapter
Aug 21, 2026
Merged

TheGreatAxios merged 5 commits into
mainfrom
cl-6204-inference-adapter

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Contributor

Carries the work from #247, which landed on this branch after its parent PR (#236) had already merged to main, leaving it stranded.

Chat agents served by Ollama were silently running at a 4096-token cap: @intx/inference's adapters fall back to options.maxTokens ?? 4096 when a caller supplies nothing, and the model catalog seeded no context or token data for any model. Ollama's num_ctx — the real context window, distinct from the output cap — rides only through the endpoint's options passthrough and was likewise unset.

quirksForDeployment now resolves those per model, the same way capabilities are already resolved, and catalog seeding passes them through. The rest of the chain was already wired: model_offering.quirks is persisted and spread into InferenceSource.quirks, which is what the Ollama adapter reads.

Defaults follow each model's real advertised ceiling rather than a single number: gpt-oss:20b and llama3.1:8b get 128K, while the Qwen3 27B/30B-class models get their genuine 32K native ceiling — 131072 there needs YaRN scaling, and an over-large num_ctx risks allocation failure or heavy swap on the inference host. Unlisted models get no override rather than a guess, and a caller-supplied value always wins.

Scoped strictly to the ollama provider; other providers' offerings are untouched.

Tests assert the value reaches the built request body, not just the resolved config — gpt-oss:20b carries options: {num_ctx: 131072} and max_tokens: 32768 (explicitly asserted !== 4096), and the catalog seed's POST body carries the per-model quirks. That assertion is the point: a silently-dropped setting is the exact failure mode here.

Chat agents served through the Ollama openai-compatible adapter silently
fall back to @intx/inference's built-in 4096-token default (and Ollama's
own small built-in context window) whenever nothing sets a per-model
ceiling. These tests pin the fix: a curated model's quirks resolve its
real advertised context window, a smaller-ceiling model gets its own
limit rather than the larger model's, a caller override wins, and an
unlisted model gets no guessed override at all -- verified against the
adapter's actual built request body, not just the resolved config.
@corbits/ollama-adapter's OllamaAdapterConfig mechanism (numCtx,
maxOutputTokens, reasoningEffort) had no real data behind it, so every
Ollama-served chat agent still ran at the built-in 4096-token default.
quirksForDeployment resolves each curated model's advertised native
context window at offering-creation time, the same way
capabilitiesForDeployment resolves capabilities -- gpt-oss:20b and
llama3.1:8b get their real 128K ceiling, Qwen3's 27B/30B-class models get
their smaller 32K native ceiling rather than an over-requested num_ctx
that risks allocation failure or heavy swap on the inference host. A
model outside this table gets no override, and a caller-supplied override
always wins.
seedCatalog computed capabilities for a new offering but never its
quirks, so nothing ever reached the model_offering row an Ollama chat
agent actually launches against. This test seeds Ollama's curated
catalog and asserts each offering's POST body carries the per-model
quirks quirksForDeployment resolves -- gpt-oss:20b's real 128K ceiling,
Qwen3's smaller real ceiling -- rather than an empty quirks column.
ensureCatalogOffering now threads a quirks value through to the offering
POST body -- @intx/hub-api already persists it on model_offering.quirks,
and the platform's own InferenceSource resolution already spreads a
non-null quirks column into the request-build path, so this is the one
place workbench needed to populate it. seedCatalog computes it with
quirksForDeployment right alongside capabilitiesForDeployment, scoped to
the ollama provider only; every other provider's offerings are
unaffected, and a model with no vetted default still gets none.
Per-model context-window defaults for chat agents (stop the silent 4096 fallback)
@TheGreatAxios
TheGreatAxios merged commit 7c01ddb into main Aug 21, 2026
2 checks passed
@TheGreatAxios
TheGreatAxios deleted the cl-6204-inference-adapter branch August 25, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant