Repository: pydantic/pydantic-ai
File: pydantic_ai_slim/pydantic_ai/ui/ag_ui/_adapter.py (Python)

Code before:
                            content_to_add = (
                                user_prompt_content[0]
                                if len(user_prompt_content) == 1 and isinstance(user_prompt_content[0], str)
                                else user_prompt_content
                            )
                            builder.add(UserPromptPart(content=content_to_add))

                case SystemMessage(content=content) | DeveloperMessage(content=content):
                    builder.add(SystemPromptPart(content=content))

                case AssistantMessage(content=content, tool_calls=tool_calls_list):
                    if content:
                        builder.add(TextPart(content=content))
                    if tool_calls_list:
                        cls.add_assistant_tool_parts(builder, tool_calls_list, tool_calls)

                case ToolMessage() as tool_msg:
                    cls.add_tool_return_part(builder, tool_msg, tool_calls)

                case ActivityMessage():
                    raise ValueError(f'Unsupported message type: {type(msg)}')

        return builder.messages

    @classmethod
    def load_binary_part(cls, part: BinaryInputContent) -> BinaryContent | ImageUrl | VideoUrl | AudioUrl | DocumentUrl:
        """Transforms an AG-UI BinaryInputContent part into a Pydantic AI content part."""
        if part.url:
            try:
                return BinaryContent.from_data_uri(part.url)
            except ValueError:
                media_type_constructors = {
                    'image': ImageUrl,
                    'video': VideoUrl,
                    'audio': AudioUrl,
                }
                media_type_prefix = part.mime_type.split('/', 1)[0]
                constructor = media_type_constructors.get(media_type_prefix, DocumentUrl)
                return constructor(
                    url=part.url,
                    media_type=part.mime_type,
                    identifier=part.id,
                )
        if part.data:
            return BinaryContent(data=b64decode(part.data), kind='binary', media_type=part.mime_type)

        raise ValueError('BinaryInputContent must have either a `url` or `data` field.')

    @classmethod
    def add_assistant_tool_parts(
        cls,

Review comment (suggestion):
These methods really shouldn't be part of the public interface, so please make them private, either has class methods, or if that doesn't work, as  private functions in the module, outside of the class

Code after:
                                                'audio': AudioUrl,
                                            }
                                            media_type_prefix = part.mime_type.split('/', 1)[0]
                                            constructor = media_type_constructors.get(media_type_prefix, DocumentUrl)
                                            binary_part = constructor(url=part.url, media_type=part.mime_type)
                                    elif part.data:
                                        binary_part = BinaryContent(
                                            data=b64decode(part.data), media_type=part.mime_type
                                        )
                                    else:  # pragma: no cover
                                        raise ValueError('BinaryInputContent must have either a `url` or `data` field.')
                                    user_prompt_content.append(binary_part)
                                case _:  # pragma: no cover
                                    raise ValueError(f'Unsupported user message part type: {type(part)}')

                        if user_prompt_content:  # pragma: no branch
                            content_to_add = (
                                user_prompt_content[0]
                                if len(user_prompt_content) == 1 and isinstance(user_prompt_content[0], str)
                                else user_prompt_content
                            )
                            builder.add(UserPromptPart(content=content_to_add))

                case SystemMessage(content=content) | DeveloperMessage(content=content):
                    builder.add(SystemPromptPart(content=content))

                case AssistantMessage(content=content, tool_calls=tool_calls_list):
                    if content:
                        builder.add(TextPart(content=content))
                    if tool_calls_list:
                        for tool_call in tool_calls_list:
                            tool_call_id = tool_call.id
                            tool_name = tool_call.function.name
                            tool_calls[tool_call_id] = tool_name

                            if tool_call_id.startswith(BUILTIN_TOOL_CALL_ID_PREFIX):
                                _, provider_name, original_id = tool_call_id.split('|', 2)
                                builder.add(
                                    BuiltinToolCallPart(
                                        tool_name=tool_name,
                                        args=tool_call.function.arguments,
                                        tool_call_id=original_id,
                                        provider_name=provider_name,
                                    )
                                )
                            else:
                                builder.add(
                                    ToolCallPart(
                                        tool_name=tool_name,
                                        tool_call_id=tool_call_id,
                                        args=tool_call.function.arguments,