Skip to content

Conversation

@Premshay
Copy link
Contributor

@Premshay Premshay commented Dec 10, 2024

Problem:
The current Bedrock implementation uses the Bedrock SDK, which requires separate handling for different model types and doesn't provide a unified streaming interface.

Solution:
Integrate the Bedrock Runtime API to provide a single, unified interface for all Bedrock models (Claude and Nova) using the ConverseStream API. This eliminates the need for separate handlers while maintaining all existing functionality.

Key Changes:

  • Refactored AwsBedrockHandler to use @aws-sdk/client-bedrock-runtime
  • Enhanced bedrock-converse-format.ts to handle all content types and properly transform between Anthropic and Bedrock formats
  • Maintained cross-region inference support with proper region prefixing
  • Added support for prompt caching configuration
  • Improved AWS credentials handling to better support default providers
  • Added proper error handling and token tracking for all response types

Dependencies:

  • Added @aws-sdk/client-bedrock-runtime for unified API access
  • Removed @anthropic-ai/bedrock-sdk dependency

Testing:

  • Verified message format conversion for all content types
  • Tested cross-region inference functionality
  • Validated streaming responses for both Claude and Nova models

This change simplifies the codebase by providing a single, consistent interface for all Bedrock models while maintaining full compatibility with existing features.


Important

Refactor Bedrock provider to use Bedrock Runtime API for unified model handling, improved error handling, and enhanced AWS credentials management.

  • Behavior:
    • Refactored AwsBedrockHandler in bedrock.ts to use @aws-sdk/client-bedrock-runtime for unified model handling.
    • Added prompt caching configuration and improved AWS credentials handling.
    • Enhanced error handling and token tracking for all response types.
  • Transformations:
    • Added convertToBedrockConverseMessages and convertToAnthropicMessage in bedrock-converse-format.ts for message format conversion.
  • Models:
    • Updated bedrockModels in api.ts to include new model configurations and pricing.
  • Dependencies:
    • Added @aws-sdk/client-bedrock-runtime and removed @anthropic-ai/bedrock-sdk in package.json.

This description was created by Ellipsis for 8280a80c93c12dd9776b8de5a8f4a40c43a05061. It will automatically update as commits are pushed.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Reviewed everything up to 8280a80c93c12dd9776b8de5a8f4a40c43a05061 in 3 minutes and 7 seconds

More details
  • Looked at 593 lines of code in 4 files
  • Skipped 1 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. package.json:174
  • Draft comment:
    Remove the @anthropic-ai/bedrock-sdk dependency as it is no longer used.
  • Reason this comment was not posted:
    Comment did not seem useful.
2. src/api/providers/bedrock.ts:69
  • Draft comment:
    Rename awsusePromptCache to awsUsePromptCache for consistency with camelCase convention.
  • Reason this comment was not posted:
    Marked as duplicate.
3. src/api/providers/bedrock.ts:128
4. src/api/transform/bedrock-converse-format.ts:154

Workflow ID: wflow_RW7qdTRZ8rfq7aqx


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@ColemanRoo
Copy link
Contributor

@Premshay Would you add some unit tests for your changes please? Specifically for changes in:
src/api/transform/bedrock-converse-format.ts
src/api/providers/bedrock.ts

@Premshay
Copy link
Contributor Author

@Premshay Would you add some unit tests for your changes please? Specifically for changes in: src/api/transform/bedrock-converse-format.ts src/api/providers/bedrock.ts

Added unit tests. bedrock-converse-format tests all pass. bedrock.ts most tests fail, but real-life testing shows everything works - messages, cline tools are working, images are analyzed properly. All real-life tests pass, for all claude and nova models. So I think that the tests aren't so good and should be refactored.

it would also be nice to a video analysis support (Nova support video, and the code already includes the basic use, now we need to get Cline to allow uploading videos like images).
Easy Future additions are adding more bedrock models, i.e. Llama 3.2, etc.

And after Amazon releases from preview the prompt caching an intelligent prompt routing features, we can add those quickly and allow cost savings for all.

@Premshay Premshay closed this Dec 10, 2024
@Premshay Premshay reopened this Dec 10, 2024
@Premshay
Copy link
Contributor Author

Premshay commented Dec 10, 2024

@Premshay Would you add some unit tests for your changes please? Specifically for changes in: src/api/transform/bedrock-converse-format.ts src/api/providers/bedrock.ts

Sorry for the delay, just saw that the tests weren't committed. You will see them now, @mrubens, @ColemanRoo

@ColemanRoo
Copy link
Contributor

@Premshay Would you add some unit tests for your changes please? Specifically for changes in: src/api/transform/bedrock-converse-format.ts src/api/providers/bedrock.ts

Sorry for the delay, just saw that the tests weren't committed. You will see them now, @mrubens, @ColemanRoo

