Skip to content

fix: normalize media format mappings - #2399

Closed
he-yufeng wants to merge 2 commits into
strands-agents:mainfrom
he-yufeng:fix/media-format-mapping
Closed

he-yufeng wants to merge 2 commits into
strands-agents:mainfrom
he-yufeng:fix/media-format-mapping

Conversation

@he-yufeng

Copy link
Copy Markdown
Contributor

Fixes part of #2204.

Summary

  • use explicit Anthropic image media-type mapping for common formats, including webp, instead of relying only on platform mimetypes
  • accept 3gp as a video input format alias and map it to Bedrock's three_gp enum value when formatting requests
  • add focused regressions for WebP image MIME type and Bedrock 3GP video formatting

I kept this PR scoped to the two deterministic provider-format bugs. The broader type/guardContent expansion mentioned in the issue should be handled separately.

To verify

  • python -m pytest tests/strands/models/test_anthropic.py::test_format_request_with_image tests/strands/models/test_anthropic.py::test_format_request_with_webp_image_uses_explicit_media_type tests/strands/models/test_bedrock.py::test_format_request_video_s3_location tests/strands/models/test_bedrock.py::test_format_request_video_3gp_maps_bedrock_enum -q
  • python -m ruff check src/strands/models/anthropic.py src/strands/models/bedrock.py src/strands/types/media.py tests/strands/models/test_anthropic.py tests/strands/models/test_bedrock.py
  • python -m ruff format --check src/strands/models/anthropic.py src/strands/models/bedrock.py src/strands/types/media.py tests/strands/models/test_anthropic.py tests/strands/models/test_bedrock.py

@yonib05 yonib05 added area-model Related to models or model providers bug Something isn't working python Pull requests that update python code labels Jun 9, 2026
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread strands-py/src/strands/types/media.py Outdated


VideoFormat = Literal["flv", "mkv", "mov", "mpeg", "mpg", "mp4", "three_gp", "webm", "wmv"]
VideoFormat = Literal["flv", "mkv", "mov", "mpeg", "mpg", "mp4", "3gp", "three_gp", "webm", "wmv"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Issue: VideoFormat now exposes both "3gp" and "three_gp", giving callers two ways to express the same format. three_gp is really the Bedrock-internal enum value, while 3gp is the user-facing extension. Exposing both publicly is a bit ambiguous.

Suggestion: Consider documenting that 3gp is the canonical input and three_gp is the Bedrock wire value (the alias map handles translation), or keep only 3gp in the public type and translate internally. Not blocking, but worth a one-line docstring note so users know which to use.

Comment thread strands-py/src/strands/models/bedrock.py Outdated
Comment thread strands-py/src/strands/models/anthropic.py
Comment thread strands-py/tests/strands/models/test_anthropic.py Outdated
@github-actions

Copy link
Copy Markdown
Contributor

Assessment: Comment (approve-leaning)

Well-scoped, correct fix for two deterministic provider-format bugs, with passing tests and clean lint/format. I confirmed the webp mimetypes behavior is platform/version-dependent, so the explicit media-type map and the monkeypatch.delitem test are a sound defensive approach. My feedback is mostly about consistency and avoiding duplication — none of it is blocking.

Review themes
  • Duplication / consistency: The new 3gp -> three_gp alias overlaps with an existing FORMAT_MAPPINGS in multiagent/a2a/executor.py, which also covers 3gpp/3g2. Worth a single source of truth or at least parity on the aliases.
  • Type/impl alignment: The "jpg" media-type key isn't reachable via the typed ImageFormat; and VideoFormat now exposes both 3gp and three_gp — a short docstring note on canonical vs. wire value would help.
  • Testing: The webp test asserts a single field; matching the full-shape assertion style of the neighboring image test would guard against regressions.

Nice, focused bugfix that keeps the broader #2204 scope appropriately separate.

@poshinchen

Copy link
Copy Markdown
Contributor

Hi, could you resolve the conflict so we could have a look?

@yonib05 yonib05 added complexity/low Touched functions have low cognitive complexity (<=10) and removed complexity/high A touched function exceeds cognitive complexity 25; may be worth splitting labels Aug 13, 2026
@poshinchen poshinchen removed their assignment Aug 25, 2026
@he-yufeng

Copy link
Copy Markdown
Contributor Author

@poshinchen 抱歉这条挂了两个月的冲突。今天核对 current main 准备解冲突时发现两类修复上游都已自行落地:bedrock 的 3gp/3g2/3gpp 别名映射(_BEDROCK_VIDEO_FORMAT_ALIASES,且 tests 2873 起有对应参数化用例)和 anthropic 图片媒体类型表(_IMAGE_MEDIA_TYPES,webp 覆盖,且不支持的格式显式 TypeError)。这条 PR 没有剩余增量了,主动关闭。媒体字面量放宽(jpg 别名)那条上游选择了严格报错的设计,我尊重这个取舍。

@he-yufeng he-yufeng closed this Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-model Related to models or model providers bug Something isn't working complexity/low Touched functions have low cognitive complexity (<=10) python Pull requests that update python code size/s

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants