Skip to content

feat(bedrock): add support for stream and tool_runner helpers#1114

Open
Ashutosh0x wants to merge 2 commits intoanthropics:mainfrom
Ashutosh0x:feat/bedrock-tool-runner
Open

feat(bedrock): add support for stream and tool_runner helpers#1114
Ashutosh0x wants to merge 2 commits intoanthropics:mainfrom
Ashutosh0x:feat/bedrock-tool-runner

Conversation

@Ashutosh0x
Copy link

@Ashutosh0x Ashutosh0x commented Jan 7, 2026

Summary

This PR adds tool_runner and stream method aliases to both Messages and AsyncMessages classes in the Bedrock beta module.

Motivation

Fixes #1106
Fixes #1120

The tool_runner API (client.beta.messages.tool_runner()) was not available on the AnthropicBedrock or AsyncAnthropicBedrock clients. This creates feature parity for enterprise AWS Bedrock users.

Changes

Added method aliases to src/anthropic/lib/bedrock/_beta_messages.py:

  • tool_runner - Automatic tool execution loop
  • stream - Streaming message helpers

Note: parse was intentionally excluded as Bedrock doesn't currently support the structured output beta header.

Checklist

  • Changes follow existing code patterns
  • No breaking changes
  • Commit follows conventional format

@Ashutosh0x Ashutosh0x requested a review from a team as a code owner January 7, 2026 20:50
@karpetrosyan
Copy link
Collaborator

I believe Bedrock doesn’t support structured outputs at the moment.
I tried locally and got an error saying the structured output beta header isn’t supported.

@cppntn
Copy link

cppntn commented Jan 21, 2026

What's the ETA on this? At least the stream part

@Ashutosh0x
Copy link
Author

@karpetrosyan good catch! you're right, I'll remove parse and keep only stream + ool_runner which don't need that header. updating the PR now

@Ashutosh0x
Copy link
Author

@cppntn working on it now! removing the unsupported parse method and keeping stream + ool_runner. should be ready for review shortly

Adds method aliases for tool_runner and stream to both Messages and
AsyncMessages classes in the Bedrock beta module. This provides feature
parity between the first-party Anthropic client and the AnthropicBedrock
client, enabling enterprise AWS Bedrock users to use:
- Automatic tool execution loops (tool_runner)
- Streaming message helpers (stream)

Note: parse method excluded as Bedrock doesn't support the structured
output beta header required by it.

Fixes anthropics#1106
@Ashutosh0x Ashutosh0x force-pushed the feat/bedrock-tool-runner branch from 22db1bc to 9833cbc Compare January 21, 2026 16:05
@Ashutosh0x
Copy link
Author

updated! removed parse method, now only stream and ool_runner are included. ready for review

@karpetrosyan
Copy link
Collaborator

@karpetrosyan good catch! you're right, I'll remove parse and keep only stream + ool_runner which don't need that header. updating the PR now

Sorry, I mean both tool_runner and stream use parse internally, and without it they won’t work.
Third-party clients don’t really support structured outputs at the moment, so I made this tiny change so they can actually use the parse method.

Copy link
Collaborator

@karpetrosyan karpetrosyan left a comment

Choose a reason for hiding this comment

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

I was also thinking about raising a runtime error when output_format or output_config is provided to any methods, but I think we can skip that for better future compatibility, when third parties support structured outputs

class Messages(SyncAPIResource):
create = FirstPartyMessagesAPI.create
tool_runner = FirstPartyMessagesAPI.tool_runner
stream = FirstPartyMessagesAPI.stream
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
stream = FirstPartyMessagesAPI.stream
stream = FirstPartyMessagesAPI.stream
if TYPE_CHECKING:
...
else:
# parse is used by stream and tool_runner internally
parse = FirstPartyMessagesAPI.parse

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! Done - added the parse method internally while keeping it hidden from type checkers.

class AsyncMessages(AsyncAPIResource):
create = FirstPartyAsyncMessagesAPI.create
tool_runner = FirstPartyAsyncMessagesAPI.tool_runner
stream = FirstPartyAsyncMessagesAPI.stream
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
stream = FirstPartyAsyncMessagesAPI.stream
stream = FirstPartyAsyncMessagesAPI.stream
if TYPE_CHECKING:
...
else:
# parse is used by stream and tool_runner internally
parse = FirstPartyMessagesAPI.parse

Copy link
Author

Choose a reason for hiding this comment

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

Applied the same fix here for AsyncMessages - parse is now available internally.

@karpetrosyan
Copy link
Collaborator

LGTM!
nit: let’s also fix the PR title, since we’re not adding the parse method to beta messages (at least not publicly). I’d suggest:

'feat(bedrock): add support for stream and tool_runner helpers'

@Ashutosh0x Ashutosh0x changed the title feat(bedrock): add tool_runner, parse, and stream methods to beta messages feat(bedrock): add support for stream and tool_runner helpers Jan 26, 2026
@Ashutosh0x
Copy link
Author

Updated the PR title as suggested and verified the fix locally. Both sync and async clients now have the parse method available internally, which resolves the dependency for tool_runner and stream. Ready for review!

@cppntn
Copy link

cppntn commented Feb 1, 2026

@karpetrosyan @Ashutosh0x what's the ETA on this mastodontic PR?

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.

Feature Request: Add stream helper to AnthropicBedrock.beta.messages Feature Request: Add tool_runner support for AnthropicBedrock client

3 participants