Skip to content

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

@Unshure

Description

@Unshure

Problem Statement

Update the document, image, and video content types to support S3 location based on Bedrock support:

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 ID

2. 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  # NEW

DocumentSource:

class DocumentSource(TypedDict, total=False):
    bytes: bytes
    s3Location: S3Location  # NEW

VideoSource:

class VideoSource(TypedDict, total=False):
    bytes: bytes
    s3Location: S3Location  # NEW

3. 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 s3Location is present in source, include it in the formatted output
  • Maintain backward compatibility with existing bytes handling

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 s3Location in 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 S3Location type definition
  • Test updated ImageSource, DocumentSource, VideoSource with s3Location

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

  • S3Location type is defined with uri (required) and bucketOwner (optional) fields
  • ImageSource, DocumentSource, VideoSource support optional s3Location field
  • 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions