feat(bedrock): add tool_runner support with message sanitization#1107
Open
lingjiekong wants to merge 1 commit intoanthropics:mainfrom
Open
feat(bedrock): add tool_runner support with message sanitization#1107lingjiekong wants to merge 1 commit intoanthropics:mainfrom
lingjiekong wants to merge 1 commit intoanthropics:mainfrom
Conversation
This PR enables the `tool_runner` API on AWS Bedrock by: 1. Adding `tool_runner` delegation to Messages and AsyncMessages classes 2. Wrapping `create`, `parse`, and `stream` methods with sanitization 3. Stripping Bedrock-unsupported fields (`parsed_output`, `caller`) ## Problem When using `client.beta.messages.tool_runner()` with Bedrock, the SDK adds internal tracking fields that Bedrock's stricter API validation rejects with 400 errors: - `parsed_output` on text blocks (structured output tracking) - `caller` on tool_use blocks (code execution features) ## Solution The `_sanitize_for_bedrock()` function strips these fields from message content blocks before sending to Bedrock. The sanitization is applied at the Bedrock layer so it doesn't affect direct Anthropic API usage. ## Tested Features - tool_runner API access - Automatic tool execution loop - Compaction control (context management) - Sync and async clients 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR enables the
tool_runnerAPI on AWS Bedrock by adding message sanitization to strip Bedrock-unsupported fields.Fixes #1106
Problem
When using
client.beta.messages.tool_runner()with Bedrock, the SDK adds internal tracking fields that Bedrock's stricter API validation rejects with 400 errors:Root Cause
tool_runnernot exposed: The BedrockMessagesclass only delegatescreate, nottool_runnerparsed_outputrejection: The SDK's.parse()method addsparsed_outputto text blocks for structured output trackingcallerrejection: The SDK addscallerto tool_use blocks for code execution featuresSolution
tool_runnerdelegation - Expose the tool_runner API on Bedrock clients_sanitize_for_bedrock()helper - Strip unsupported fields from message content blockscreate,parse,streammethods - Apply sanitization transparently before API callsThe sanitization is applied at the Bedrock layer so it doesn't affect direct Anthropic API usage.
Changes
BEDROCK_UNSUPPORTED_FIELDSset for extensibility_sanitize_for_bedrock()sanitization functioncreate,parse,streammethods with sanitizationtool_runnerdelegation to both sync and async classesTested Features
tool_runnerAPI access on Bedrocktoken_threshold)parsed_outputfield sanitizationcallerfield sanitizationExample Usage
Test plan
tool_runnerworks with Bedrock after patchparsed_outputorcallerfieldscreatefunctionality still works🤖 Generated with Claude Code