Hey @Premshay thank you for adding the tests! Can you please make sure to merge latest Roo-Cline/main into your branch and then increment the version number in package.json
Also make sure you are not committing any failing tests as your PR will not be allowed to merge with failing unit tests

@Premshay
Copy link
Contributor Author

@Premshay Would you add some unit tests for your changes please? Specifically for changes in: src/api/transform/bedrock-converse-format.ts src/api/providers/bedrock.ts

Sorry for the delay, just saw that the tests weren't committed. You will see them now, @mrubens, @ColemanRoo

Hey @Premshay thank you for adding the tests! Can you please make sure to merge latest Roo-Cline/main into your branch and then increment the version number in package.json Also make sure you are not committing any failing tests as your PR will not be allowed to merge with failing unit tests

Done. Also added Meta 3, 3.1, 3.2 models available on bedrock api.

package.json Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

For this PR to be able to merge the update published, you will need to update the version number in package.json
2.1.18 -> 2.1.19

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@Premshay
Copy link
Contributor Author

@Premshay Would you add some unit tests for your changes please? Specifically for changes in: src/api/transform/bedrock-converse-format.ts src/api/providers/bedrock.ts

Sorry for the delay, just saw that the tests weren't committed. You will see them now, @mrubens, @ColemanRoo

Hey @Premshay thank you for adding the tests! Can you please make sure to merge latest Roo-Cline/main into your branch and then increment the version number in package.json Also make sure you are not committing any failing tests as your PR will not be allowed to merge with failing unit tests

Updated the tests and all are passing now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I missed this @Premshay can you rebuild your package-lock.json too so it has the correct version number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Cline added 5 commits December 11, 2024 22:31
Problem:
The current Bedrock implementation uses the Bedrock SDK, which requires separate handling for different model types and doesn't provide a unified streaming interface.

Solution:
Integrate the Bedrock Runtime API to provide a single, unified interface for all Bedrock models (Claude and Nova) using the ConverseStream API. This eliminates the need for separate handlers while maintaining all existing functionality.

Key Changes:
- Refactored AwsBedrockHandler to use @aws-sdk/client-bedrock-runtime
- Enhanced bedrock-converse-format.ts to handle all content types and properly transform between Anthropic and Bedrock formats
- Maintained cross-region inference support with proper region prefixing
- Added support for prompt caching configuration
- Improved AWS credentials handling to better support default providers
- Added proper error handling and token tracking for all response types

Dependencies:
- Added @aws-sdk/client-bedrock-runtime for unified API access
- Removed @anthropic-ai/bedrock-sdk dependency

Testing:
- Verified message format conversion for all content types
- Tested cross-region inference functionality
- Validated streaming responses for both Claude and Nova models

This change simplifies the codebase by providing a single, consistent interface for all Bedrock models while maintaining full compatibility with existing features.
- Fix TypeScript error in ConverseStreamCommand payload
- Add proper JSON parsing for test stream events
- Improve error handling with proper Error objects
- Add test-specific model info with required fields
- Fix cross-region inference and prompt cache config
- Add tests for AWS Bedrock handler (stream handling, config, errors)
- Add tests for message format conversion (text, images, tools)
- Add tests for stream event parsing and transformation
- Add tests for cross-region inference and prompt cache
- Add tests for metadata and message lifecycle events
@Premshay Premshay reopened this Dec 11, 2024
@Premshay
Copy link
Contributor Author

Had to redo the commits because of compounding unresolvable conflicts. It should now be ok.

@Premshay Premshay requested a review from ColemanRoo December 11, 2024 21:06
@changeset-bot
Copy link

changeset-bot bot commented Dec 12, 2024

⚠️ No Changeset found

Latest commit: e93f590

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@Premshay
Copy link
Contributor Author

why is this PR not merged yet?
Nothing is missing, and versions are being updated everyday, making this PR backwards in versions package each time...
How can we merge it?

@ColemanRoo
Copy link
Contributor

why is this PR not merged yet? Nothing is missing, and versions are being updated everyday, making this PR backwards in versions package each time... How can we merge it?

Hi @Premshay Sorry for the delay; I am finally getting around to testing your PR and I noticed that when I ran through a simple task of having Roo-Cline write tests for me, the tokens and API costs in the screenshot
image
were not updating as the task moved forward.
I am also a bit concerned with this PR as the numbers in the screenshot do not feel accurate to how long the task took.
It seems like those values only updated after the final call instead of incrementally.

Can you please take a look at why this might be happening? As of right now, I do not feel confident in merging this PR.

@Premshay
Copy link
Contributor Author

why is this PR not merged yet? Nothing is missing, and versions are being updated everyday, making this PR backwards in versions package each time... How can we merge it?

