Skip to content

feat(models): adaptive thinking for Opus 4.6 - #2550

Merged
steebchen merged 4 commits into
theopenco:mainfrom
RATCHAW:RATCHAW/opus-adaptive-thinking
Jun 7, 2026
Merged

steebchen merged 4 commits into
theopenco:mainfrom
RATCHAW:RATCHAW/opus-adaptive-thinking

Conversation

@RATCHAW

@RATCHAW RATCHAW commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Enables adaptive thinking for Claude Opus 4.6 by setting reasoningMode: "adaptive" on its anthropic, aws-bedrock, and vertex-anthropic provider mappings, so the gateway sends thinking: { type: "adaptive" } with output_config.effort instead of the legacy budget_tokens form — bringing 4.6 in line with Opus 4.7/4.8 and enabling interleaved thinking between tool calls. Adds a regression test asserting 4.6/4.7/4.8 build the adaptive thinking block. Note: for 4.6, reasoning.max_tokens now routes to adaptive and the explicit budget_tokens is dropped (Anthropic rejects it in adaptive mode), with depth controlled via effort instead. Verified end-to-end through the gateway — 4.6 emits the adaptive payload, Anthropic accepts it, and thinking scales with prompt complexity (0 tokens on a trivial prompt vs 263 on a hard one at equal effort).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests

    • Added tests validating adaptive-thinking request construction and regression coverage ensuring Opus 4.6/4.7/4.8 route to the adaptive configuration.
  • New Features

    • Enabled adaptive reasoning mode and adjusted reasoning output behavior for Claude Opus 4.6 across native Anthropic, AWS Bedrock, and Vertex AI mappings.
  • Documentation

    • Clarified that TEST_MODELS can override provider mappings marked as skipped for E2E testing.

Set reasoningMode adaptive on the Opus 4.6 anthropic, aws-bedrock and vertex-anthropic provider mappings so the gateway sends thinking type adaptive with output_config.effort instead of the legacy budget_tokens form, matching Opus 4.7/4.8 and enabling interleaved thinking. Adds a regression test covering 4.6/4.7/4.8.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5c76a571-c996-4a70-af68-a8b025a4d091

📥 Commits

Reviewing files that changed from the base of the PR and between 930f8c2 and b981be5.

📒 Files selected for processing (2)
  • AGENTS.md
  • packages/models/src/models/anthropic.ts
✅ Files skipped from review due to trivial changes (1)
  • AGENTS.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/models/src/models/anthropic.ts

Walkthrough

This PR updates claude-opus-4-6 provider entries to declare adaptive reasoning (reasoningMode: "adaptive", reasoningOutput: "omit"), adds a Vitest spec verifying prepareRequestBody constructs Anthropic adaptive-thinking requests, and documents that TEST_MODELS overrides provider mappings marked test: "skip".

Changes

Adaptive Reasoning Mode for Opus 4.6

Layer / File(s) Summary
Model metadata - adaptive reasoning mode
packages/models/src/models/anthropic.ts, AGENTS.md
Replaced reasoningMaxTokens: true with reasoningMode: "adaptive" and reasoningOutput: "omit" for the claude-opus-4-6 provider entries (anthropic, aws-bedrock, vertex-anthropic) and noted that TEST_MODELS can include mappings marked test: "skip".
Adaptive thinking request construction tests
packages/actions/src/prepare-request-body.adaptive.spec.ts
Adds tests and a local helper to assert prepareRequestBody("anthropic", ...) emits thinking: { type: "adaptive" } and that reasoning_effort / reasoning_max_tokens map to output_config.effort for Opus 4.6/4.7/4.8 (including an Opus 4.6 regression case).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • theopenco/llmgateway#2542: Also updates packages/models/src/models/anthropic.ts to add reasoningMode: "adaptive" / reasoningOutput: "omit" for Claude Opus provider entries.
  • theopenco/llmgateway#2435: Similar changes adding adaptive reasoning settings for Opus variants, including Opus 4.8.
  • theopenco/llmgateway#2289: Related tests and fixes around Anthropic reasoning parameter routing (reasoning_max_tokens / budget_tokens handling).

Suggested reviewers

  • smakosh
  • proxysoul
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely describes the main change: enabling adaptive thinking for Opus 4.6, which is the core objective of the PR across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/actions/src/prepare-request-body.adaptive.spec.ts`:
- Line 49: Remove the "as any" cast on the test helper return (the expression
")) as any;") and replace it with a narrow, explicit type: declare the helper's
return type (or the variable it's assigned to) to the correct interface used by
the tests (e.g., RequestBody / PrepareRequestBodyResult) or use a generic helper
signature so callers infer the correct type; if the value is temporally untyped,
use "unknown" and then cast to the precise type at the point of use. Update the
helper function/mocked builder signature so the compiler enforces the concrete
type instead of bypassing type-checking with "as any", and adjust any test
callers to match the new typed return.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8bef36a3-f1c8-4f62-a4f6-99b47c73220b

📥 Commits

Reviewing files that changed from the base of the PR and between 7778ec5 and 2ad1ec7.

📒 Files selected for processing (2)
  • packages/actions/src/prepare-request-body.adaptive.spec.ts
  • packages/models/src/models/anthropic.ts

Comment thread packages/actions/src/prepare-request-body.adaptive.spec.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2ad1ec7190

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/models/src/models/anthropic.ts Outdated
Comment on lines 977 to 978
reasoningMode: "adaptive",
reasoningMaxTokens: true,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop advertising exact budgets for adaptive Opus 4.6

Marking this mapping as adaptive while leaving reasoningMaxTokens: true advertises support for an exact reasoning.max_tokens budget (the validator and auto-router key off that flag), but the adaptive branch in prepareRequestBody sends only thinking: { type: "adaptive" } and never forwards a budget. Requests that specify reasoning.max_tokens will now be accepted or auto-routed here but silently ignore the requested budget; match the 4.7/4.8 mappings by clearing the flag on all new adaptive 4.6 mappings, or translate the budget explicitly.

Useful? React with 👍 / 👎.

contextSize: 1000000,
maxOutput: 128000,
reasoning: true,
reasoningMode: "adaptive",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Mark adaptive Opus 4.6 reasoning output as omitted

Adaptive thinking can skip emitting reasoning text, but leaving reasoningOutput undefined means the model metadata says reasoning output is expected by default (see ProviderModelMapping docs), and the gateway reasoning e2e checks use that flag. The existing Opus 4.7/4.8 adaptive mappings set reasoningOutput: "omit" for this reason; without the same setting here, 4.6 requests/tests that inspect the metadata can fail whenever the model chooses not to produce a thinking block.

Useful? React with 👍 / 👎.

@steebchen
steebchen enabled auto-merge June 7, 2026 17:44

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b981be5b5b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

maxOutput: 128000,
reasoning: true,
reasoningMaxTokens: true,
reasoningMode: "adaptive",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve effort when enabling adaptive 4.6

For Anthropic/Vertex Opus 4.6 requests that combine reasoning_effort/effort with response_format: { type: "json_schema" }, this new adaptive mapping makes prepareRequestBody put the requested depth in requestBody.output_config.effort, but the later JSON-schema branch replaces output_config with only format. Before this change, 4.6 used thinking: { type: "enabled", budget_tokens } and did not depend on output_config.effort, so structured-output calls now silently lose the requested reasoning depth; merge the JSON-schema format into the existing output_config instead of overwriting it.

Useful? React with 👍 / 👎.

@steebchen
steebchen added this pull request to the merge queue Jun 7, 2026
Merged via the queue into theopenco:main with commit 493eccf Jun 7, 2026
11 checks passed
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.

2 participants