Skip to content

fix: support newer ag-ui input content shapes#4985

Open
pandego wants to merge 5 commits intopydantic:mainfrom
pandego:fix/4946-ag-ui-input-content
Open

fix: support newer ag-ui input content shapes#4985
pandego wants to merge 5 commits intopydantic:mainfrom
pandego:fix/4946-ag-ui-input-content

Conversation

@pandego
Copy link
Copy Markdown

@pandego pandego commented Apr 5, 2026

Pre-Review Checklist

  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • No breaking changes in accordance with the version policy.
  • Linting and type checking pass per make format and make typecheck.
  • PR title is fit for the release changelog.

Pre-Merge Checklist

  • New tests for any fix or new behavior, maintaining 100% coverage.
  • Updated documentation for new features and behaviors, including docstrings for API docs.

Summary

Support the newer AG-UI InputContent variants for user messages while keeping compatibility with the deprecated BinaryInputContent path.

Changes

  • keep the existing BinaryInputContent handling intact
  • accept the newer typed AG-UI user input content shapes (image, audio, video, document)
  • map typed URL/data sources into the existing Pydantic AI binary content/url parts
  • add regression coverage for future-shape inputs built through UserMessage

Test 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

@github-actions github-actions bot added size: M Medium PR (101-500 weighted lines) bug Report that something isn't working, or PR implementing a fix labels Apr 5, 2026
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 4 additional findings in Devin Review.

Open in Devin Review

Comment on lines +134 to +137
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)
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot Apr 5, 2026

Choose a reason for hiding this comment

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

🚩 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.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

devin-ai-integration[bot]

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Report that something isn't working, or PR implementing a fix size: M Medium PR (101-500 weighted lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New ag-ui user *InputContent aren't supported

1 participant