[BUG] A2A adapter: audio parts round trip as video/mpeg, and MIME parameters leak into document format
Human Overview
No response
Checks
- [x] I have updated to the lastest minor and patch version of Strands
- [x] I have checked the documentation and this is not expected behavior
- [x] I have searched ./issues and there are no duplicates of my issue
SDK Language
TypeScript
Strands Version
main at ad1ae00
Language Runtime Version
Bun 1.3.9 (Node v26.13.0 also installed)
Operating System
macOS 26.6.2
Installation Method
git clone
Steps to Reproduce
Hi all, hope you're doing well! The A2A adapter in strands-ts/src/a2a/adapters.ts turns audio file parts into documents that come back out as video/mpeg, and it keeps MIME parameters like ; charset=utf-8 inside the document format.
When an A2A FilePart comes in, _convertFilePart picks a block type with _getFileType (119 to 128) and a format with _getFormat (139 to 157). _getFormat lowercases the MIME type (144), tries the exact lookup toMediaFormat (mime.ts:110), and on a miss falls back to split('/').pop() (153 to 154).
- Send a
FilePartwithmimeType: 'audio/mpeg'. _getFileTypehas no audio branch, so it returnsunknownand the part becomes aDocumentBlock(line 101).toMediaFormat('audio/mpeg')misses, so the format becomesmpeg.- On the way out,
toMimeType('mpeg')maps tovideo/mpeg(mime.ts:47).audio/wavcomes out with no mimeType at all. - Separately, send
text/plain; charset=utf-8. The exact lookup misses because of the parameter, so the format becomes"plain; charset=utf-8"and the mimeType is undefined on the way out.application/pdf; name=xbecomes"pdf; name=x".
Plain text/plain works fine.
Expected Behavior
Audio parts become an AudioBlock (it already exists in types/media.ts) and keep their audio MIME type on the way back out. MIME parameters are ignored when picking the format, so text/plain; charset=utf-8 becomes txt and application/pdf; name=x becomes pdf.
Actual Behavior
Minimal repro, run from the repo root with Bun against the real adapter:
import {
partsToContentBlocks,
contentBlocksToParts,
} from "./strands-ts/src/a2a/adapters.ts";
import { encodeBase64 } from "./strands-ts/src/types/media.ts";
for (const mimeType of [
"text/plain",
"text/plain; charset=utf-8",
"application/pdf; name=x",
"audio/mpeg",
"audio/wav",
]) {
const [block] = partsToContentBlocks([
{ kind: "file", file: { bytes: encodeBase64("hi"), mimeType, name: "f" } },
] as any);
const [part] = contentBlocksToParts([block]);
console.log(
JSON.stringify({
in: mimeType,
block: block.type,
format: (block as any).format,
out: (part as any)?.file?.mimeType ?? null,
}),
);
}
{"in":"text/plain","block":"documentBlock","format":"txt","out":"text/plain"}
{"in":"text/plain; charset=utf-8","block":"documentBlock","format":"plain; charset=utf-8","out":null}
{"in":"application/pdf; name=x","block":"documentBlock","format":"pdf; name=x","out":null}
{"in":"audio/mpeg","block":"documentBlock","format":"mpeg","out":"video/mpeg"}
{"in":"audio/wav","block":"documentBlock","format":"wav","out":null}
Possible Solution
I'm not sure which fix you'd prefer, so I'd love your take. One option is to strip parameters (everything after ;, trimmed) before the lookup and add an audio branch that creates an AudioBlock. A narrower option would be to only strip parameters and leave audio for a separate change. Would either of those fit how you see the adapter? And should the Python executor be aligned in the same change, or kept separate? Happy to go with whatever you think is best.
Additional Context
Bedrock and Python notes
Bedrock: bedrock.ts casts the format with as DocumentFormat and passes it straight through (around 1544 to 1549 and 1626). The Converse document formats are limited to pdf, csv, doc, docx, xls, xlsx, html, txt and md, so mpeg, wav or "plain; charset=utf-8" would likely fail validation. I got that from the published API enum, not a live Bedrock call, so please correct me if I'm reading it wrong.
Python: strands-py/src/strands/multiagent/a2a/executor.py (592 to 648) avoids the garbage string, but it can quietly pick the wrong format instead. A PDF with parameters becomes txt, and image/jpeg; ... becomes png.
Related Issues
#1504 (A2A content type request), #3019 and #3066 (similar format bugs in ContextOffloader)
Disclosure: I found this with help from AI tools and confirmed the repro on main.
How it surfaced
Functions Focus: partsToContentBlocks calls _convertFilePart, which calls _getFileType and _getFormat (adapters.ts:139).
Layers: the orchestration to foundation cell (37 calls) with _getFormat calling toMediaFormat highlighted; the same list shows _mediaBlockToFilePart calling toMimeType (mime.ts:100), the return half of the round trip.
Functions Focus: contentBlocksToParts calls _mediaBlockToFilePart, which calls toMimeType on the way back out.
Views from Architect
Hi, I'd like to work on this. I reproduced the behavior on current main (audio FileParts become DocumentBlocks, and MIME parameters leak into the format).
Proposed direction: strip MIME parameters before classifying and resolving the format, and map audio/* to the existing AudioBlock with a small audio MIME lookup so it round-trips back to audio/*. TypeScript only; I'd leave the Python executor for a separate change.
Does that direction work for you, or would you prefer the narrower option (parameters only, audio separately)? I have a local patch with tests ready and will open a PR once you confirm. (Drafted with AI assistance, Claude Code.)
Hey @mccalpink, hope you're doing well! Thank you so much for picking this up and for reproducing it on main, that really helps.
Your direction sounds great to me: strip the MIME parameters before classifying and resolving the format, and map audio/* to the existing AudioBlock with a small audio lookup so it comes back out as audio/*. Keeping it to TypeScript and leaving the Python executor for a separate change makes sense too. Please go ahead and open your PR whenever it's ready.
A few cases that might be worth a test, in case they're not already in your patch:
- A MIME with an empty type after stripping, like
"; charset=utf-8", so it still lands on the default document format instead of an empty string. audio/x-wav(and maybeaudio/wave), which some clients send instead ofaudio/wav.- Mixed case with spaces, like
" Image/PNG ; q=1". - The outbound fallback: an unknown format such as
tiff(fromimage/tiffcoming in) going back out asimage/tiffinstead of nomimeType. audio/mp4, sincemp4is both an audio and a video format, so it shouldn't come back out asvideo/mp4.
I'd be really happy to review once it's up. And if any of these don't fit how you've shaped it, no worries at all, I'd love to hear what you think.
@abhiramshaji-cyber thanks, PR is up: #6164. It also covers the cases you suggested (audio/x-wav and audio/wave, audio/mp4, mixed case, empty type). I see #6163 came in meanwhile for the same issue, so happy to go with whichever the maintainers prefer.
Hey @mccalpink, thank you so much for this, and for working all of those cases into #6164 and laying them out in the table, that made it really easy to follow. Your note on the image/tiff fallback makes total sense too. It's existing behavior across images, video and documents, so keeping it separate sounds right to me.
Thanks as well to @MdIbuA for #6163, it's great to see two takes on this.
I ran the repro from the issue against both branches (#6163 at 7726994, #6164 at 8419a1f) to see how they line up with the cases from earlier:
- #6164:
audio/mpegandaudio/wavround trip as audio, MIME parameters are dropped, the empty type lands ontxt,Image/PNG ; q=1becomespng,audio/x-wavandaudio/wavecome back asaudio/wav, andaudio/mp4comes back asaudio/mp4. Audio subtypes outside the lookup (likeaudio/x-unknown) stay on the document path as before. - #6163: same results for
audio/mpeg,audio/wav, the parameters, the empty type, mixed case andaudio/mp4.audio/x-wav,audio/waveand other subtypes outside the lookup become an AudioBlock with the subtype as the format (x-wav,wave) and go back out with no mimeType. @MdIbuA, would it be worth adding those as aliases, or did you leave them out on purpose? - Neither changes the
image/tifffallback, which matches main.
Both look like good fixes to me, so I'll happily leave the choice to the maintainers. Would love to hear what you all think, and I'm glad to help review whichever one you'd like to move forward with.
@abhiramshaji-cyber Thanks for flagging the WAV aliases. I had left audio/x-wav and audio/wave out of the lookup; that was an omission, not intentional. I have updated #6163 to recognize both as wav and canonicalize them to audio/wav, with MIME conversion and round-trip regression tests. audio/mp4 continues to round-trip as audio/mp4. The focused tests and TypeScript type checks pass.
Hey @MdIbuA, hope you're doing well! Thanks so much for the quick update, and for adding the round trip tests alongside the WAV aliases, that's really nice to see.
I ran the repro from the issue again against #6163 at eb1f010:
audio/x-wav,audio/waveand evenaudio/WAVE; codecs=1now come in as an AudioBlock with formatwavand go back out asaudio/wav.audio/mpeg,audio/wav,audio/mp4, the MIME parameters, the empty type andImage/PNG ; q=1all still land where they should.
One small thing I noticed, just in case it's useful: audio subtypes outside the lookup (like audio/x-unknown or audio/vnd.wave) still become an AudioBlock with the raw subtype as the format, and go back out with no mimeType (_getFormat falls back to the subtype at adapters.ts L162 to L165). On main they stayed on the document path, so it's not a regression in the outbound result. Would it make sense to keep them as documents, or do you think the AudioBlock is the better home? Totally happy either way, and I'd love to hear what the maintainers think too.
_getFormat and its caller _convertFilePart, Functions view in Architect
Thanks again for all the work on this!
Hey everyone, hope you're all doing well! Just a gentle check in on this one.
@MdIbuA, thank you for 4c4070a. Sending unsupported audio types like audio/aiff back to the document path, and adding audio/vnd.wave to the lookup, answers the question I raised earlier. The extra aliases (audio/mp3, audio/x-m4a, audio/x-flac) are a nice touch too. @mccalpink, thanks again for #6164 and for covering all those edge cases so carefully. Both PRs handled the original repro when I ran it earlier in the thread.
I know the maintainers have a lot on their plates, so no rush at all. When someone has a moment, is there a direction you'd prefer between #6163 and #6164? Or is there anything else that would make this easier to review, like more repro detail or a specific case to test? Happy to help however is most useful, and I'd love to hear what everyone thinks.
Hi, I prefer #6163 because it keeps the audio case and conversion function separate from the other media, which is consistent with AudioFormat being outside the MediaFormat union in mime.ts.