feat(bedrock): add support for stream and tool_runner helpers#1114
feat(bedrock): add support for stream and tool_runner helpers#1114Ashutosh0x wants to merge 2 commits intoanthropics:mainfrom
Conversation
|
I believe Bedrock doesn’t support structured outputs at the moment. |
|
What's the ETA on this? At least the |
|
@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 |
|
@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
22db1bc to
9833cbc
Compare
|
updated! removed parse method, now only stream and ool_runner are included. ready for review |
Sorry, I mean both |
karpetrosyan
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
| stream = FirstPartyMessagesAPI.stream | |
| stream = FirstPartyMessagesAPI.stream | |
| if TYPE_CHECKING: | |
| ... | |
| else: | |
| # parse is used by stream and tool_runner internally | |
| parse = FirstPartyMessagesAPI.parse |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
| stream = FirstPartyAsyncMessagesAPI.stream | |
| stream = FirstPartyAsyncMessagesAPI.stream | |
| if TYPE_CHECKING: | |
| ... | |
| else: | |
| # parse is used by stream and tool_runner internally | |
| parse = FirstPartyMessagesAPI.parse |
There was a problem hiding this comment.
Applied the same fix here for AsyncMessages - parse is now available internally.
|
LGTM! 'feat(bedrock): add support for stream and tool_runner helpers' |
|
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! |
|
@karpetrosyan @Ashutosh0x what's the ETA on this mastodontic PR? |
Summary
This PR adds
tool_runnerandstreammethod aliases to both Messages and AsyncMessages classes in the Bedrock beta module.Motivation
Fixes #1106
Fixes #1120
The
tool_runnerAPI (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 loopstream- Streaming message helpersNote:
parsewas intentionally excluded as Bedrock doesn't currently support the structured output beta header.Checklist