Hi @Premshay Sorry for the delay; I am finally getting around to testing your PR and I noticed that when I ran through a simple task of having Roo-Cline write tests for me, the tokens and API costs in the screenshot image were not updating as the task moved forward. I am also a bit concerned with this PR as the numbers in the screenshot do not feel accurate to how long the task took. It seems like those values only updated after the final call instead of incrementally.

Can you please take a look at why this might be happening? As of right now, I do not feel confident in merging this PR.

What you are describing sounds like every time I have used openrouter or Bedrock before. In other words: This seems to be a Cline issue in general. That's the way Cline works on calculating the usage numbers it gets.
What in the numbers seems to not make sense to you?
I've tested the different models, and I can see the differences as expected.
In any case I'll go through it again and see if the usage info can be further improved.

@ColemanRoo
Copy link
Contributor

ColemanRoo commented Dec 16, 2024

why is this PR not merged yet? Nothing is missing, and versions are being updated everyday, making this PR backwards in versions package each time... How can we merge it?

Hi @Premshay Sorry for the delay; I am finally getting around to testing your PR and I noticed that when I ran through a simple task of having Roo-Cline write tests for me, the tokens and API costs in the screenshot image were not updating as the task moved forward. I am also a bit concerned with this PR as the numbers in the screenshot do not feel accurate to how long the task took. It seems like those values only updated after the final call instead of incrementally.
Can you please take a look at why this might be happening? As of right now, I do not feel confident in merging this PR.

What you are describing sounds like every time I have used openrouter or Bedrock before. In other words: This seems to be a Cline issue in general. That's the way Cline works on calculating the usage numbers it gets. What in the numbers seems to not make sense to you? I've tested the different models, and I can see the differences as expected. In any case I'll go through it again and see if the usage info can be further improved.

In regards to the numbers, for the task I had your PR version do, it wrote ~400 lines of brand new code; it iterated over the code multiple times and ran tests and coverage reports each time. It was quick, but each time it accomplished a task, the Tokens: and API Cost values should have updated (which they did not) and those numbers only updated at the end. And from my previous experiences have Cline perform test writing tasks, the numbers that DID eventually appear at the end seem too low to me, indicating it did not aggregate each call to openrouter and only recorded the last one.

@Premshay
Copy link
Contributor Author

Thanks for the added information.
One point to be sure: you wrote "to openrouter". You meant "to bedrock", right?

@ColemanRoo
Copy link
Contributor

Thanks for the added information. One point to be sure: you wrote "to openrouter". You meant "to bedrock", right?

The key I use is an openRouter API Key, so if that routes differently in your PR, then that could be an issue as well. But my assumption is that bedrock is just the grouping of all the different models?

But either way, using the same key I should get the same experience between existing marketplace version and your PR version.

@Premshay
Copy link
Contributor Author

Premshay commented Dec 16, 2024 via email

@ColemanRoo
Copy link
Contributor

I'm sorry, I must be missing something here. My PR is only for using the Bedrock service. It can only be used providing aws credentials, and the only models that will work would be those that the person with those credentials have access too. Otherwise you get specific errors stating lack of credentials or non access to model. The Bedrock provider can't be checked with anything but AWS credentials. Could you further explain?

On Mon, Dec 16, 2024, 22:41 Mike C @.> wrote: Thanks for the added information. One point to be sure: you wrote "to openrouter". You meant "to bedrock", right? The key I use is an openRouter API Key, so if that routes differently in your PR, then that could be an issue as well. But my assumption is that bedrock is just the grouping of all the different models? But either way, using the same key I should get the same experience between existing marketplace version and your PR version. — Reply to this email directly, view it on GitHub <#60 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGWMILCZDELXJXE3PNLSSUT2F43G7AVCNFSM6AAAAABTLSYLP6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNBWGY4TONRVG4 . You are receiving this because you were mentioned.Message ID: @.>

hmmm, ok

Could you go into details exactly how one would go about using the bedrock service? We need to be able to test these changes...

However, I am still concerned that my current experience differs between your PR and the currently available version when it comes to tracking tokens and cost as the task progresses.

@Premshay
Copy link
Contributor Author

Premshay commented Dec 16, 2024 via email

Comment on lines +177 to +178
cacheWritesPrice: 3.75, // per million tokens
cacheReadsPrice: 0.3, // per million tokens
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Premshay out of curiosity where do you look up these values from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW, I've prepared infrastructure but haven't fully connected the Bedrock prompt caching feature. Reason is that it's still in preview for limited number of users. When this is fully released it'll be easy to apply. I also hope to integrate the new intelligent prompt routing when it is fully released and tested.

@ColemanRoo ColemanRoo merged commit 1be51a4 into RooCodeInc:main Dec 17, 2024
6 checks passed
roomote pushed a commit that referenced this pull request Jul 8, 2025
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.

3 participants