Skip to content

feat(media): add S3 location support to image, document, and video content types#11

Open
github-actions[bot] wants to merge 2 commits intomainfrom
agent-tasks/10
Open

feat(media): add S3 location support to image, document, and video content types#11
github-actions[bot] wants to merge 2 commits intomainfrom
agent-tasks/10

Conversation

@github-actions
Copy link

@github-actions github-actions bot commented Jan 21, 2026

Summary

Adds native S3 location support for media content types in Bedrock, allowing users to reference images, documents, and videos stored in S3 directly rather than requiring base64 encoding.

Why

Currently users must download media from S3 and base64-encode it before sending to Bedrock. This feature enables direct S3 references, reducing memory usage and simplifying workflows for S3-hosted content. This is particularly valuable for large media files where base64 encoding is impractical.

What Changed

Type System Updates

  • Extended ImageSource, DocumentSource, and VideoSource in types/media.py to accept s3Location as an alternative to bytes
  • Added S3Location TypedDict with required uri field and optional bucketOwner for cross-account access

Provider Behavior

  • Bedrock: Passes S3 locations through unchanged to the API
  • Non-Bedrock providers: Filter S3 sources with a warning since they don't support S3 references

Code Consolidation

  • Centralized S3 source detection in _validation.has_s3_source() helper function
  • Removed duplicate _has_s3_source() methods from individual model providers

Usage Example

from strands import Agent
from strands.models.bedrock import BedrockModel

agent = Agent(model=BedrockModel())

# Reference an S3-hosted document directly
response = agent(
    [
        {
            "role": "user",
            "content": [
                {"text": "Summarize this document:"},
                {
                    "document": {
                        "format": "pdf",
                        "name": "report.pdf",
                        "source": {
                            "s3Location": {
                                "uri": "s3://my-bucket/documents/report.pdf",
                                "bucketOwner": "123456789012"  # Optional
                            }
                        }
                    }
                }
            ]
        }
    ]
)

Testing

  • Unit tests verify S3 location formatting in Bedrock requests
  • Unit tests verify S3 source filtering with warnings in non-Bedrock providers
  • Integration tests validate end-to-end S3 document processing

Resolves #10

Comment on lines 348 to 364
def _has_s3_source(self, content: ContentBlock) -> bool:
"""Check if a content block contains an S3 source.

Args:
content: Content block to check.

Returns:
True if the content block contains an S3 source, False otherwise.
"""
if "image" in content:
return "s3Location" in content["image"].get("source", {})
if "document" in content:
return "s3Location" in content["document"].get("source", {})
if "video" in content:
return "s3Location" in content["video"].get("source", {})
return False

Copy link
Owner

Choose a reason for hiding this comment

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

Can you turn this into a centralized helper method, and update the pr to use it

Copy link
Author

Choose a reason for hiding this comment

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

+1. Consider adding this as a helper function in src/strands/types/media.py since it operates on the media content types defined there, or in a shared utilities module under src/strands/models/. That would keep the model implementations DRY and ensure consistent behavior across all providers.

Copy link
Author

Choose a reason for hiding this comment

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

Done - centralized as _has_s3_source() in src/strands/models/_validation.py and all providers now use it.


def test_format_request_filters_s3_source_image(model, caplog):
"""Test that images with S3 sources are filtered out with warning."""
import logging
Copy link
Owner

Choose a reason for hiding this comment

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

top-level imports


def test_format_request_filters_s3_source_document(model, caplog):
"""Test that documents with S3 sources are filtered out with warning."""
import logging
Copy link
Owner

Choose a reason for hiding this comment

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

top-level imports


def test_has_s3_source_detection():
"""Test _has_s3_source class method correctly detects S3 sources."""
from strands.models.openai import OpenAIModel
Copy link
Owner

Choose a reason for hiding this comment

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

top-level imports

@Unshure
Copy link
Owner

Unshure commented Jan 26, 2026

/strands

@Unshure
Copy link
Owner

Unshure commented Jan 26, 2026

/strands review

@github-actions
Copy link
Author

Review Summary

Assessment: Request Changes

Key Themes:

  1. Type correctness - The S3Location TypedDict needs uri to be required per AWS Bedrock API docs
  2. Code duplication - The _has_s3_source helper is duplicated across 8 model files; should be centralized
  3. Test conventions - Imports should be at module level, not inside test functions (affects both test_anthropic.py and test_openai.py)
  4. Test coverage - Integration test requested to validate end-to-end S3 functionality

The feature implementation looks solid - the Bedrock S3 handling is correct, and the warning/skip pattern for unsupported providers is a good approach. Once the above items are addressed, this PR will be ready to merge.

Nice work on the comprehensive coverage across all model providers! 🎉

@Unshure
Copy link
Owner

Unshure commented Jan 26, 2026

/strands

@Unshure
Copy link
Owner

Unshure commented Jan 27, 2026

/strands can you add unit tests to this pull request to cover the missing model providers? You should be able to add a simple test to most model providers that passes in an s3location content block, and asserts that a warning is thrown and the content is removed in the api call.

@github-actions github-actions bot added size/xl and removed size/xl labels Jan 28, 2026
@Unshure Unshure marked this pull request as draft January 29, 2026 17:23
@Unshure Unshure marked this pull request as ready for review January 29, 2026 17:23
@Unshure Unshure force-pushed the main branch 10 times, most recently from 664745d to ab51706 Compare January 30, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add support of s3Location to image and document content types

1 participant