Multimodal content blocks - #1060
Open
Zhuoxi2000 wants to merge 6 commits into
Open
Conversation
…nditions, providers
Zhuoxi2000
marked this pull request as ready for review
August 29, 2026 03:56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue: #1059 (Phase 1 — the tracking issue stays open for the provider phase)
Purpose of change
Implements the framework part of the multimodal design agreed in #1031.
ChatMessage.content: Stringis replaced byblocks: List<ContentBlock>in both Java and Python. The initial block types areTextBlock,ImageBlock,AudioBlock,VideoBlock, andDocumentBlock. Media blocks share a MIME-typed shape withmime_type, exactly one of base64dataor externalurl, and optional metadata such asname,size_bytes, andsha256.Existing text constructors/factories keep their signatures and create a single
TextBlock.getText()/.textreturns the ordered text projection.Java and Python use the same
type-discriminated JSON format, covered by the regenerated cross-language snapshots. The pemja bridge is updated to carry blocks across runtimes as well.This PR also updates prompt handling so image-only messages are preserved, and
Prompt.formatMessagesapplies substitutions only to text blocks while passing media blocks through unchanged.Provider-specific multimodal conversion is intentionally left to the next #1059 phase. Existing providers continue using the text projection in this PR.
Behavior changes:
response.contentneed to migrate toresponse.blocks.ChatMessagenow rejects unknown fields, so the removedcontent=argument fails explicitly instead of silently creating an empty message.toString()/__str__, equality, and hashing now use the block representation.dataandurlare mutually exclusive for media blocks.Tests
ChatMessageserialization tests covering the wire format, mixed block ordering, media fields, round trips, source validation, and rejection of the removedcontentargument.ChatMessage.API
Yes. This is a Beta breaking change discussed in #1031.
ChatMessage.contentis replaced byblocksin both Java and Python. Java removesgetContent()/setContent; Python removes.content. Text-only access remains available throughgetText()/.textandsetText()/set_text().New public types in both languages are
ContentBlock,TextBlock,MediaBlock,ImageBlock,AudioBlock,VideoBlock, andDocumentBlock.ChatMessagealso addsgetBlocksAsMaps()/setBlocksFromMaps()for the pemja bridge, where blocks cross as plain maps.CEL expressions referencing
response.contentmust migrate toresponse.blocks.Documentation
doc-neededdoc-not-neededdoc-includedWas this patch authored or co-authored using generative AI tooling?
Generated by: Claude Code Fable 5