fix: support newer ag-ui input content shapes#4985
fix: support newer ag-ui input content shapes#4985pandego wants to merge 5 commits intopydantic:mainfrom
Conversation
| if source_type == 'url' and isinstance(source_value, str): | ||
| if mime_type is None: | ||
| raise ValueError(f'{type(part).__name__} with URL source must include a MIME type.') | ||
| return AGUIAdapter._binary_url_part(url=source_value, mime_type=mime_type) |
There was a problem hiding this comment.
🚩 Typed content with URL source but no mime_type raises ValueError even though ImageUrl accepts None
For an ImageInputContent with InputContentUrlSource(value='http://...', mime_type=None) (which is valid per ag_ui's schema where InputContentUrlSource.mime_type is Optional[str]), the code raises ValueError('ImageInputContent with URL source must include a MIME type.') at line 136. However, ImageUrl(url=...) actually accepts media_type=None since FileUrl._media_type defaults to None (messages.py:203). The code could instead use part.type ('image', 'audio', etc.) to select the URL constructor and allow media_type=None. This is a strictness design choice rather than a bug — the error is explicit and descriptive — but it could cause failures for valid ag_ui messages where the client omits the optional mime_type.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
I looked at this one and I'm keeping the explicit MIME requirement for now.
Even though ImageUrl can infer or tolerate missing media type later, this adapter branch currently treats typed AG-UI URL content as requiring enough information to map deterministically to the right Pydantic AI file/url part up front. That keeps failures explicit instead of silently accepting underspecified input in one path but not the others.
So I treated this as a design choice rather than a follow-up bug in this PR.
Pre-Review Checklist
make formatandmake typecheck.Pre-Merge Checklist
Summary
Support the newer AG-UI
InputContentvariants for user messages while keeping compatibility with the deprecatedBinaryInputContentpath.Changes
BinaryInputContenthandling intactimage,audio,video,document)UserMessageTest plan
uv run pytest tests/test_ag_ui.py -k 'test_messages or future_input_content_shapes'uv run ruff check pydantic_ai_slim/pydantic_ai/ui/ag_ui/_adapter.py tests/test_ag_ui.py