Skip to content

(v5): Add support for bedrock provies tools #7572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: v5
Choose a base branch
from

Conversation

Und3rf10w
Copy link
Contributor

@Und3rf10w Und3rf10w commented Jul 26, 2025

Background

Amazon Bedrock provides access to Anthropic's powerful Claude models, which offer advanced features that go beyond standard text generation. These include "Computer Use" tools (Bash, Text Editor, Computer), which allow models to interact with system resources in sophisticated ways.

To leverage these features, API requests to Bedrock must include specific anthropic_beta headers and use a distinct, provider-specific format for tool configuration. The existing AI SDK Bedrock provider lacked the logic to handle these requirements, preventing users from accessing the full capabilities of Claude models on Bedrock. This PR adds the necessary support to bridge that gap.

Summary

This PR introduces comprehensive support for Anthropic's provider-defined tools within the Amazon Bedrock provider, enabling the use of advanced "Computer Use" features. The core logic has been significantly enhanced to correctly format requests for Bedrock and manage the required beta flags.

The key changes include:

  • Provider-Defined Tool Support: The tool preparation logic (bedrock-prepare-tools.ts) has been overhauled to differentiate between standard function tools and Anthropic's provider-defined tools. It now correctly processes tools like computer, bash, and textEditor, transforming them into the format required by the Bedrock API.
  • Automatic Beta Flag Injection: The SDK now automatically detects when an Anthropic tool is used and injects the corresponding anthropic_beta flag (e.g., computer-use-2024-10-22) into the additionalModelRequestFields of the request payload.
  • New anthropicBeta Provider Option: A new providerOptions.bedrock.anthropicBeta array has been added, allowing users to manually opt-in to other Anthropic beta features that don't have an associated tool.
  • Robust Payload Construction: The request-building logic in bedrock-chat-language-model.ts has been refactored to correctly merge SDK-managed fields (like beta flags and prepared tools) with user-provided additionalModelRequestFields, ensuring a valid final payload.
  • Comprehensive Documentation: A new, detailed guide has been added to the Amazon Bedrock documentation. This section covers how to use the Computer Use tools, with code examples for the bash, textEditor, and computer tools, and explains how to enable other beta features.
  • Expanded Testing: New test suites (bedrock-prepare-tools.test.ts) have been added to validate the new tool preparation logic. Core model tests have also been updated to assert that beta flags and mixed tool configurations are handled correctly.

Verification

The changes have been verified through the newly added and updated unit tests, which confirm that the request payload sent to the Bedrock API is correctly formatted for various tool and beta flag combinations.

Tasks

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A minor changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • Formatting issues have been fixed (run pnpm prettier-fix in the project root)

Future Work

  • The execute logic for the Computer Use tools is currently left to the user. Future work could involve creating higher-level abstractions or more detailed examples for common use cases, especially for the computer tool which involves screen coordinates and actions.
  • Explore providing more structured error handling and feedback for tool execution failures.

One thing to note is that Amazon documentation is conflicting on the Interleaved-thinking beta:

Here it says Interleaved-thinking-2025-05-14:
image

While here, it says interleaved-thinking-2025-05-14:
image

Related Issues

@Und3rf10w Und3rf10w force-pushed the und3rf10w/v5-bedrock-anthropic-provided-tools branch 2 times, most recently from a504460 to 5372c70 Compare July 26, 2025 13:27
@Und3rf10w Und3rf10w marked this pull request as ready for review July 26, 2025 13:36
@Und3rf10w Und3rf10w marked this pull request as draft July 26, 2025 20:36
@Und3rf10w
Copy link
Contributor Author

Actually I think I implemented this wrong, so I'll mark this back as a draft for now

@Und3rf10w Und3rf10w force-pushed the und3rf10w/v5-bedrock-anthropic-provided-tools branch from 97a7aa4 to 0ab6a7c Compare July 26, 2025 23:08
@lgrammel
Copy link
Collaborator

lmk when you want feedback

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