Skip to content

feat: make BedrockModel._format_request and _convert_non_streaming_to…#2315

Open
celealramos wants to merge 1 commit into
strands-agents:mainfrom
celealramos:feat/make-bedrock-model-methods-public
Open

feat: make BedrockModel._format_request and _convert_non_streaming_to…#2315
celealramos wants to merge 1 commit into
strands-agents:mainfrom
celealramos:feat/make-bedrock-model-methods-public

Conversation

@celealramos
Copy link
Copy Markdown

…_streaming public

Description

Users building custom Bedrock integrations need to format requests and convert non-streaming responses outside of the standard stream() flow. For example, to inspect or modify the request before sending, or to integrate with custom invocation pipelines. Currently these capabilities are only available through private methods (_format_request, _convert_non_streaming_to_streaming), making them fragile to depend on and inconsistent with other providers (Anthropic, Mistral, Ollama, Writer) that already expose public format_request.

Public API Changes
BedrockModel now exposes two public methods that delegate to the existing private implementations:

Before: rely on private API (fragile, undocumented)
model = BedrockModel(model_id="us.anthropic.claude-sonnet-4-20250514-v1:0")
request = model._format_request(messages, tool_specs)
events = model._convert_non_streaming_to_streaming(response)

After: stable public API
model = BedrockModel(model_id="us.anthropic.claude-sonnet-4-20250514-v1:0")
request = model.format_request(messages, tool_specs)
events = model.convert_non_streaming_to_streaming(response)

The private methods now emit a DeprecationWarning when called directly, with removal planned for September 2026. Internal call sites continue dispatching through the private methods (with warnings suppressed) so subclass overrides are honored without behavioral changes.

Related Issues

#2308

Documentation PR

Type of Change

New feature

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • [ x] I have read the CONTRIBUTING document
  • [ x] I have added any necessary tests that prove my fix is effective or my feature works
  • [x ] I have updated the documentation accordingly
  • [ x] I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • [x ] Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@zastrowm zastrowm force-pushed the feat/make-bedrock-model-methods-public branch from 9d1ae79 to 078434b Compare May 26, 2026 18:17
@github-actions github-actions Bot added size/m and removed size/m labels May 26, 2026
"""Format a Bedrock converse stream request.

.. deprecated::
Use :meth:`format_request` instead. This will be removed in September 2026.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't call out a specific date; it's very subject to change.

Returns:
A Bedrock converse stream request.
"""
with warnings.catch_warnings():
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The flow is a little odd right now; could we switch to:

  • format_request is the entry point and what the model calls internally
  • format_request checks if _format_request is overridden; if it is it emits a warning and calls it, otherwise it invokes _format_request_impl (which is the default implementation) which calls _format_request

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we're also okay breaking users of _ as well given that it's marked as private.

That's what we went with for #2370

tool_specs: list[ToolSpec] | None = None,
system_prompt_content: list[SystemContentBlock] | None = None,
tool_choice: ToolChoice | None = None,
) -> dict[str, Any]:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's add kwargs here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The changes in https://github.com/strands-agents/sdk-python/pull/2093/changes#r3306308887 is an example of an additive parameter FWIW

@zastrowm zastrowm changed the title feat: Make BedrockModel._format_request and _convert_non_streaming_to… feat: make BedrockModel._format_request and _convert_non_streaming_to… May 26, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@yonib05 yonib05 added area-provider Related to model providers area-devx Developer experience improvements python Pull requests that update python code enhancement New feature or request labels May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-devx Developer experience improvements area-provider Related to model providers enhancement New feature or request python Pull requests that update python code size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants