Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Jun 9, 2025

Description

Fixes #4201

Adds comprehensive Extended Thinking (reasoning budget) support for AWS Bedrock Claude models (Sonnet 4, Opus 4, and 3.7 Sonnet). This implementation provides the equivalent functionality to the "Enable Reasoning Mode" available in the direct Anthropic provider, but integrated with AWS Bedrock's API structure.

Changes Made

🎯 Core Implementation

  • Added supportsReasoningBudget: true to Claude models in packages/types/src/providers/bedrock.ts
  • Implemented extended thinking support in src/api/providers/bedrock.ts with:
    • additionalModelRequestFields.thinking parameter support
    • Proper anthropic_version header handling
    • Dynamic budget token configuration
    • Conditional parameter exclusion (topP) when thinking is enabled

🔄 Stream Processing Enhancements

  • Enhanced stream event handling to properly process reasoning content:
    • Support for reasoningContent blocks
    • Support for thinking content types
    • Proper content block indexing and formatting
    • Multiple fallback structures for AWS SDK compatibility

🧪 Comprehensive Testing

  • Added extensive test suite in src/api/providers/__tests__/bedrock-reasoning.test.ts with 280 lines of tests covering:
    • Extended thinking parameter inclusion for supported models
    • Parameter exclusion for non-supported models
    • Stream processing for reasoning content
    • Multiple event structure compatibility
    • Error handling and validation

🎨 UI Improvements

  • Updated ThinkingBudget component in webview-ui/src/components/settings/ThinkingBudget.tsx to:
    • Properly calculate max token limits for Bedrock models
    • Show reasoning budget controls when supportsReasoningBudget is true
    • Integrate with existing reasoning effort settings
  • Fixed ApiOptions component to conditionally render ThinkingBudget only when models are available
  • Improved Bedrock provider settings layout and conditional rendering

🛠️ Error Handling

  • Added VALIDATION_ERROR handling for parameter validation issues
  • Enhanced error messaging with specific guidance for extended thinking problems
  • Improved logging for debugging extended thinking requests

Technical Implementation Details

API Integration

The implementation follows AWS Bedrock's official extended thinking specification:

additionalModelRequestFields: {
  thinking: {
    type: "enabled",
    budget_tokens: metadata?.thinking?.maxThinkingTokens || modelConfig.reasoningBudget || 4096
  }
}

Stream Processing

Handles multiple AWS SDK event structures:

  • contentBlock.reasoningContent.text (official AWS docs structure)
  • contentBlock.type === "thinking" (alternative structure)
  • delta.reasoningContent.text and delta.thinking (delta events)

Model Support

Enabled for:

  • anthropic.claude-sonnet-4-20250514-v1:0
  • anthropic.claude-opus-4-20250514-v1:0
  • anthropic.claude-3-7-sonnet-20250219-v1:0

Testing Performed

  • All existing tests pass - verified backward compatibility
  • New test suite passes - 280 lines of reasoning-specific tests
  • Manual testing completed:
    • Extended thinking activates correctly for supported models
    • Reasoning content renders properly in the UI
    • Settings UI shows/hides controls appropriately
    • Parameter validation works correctly
    • Error handling provides helpful messages

Verification of Acceptance Criteria

From issue #4201:

  • Models show reasoning support: Instead of :thinking variants, models now support reasoning budget configuration
  • Enable Reasoning Mode equivalent: ThinkingBudget component provides the same functionality as Anthropic provider
  • Max Thinking Tokens configuration: Fully configurable budget with appropriate limits
  • Extended thinking triggers: Reasoning now activates correctly when enabled and supported
  • UI consistency: Matches the pattern established by other providers

Checklist

  • ✅ Code follows project style guidelines
  • ✅ Self-review completed
  • ✅ Comments added for complex logic (stream processing, reasoning detection)
  • ✅ No breaking changes to existing Bedrock functionality
  • ✅ Comprehensive test coverage for new functionality
  • ✅ Error handling covers edge cases and provides helpful messages
  • ✅ UI changes are consistent with existing design patterns
  • ✅ Performance impact minimal (only adds parameters when needed)

Related Issues

Screenshots/Demo

Before: No reasoning budget controls visible for Bedrock models
After: ThinkingBudget component appears for supported Bedrock models, matching Anthropic provider functionality

Users can now:

  1. Select a supported Claude model in Bedrock
  2. See the "Enable Reasoning Mode" toggle and token budget slider
  3. Configure reasoning parameters just like with the direct Anthropic provider
  4. Experience extended thinking in their conversations with proper reasoning content rendering

Important

Adds reasoning budget support to AWS Bedrock models, enabling extended thinking capabilities with updated configurations, stream processing, UI, and error handling.

  • Behavior:
    • Adds supportsReasoningBudget: true to Claude models in bedrock.ts.
    • Implements extended thinking in bedrock.ts with additionalModelRequestFields.thinking and dynamic budget token configuration.
    • Excludes topP parameter when thinking is enabled.
  • Stream Processing:
    • Enhances stream event handling in bedrock.ts to process reasoningContent and thinking content types.
  • Testing:
    • Adds tests in bedrock-reasoning.test.ts for reasoning parameter inclusion, stream processing, and error handling.
  • UI:
    • Updates ThinkingBudget.tsx to calculate max token limits and show reasoning budget controls.
    • Updates ApiOptions.tsx to conditionally render ThinkingBudget.
  • Error Handling:
    • Adds VALIDATION_ERROR handling for parameter validation issues in bedrock.ts.

This description was created by Ellipsis for dafa25b. You can customize this summary. It will automatically update as commits are pushed.

@hannesrudolph hannesrudolph requested review from cte, jr and mrubens as code owners June 9, 2025 22:34
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. enhancement New feature or request UI/UX UI/UX related or focused labels Jun 9, 2025
@hannesrudolph hannesrudolph moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jun 9, 2025
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jun 10, 2025
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jun 11, 2025
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Jun 11, 2025
…ponents

- Introduced `supportsReasoningBudget` property in Bedrock models.
- Enhanced `AwsBedrockHandler` to handle reasoning budget in payloads.
- Updated `ThinkingBudget` component to dynamically set max tokens based on reasoning support.
- Modified `ApiOptions` and `Bedrock` components to conditionally render `ThinkingBudget`.
- Added tests for extended thinking functionality in `bedrock-reasoning.test.ts`.
- Simplify ThinkingBudget ternary logic since component only renders when reasoning budget supported
- Break down complex thinking enabled condition with clear documentation
- Replace 'as any' usage with proper TypeScript interfaces for AWS SDK events
- Add comprehensive documentation for multiple stream structures explaining AWS SDK compatibility
@hannesrudolph hannesrudolph moved this from PR [Changes Requested] to PR [Needs Prelim Review] in Roo Code Roadmap Jun 11, 2025
@ellipsis-dev
Copy link
Contributor

ellipsis-dev bot commented Jun 11, 2025

⚠️ This PR is too big for Ellipsis, but support for larger PRs is coming soon. If you want us to prioritize this feature, let us know at [email protected]


Generated with ❤️ by ellipsis.dev

Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

LGTM with emphasis on "looks" cause I don't have a way to test this.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 12, 2025
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Jun 12, 2025
@hannesrudolph
Copy link
Collaborator Author

I tested it

@mrubens mrubens merged commit fb3a728 into main Jun 12, 2025
21 checks passed
@mrubens mrubens deleted the 4201-fix branch June 12, 2025 16:39
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Jun 12, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jun 12, 2025
@daniel-lxs daniel-lxs restored the 4201-fix branch June 13, 2025 12:49
@daniel-lxs daniel-lxs deleted the 4201-fix branch June 13, 2025 13:31
mrubens pushed a commit that referenced this pull request Jun 13, 2025
* Add reasoning budget support to Bedrock models and update related components

- Introduced `supportsReasoningBudget` property in Bedrock models.
- Enhanced `AwsBedrockHandler` to handle reasoning budget in payloads.
- Updated `ThinkingBudget` component to dynamically set max tokens based on reasoning support.
- Modified `ApiOptions` and `Bedrock` components to conditionally render `ThinkingBudget`.
- Added tests for extended thinking functionality in `bedrock-reasoning.test.ts`.

* Add BedrockThinkingConfig interface and update payload structure

* fix: address PR review feedback (#4481)

- Simplify ThinkingBudget ternary logic since component only renders when reasoning budget supported
- Break down complex thinking enabled condition with clear documentation
- Replace 'as any' usage with proper TypeScript interfaces for AWS SDK events
- Add comprehensive documentation for multiple stream structures explaining AWS SDK compatibility

* feat: show ThinkingBudget component unconditionally

Remove selectedProviderModels.length check to display ThinkingBudget
for all providers, not just those with available models

---------

Co-authored-by: hannesrudolph <[email protected]>
cte pushed a commit that referenced this pull request Jun 24, 2025
…nking (#4201) (#4481)

* Add reasoning budget support to Bedrock models and update related components

- Introduced `supportsReasoningBudget` property in Bedrock models.
- Enhanced `AwsBedrockHandler` to handle reasoning budget in payloads.
- Updated `ThinkingBudget` component to dynamically set max tokens based on reasoning support.
- Modified `ApiOptions` and `Bedrock` components to conditionally render `ThinkingBudget`.
- Added tests for extended thinking functionality in `bedrock-reasoning.test.ts`.

* Add BedrockThinkingConfig interface and update payload structure

* fix: address PR review feedback (#4481)

- Simplify ThinkingBudget ternary logic since component only renders when reasoning budget supported
- Break down complex thinking enabled condition with clear documentation
- Replace 'as any' usage with proper TypeScript interfaces for AWS SDK events
- Add comprehensive documentation for multiple stream structures explaining AWS SDK compatibility
cte pushed a commit that referenced this pull request Jun 24, 2025
* Add reasoning budget support to Bedrock models and update related components

- Introduced `supportsReasoningBudget` property in Bedrock models.
- Enhanced `AwsBedrockHandler` to handle reasoning budget in payloads.
- Updated `ThinkingBudget` component to dynamically set max tokens based on reasoning support.
- Modified `ApiOptions` and `Bedrock` components to conditionally render `ThinkingBudget`.
- Added tests for extended thinking functionality in `bedrock-reasoning.test.ts`.

* Add BedrockThinkingConfig interface and update payload structure

* fix: address PR review feedback (#4481)

- Simplify ThinkingBudget ternary logic since component only renders when reasoning budget supported
- Break down complex thinking enabled condition with clear documentation
- Replace 'as any' usage with proper TypeScript interfaces for AWS SDK events
- Add comprehensive documentation for multiple stream structures explaining AWS SDK compatibility

* feat: show ThinkingBudget component unconditionally

Remove selectedProviderModels.length check to display ThinkingBudget
for all providers, not just those with available models

---------

Co-authored-by: hannesrudolph <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer PR - Needs Review size:XL This PR changes 500-999 lines, ignoring generated files. UI/UX UI/UX related or focused

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

AWS Bedrock does not show or support Sonnet and Opus 4 Extended Thinking

4 participants