Skip to content

feat(session): add automatic reasoning effort variant - #49245

Closed
JinhaoGu wants to merge 1 commit into
anomalyco:devfrom
JinhaoGu:auto-reasoning-effort
Closed

JinhaoGu wants to merge 1 commit into
anomalyco:devfrom
JinhaoGu:auto-reasoning-effort

Conversation

@JinhaoGu

@JinhaoGu JinhaoGu commented Sep 15, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds an auto reasoning variant. When a model exposes more than one reasoning effort, the assembled model now also exposes auto. Selecting it classifies the current user turn and applies the matching effort for that request instead of a fixed preset.

The classifier scores the last user message on length, code blocks, attachments, and a set of complexity terms, then returns low, medium, high, or xhigh. A [think:xhigh] or [reasoning:low] prefix in the message overrides the result. The chosen effort maps to the closest effort variant the model already has, so models that only expose low and high still resolve.

Most of this is in packages/opencode/src/session/auto-reasoning.ts. LLMRequestPrep.prepare calls it when the selected variant is auto, and createUserMessage accepts variant: "auto". ProviderTransform.withAutoVariant adds the variant where the provider assembles model.variants, so ProviderTransform.variants stays a plain provider effort map.

Config still wins. Registration happens after config variants merge, so auto can be disabled per model like any other variant, and it drops out when fewer than two concrete efforts remain.

A model only receives auto when it exposes at least two rankable efforts. Models that expose a single toggle or no effort levels keep their current variant list, so deepseek-chat, deepseek-reasoner, deepseek-v3, qwen, glm-4.6, and kimi-k2 are unchanged. Models with real effort levels gain it: deepseek-v4, gpt-5, and claude-sonnet-4-6 all list low, medium, high, auto. Toggle models such as minimax-m3 (none, thinking) are rankable, with thinking treated as a high effort.

How did you verify your code works?

  • bun typecheck on packages/opencode.
  • New test/session/auto-reasoning.test.ts covers classification, overrides, effort-to-variant selection, prompt extraction, ProviderTransform.withAutoVariant gating, and LLMRequestPrep selecting low and high for simple and complex prompts.
  • test/provider/transform.test.ts, test/provider/provider.test.ts, test/session/, test/acp/, and test/cli/run/ pass, as does the app model-variant.test.ts.

I have not run this against a live provider, so the end-to-end behavior with a real model is untested.

Screenshots / recordings

The auto option appears in the existing model variant picker. No separate interface change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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