Skip to content

Make thinking-level support data-driven so new models and custom endpoints need no code change #559

Open

Description

@tobiasploetz

Summary

Thinking-level support is encoded in code rather than data, and the encoding is duplicated across three layers that can disagree. Adding a model family means editing packages/ai predicates, provider if/else trees, tests and docs, then rebuilding dreb — and a custom models.json endpoint has no way to declare it at all.

Observed in practice: a local Anthropic-compatible gateway (api: "anthropic-messages", model deepseek-v4.1-flash) accepts output_config: { effort: "max" } and returns thinking blocks — verified with a direct request — but dreb cannot offer max for it. supportsMax() returns false (id not in the hardcoded families), so the session clamps max → xhigh → high, and an explicit max is a hard error in validateThinkingLevelForModel(). There is no models.json override for this: ModelDefinitionSchema/ModelOverrideSchema expose only reasoning: boolean, and compat is typed for openai-completions only — so an anthropic-messages gateway has zero knobs.

Root causes

  1. Capabilities are boolean predicates over model-id regexes, in packages/ai/src/models.ts:

    • supportsMax() (:221), supportsXhigh() (:246), supportsAdaptiveThinking() (:269), supportsThinkingOff() (:284), getClaudeThinkingOffMode() (:300), isQwen38OrLater() (:206), plus claudeFamilyVersion()/nativeClaude().
    • One commit per family is the observable consequence: b29f468 (GPT-5.6 max), 4d74107 (Claude 5.5 xhigh/max), b83112b (Qwen), 02eab03 (Kimi).
  2. Tiers are not representable outside code. ThinkingBudgets (packages/ai/src/types.ts:48) has only minimal|low|medium|high. So xhigh/max cannot exist on a budget-based transport, and clampReasoning() (packages/ai/src/providers/simple-options.ts:19) hardcodes xhigh|max → high. The capability gate and the wire layer cannot agree on the top two tiers — a correct supportsMax() alone still produces high behaviour on budget transports.

  3. No override surface. ModelDefinitionSchema (packages/coding-agent/src/core/model-registry.ts:87), ModelOverrideSchema (:111) and applyModelOverride() (:294) know nothing about thinking; compat.thinkingFormat (packages/ai/src/providers/openai-completions.ts:415-460) is a closed enum of per-vendor branches rather than data.

  4. Provider payload code branches on model id rather than on a capability: packages/ai/src/providers/anthropic.ts:698-775 (adaptive vs budget vs off-mode), amazon-bedrock.ts:711, openai-completions.ts:415-460.

Proposed work

Introduce one declarative capability descriptor on the model record and derive everything from it. Heuristics stay as a fallback for unknown ids, so behaviour for existing models is unchanged.

// packages/ai/src/types.ts
export type ThinkingEncodingKind = "effort" | "budget" | "toggle" | "adaptive";

export interface ThinkingEncoding {
  kind: ThinkingEncodingKind;
  // reserved for the provider work (stage 2):
  field?: string;
  map?: Partial<Record<ThinkingLevel, string>>;
  budgets?: Partial<Record<ThinkingLevel, number>>;
}

export interface ThinkingCapability {
  /** Supported tiers, ascending; empty for non-reasoning models. "off" is expressed by `off`. */
  levels: ThinkingLevel[];
  /** How a request disables thinking. `"omit"` means it cannot be disabled. */
  off: "disabled" | "between_tools" | "omit";
  encoding: ThinkingEncoding;
}

export interface Model<TApi extends Api> {
  // ...
  thinking?: ThinkingCapability;
}

Resolution order in getThinkingCapability(model): model.thinking (from models.json) → curated catalog data → id-heuristic inference (today's rules, moved verbatim) → conservative default (reasoning ? [minimal..high] : []). supportsMax/supportsXhigh/supportsThinkingOff/supportsAdaptiveThinking/getAvailableThinkingLevels/clampThinkingLevel become thin derivations with unchanged signatures, so coding-agent call sites don't move.

Stage 1 (this issue's first PR): descriptor + config surface, zero provider changes.

  • New types and Model.thinking.
  • getThinkingCapability() + inference that reproduces current behaviour exactly (proved by a golden snapshot over every registered model).
  • Route the existing helpers through the capability.
  • thinking accepted in models.json at both model-definition and per-model-override level, deep-merged in applyModelOverride(), validated in validateConfig().
  • Docs: packages/coding-agent/docs/models.md field table + example, packages/ai/README.md helpers note.

A user can then fix the deepseek-v4.1-flash case above, and any future gateway model, without a rebuild:

{ "providers": { "tux-anthropic": { "modelOverrides": { "deepseek-v4.1-flash": {
  "thinking": {
    "levels": ["minimal", "low", "medium", "high", "xhigh", "max"],
    "off": "disabled",
    "encoding": { "kind": "effort" }
  } } } } } }

Note: until stage 2 lands, a declared tier is accepted and offered but the provider still uses its existing branch, so max on a non-adaptive transport is not yet sent on the wire. Stage 1 is deliberately behaviour-neutral for stock models.

Stage 2: providers switch on encoding.kind instead of model id; ThinkingBudgets extended to all six tiers; clampReasoning() stops folding xhigh/max into high; anthropic.ts/bedrock read encoding for the adaptive/effort case.

Stage 3: scripts/generate-models.ts emits thinking (models.dev/OpenRouter data merged with a curated data-only catalog), shrinking the heuristics to an unknown-id fallback.

Acceptance criteria

  • getThinkingCapability(model) returns identical effective behaviour to today for every model in the generated registry (golden snapshot test added).
  • supportsMax, supportsXhigh, supportsAdaptiveThinking, supportsThinkingOff, getClaudeThinkingOffMode, getAvailableThinkingLevels keep their exported signatures and values; existing tests pass unchanged.
  • models.json accepts thinking in both models[] and modelOverrides, with validation errors that name the offending provider/model.
  • Invalid capability data (unknown tier, unknown off/kind, duplicate or unsorted levels) is rejected or normalised deterministically, covered by tests.
  • Docs updated (docs/models.md, packages/ai/README.md).

Out of scope

  • Provider payload rewrites (stage 2) and codegen/catalog work (stage 3) — separate PRs.
  • Runtime capability probing against a live endpoint.
  • Changing the session-facing ThinkingLevel scale or the selector UX.

Prior art

#545 / #546 (Claude 5.5 effort levels), #338 (GPT-5.6 max), #117 (effort mapping), #250 (Opus 4.7+ display), #466 (Qwen effort forwarding).

Activity

  1. tobiasploetz commented on Nov 5, 2026

    @tobiasploetz
    ContributorAuthor

    Stage 1 is implemented in a fork PR: tobiasploetz#9 (base main-tp).

    Scope delivered matches the "Stage 1" bullet list above — descriptor types, getThinkingCapability() resolver with the existing heuristics preserved as the inference fallback, all helper signatures unchanged, and thinking accepted on models.json custom models and modelOverrides.

    Evidence that it is behaviour-neutral for stock models: a new golden snapshot pins off | levels | encoding.kind for every registered model, and the 211 existing capability assertions in supports-max / supports-xhigh / supports-thinking-off / supports-adaptive-thinking pass untouched (full suite 6952 passed).

    Two design decisions worth a maintainer's eye before stage 2:

    1. Model.thinking is typed as the partial ThinkingCapabilityDeclaration, while ThinkingCapability is the resolved form. Read sites go through getThinkingCapability(); direct field access would see optional values. This keeps SDK construction and single-field overrides ergonomic.
    2. encoding carries field / map / budgets already, so stage 2 can be provider-only without another models.json schema change. Only kind === "adaptive" and off affect requests today — the docs say so explicitly, so a declared tier is selectable but inert on the wire until stage 2.

    Stages 2 and 3 will be separate PRs against the same base per the repo's small-PR guidance.

  2. m-aebrer commented on Nov 6, 2026

    @m-aebrer
    Collaborator

    This seems really promising! Can you give me a plain english ELI5 description of what it's doing though? It's a bit jargony as written.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions