-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem Statement
Update the document, image, and video content types to support S3 location based on Bedrock support:
- https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_VideoSource.html
- https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ImageBlock.html
- https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_DocumentBlock.html
Use Case
Adding sources in S3 for content, enabling users to reference media files stored in Amazon S3 buckets instead of passing raw bytes.
Implementation Requirements
Based on AWS Bedrock API documentation and clarification discussion:
1. New Type Definition
Add S3Location TypedDict to src/strands/types/media.py:
class S3Location(TypedDict, total=False):
"""A storage location in an Amazon S3 bucket.
Attributes:
uri: An object URI starting with `s3://`.
bucketOwner: If the bucket belongs to another AWS account, specify that account's ID.
"""
uri: str # Required - pattern: s3://[bucket]/[key]
bucketOwner: str # Optional - 12-digit AWS account ID2. Update Source Types
Update source types in src/strands/types/media.py to support S3 locations (Union pattern - only one field should be specified):
ImageSource:
class ImageSource(TypedDict, total=False):
bytes: bytes
s3Location: S3Location # NEWDocumentSource:
class DocumentSource(TypedDict, total=False):
bytes: bytes
s3Location: S3Location # NEWVideoSource:
class VideoSource(TypedDict, total=False):
bytes: bytes
s3Location: S3Location # NEW3. Bedrock Model Provider Updates
Update src/strands/models/bedrock.py _format_request_message_content method to handle s3Location in image, document, and video sources:
- When
s3Locationis present in source, include it in the formatted output - Maintain backward compatibility with existing
byteshandling
4. Other Model Providers - Warning & Filter
For model providers that don't support S3 sources (Anthropic, OpenAI, Gemini, LiteLLM, Ollama, Mistral, LlamaAPI, LlamaCpp, SageMaker, Writer):
- Add detection for
s3Locationin image/document/video sources - Log a warning when S3 source is detected (e.g., "S3 sources are not supported by {provider}, skipping content block")
- Filter out/skip content blocks that use S3 sources
- Continue processing remaining content blocks
5. Testing Requirements
Unit Tests (tests/strands/types/):
- Test
S3Locationtype definition - Test updated
ImageSource,DocumentSource,VideoSourcewiths3Location
Unit Tests (tests/strands/models/):
- Test Bedrock model correctly formats S3 location sources
- Test Bedrock model maintains backward compatibility with bytes sources
- Test other model providers log warning and filter S3 content blocks
Files to Modify
| File | Changes |
|---|---|
src/strands/types/media.py |
Add S3Location, update ImageSource, DocumentSource, VideoSource |
src/strands/models/bedrock.py |
Handle s3Location in _format_request_message_content |
src/strands/models/anthropic.py |
Add S3 detection, warning, and filtering |
src/strands/models/openai.py |
Add S3 detection, warning, and filtering |
src/strands/models/gemini.py |
Add S3 detection, warning, and filtering |
src/strands/models/litellm.py |
Add S3 detection, warning, and filtering |
src/strands/models/ollama.py |
Add S3 detection, warning, and filtering |
src/strands/models/mistral.py |
Add S3 detection, warning, and filtering |
src/strands/models/llamaapi.py |
Add S3 detection, warning, and filtering |
src/strands/models/llamacpp.py |
Add S3 detection, warning, and filtering |
src/strands/models/sagemaker.py |
Add S3 detection, warning, and filtering |
src/strands/models/writer.py |
Add S3 detection, warning, and filtering |
tests/strands/types/test_media.py |
New file - tests for S3Location and updated source types |
tests/strands/models/test_bedrock.py |
Add tests for S3 source handling |
| Various provider test files | Add tests for S3 warning/filter behavior |
Acceptance Criteria
-
S3Locationtype is defined withuri(required) andbucketOwner(optional) fields -
ImageSource,DocumentSource,VideoSourcesupport optionals3Locationfield - Bedrock model provider correctly formats requests with S3 location sources
- Bedrock model provider maintains backward compatibility with bytes sources
- Non-Bedrock model providers log warnings when S3 sources are detected
- Non-Bedrock model providers filter out S3 source content blocks gracefully
- Unit tests cover all new functionality
- All existing tests continue to pass
- Code follows repository style guidelines (type annotations, Google docstrings, structured logging)