Skip to content

feat: Add Claude Opus 4.7 adaptive thinking support#249

Open
bszadkowski wants to merge 2 commits into
aws-samples:mainfrom
bszadkowski:feat/opus-47-adaptive-thinking
Open

feat: Add Claude Opus 4.7 adaptive thinking support#249
bszadkowski wants to merge 2 commits into
aws-samples:mainfrom
bszadkowski:feat/opus-47-adaptive-thinking

Conversation

@bszadkowski
Copy link
Copy Markdown

Issue #, if available:

#248

Description of changes:

Adds support for Claude Opus 4.7's adaptive thinking API format, which differs from earlier Claude models in three ways (see linked issue for reproduction steps with exact error responses).

Key changes in src/api/models/bedrock.py:

  • ADAPTIVE_THINKING_MODELS — New model set for Opus 4.7+. When reasoning_effort is requested, sends thinking.type=adaptive + output_config.effort via additionalModelRequestFields instead of reasoning_config.budget_tokens.
  • NO_SAMPLING_PARAMS_MODELS — Strips temperature/topP from inferenceConfig for models that reject sampling parameters.
  • NO_ASSISTANT_PREFILL_MODELS — Added Opus 4.7 (like Opus 4.6, it doesn't support assistant message prefill).

All changes are additive and backward-compatible — existing models are unaffected.

Tests (optional, can be omitted):

This PR includes tests/conftest.py and tests/test_opus47_properties.py covering the following scenarios:

  • Adaptive thinking shape — for all reasoning_effort values (low/medium/high) on us.anthropic.claude-opus-4-7 (cross-region inference profile), verifies additionalModelRequestFields contains thinking.type=adaptive + output_config.effort, and that reasoning_config/budget_tokens are absent.
  • Sampling parameter stripping — verifies temperature and topP are removed from inferenceConfig across a range of input combinations, while maxTokens is preserved.
  • Legacy model compatibility — verifies existing Claude models (e.g. Sonnet 4.5) still produce the reasoning_config.budget_tokens format unchanged.
  • Assistant prefill handling — verifies conversations ending with an assistant message get a continuation user message appended, and user-ending conversations are unmodified.

Since the upstream repo does not currently have a test suite, maintainers may choose to exclude these files if they prefer to keep the test infrastructure decision separate.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

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