feat(py): drop Part(root=); one Part through generate - #6309
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the Part data model across the Genkit Python SDK and its provider plugins (including Bedrock, Anthropic, Google GenAI, Ollama, and OpenAI). It flattens the Part structure, replacing the nested root attribute with direct properties (such as text, media, and tool_request) and introducing helper factory methods like Part.from_text and Part.from_media. The review feedback identifies a critical runtime error where model_dump is called with an unsupported fallback argument on a Pydantic BaseModel. Additionally, several unidiomatic expressions (such as not part.media is not None) and redundant checks can be simplified to improve code readability and maintainability.
huangjeff5
force-pushed
the
feat/py-part-flatten
branch
from
September 10, 2026 12:37
dc8c6dd to
7568483
Compare
huangjeff5
force-pushed
the
feat/py-part-ergonomics
branch
from
September 10, 2026 14:37
6300ab8 to
a091574
Compare
huangjeff5
force-pushed
the
feat/py-part-flatten
branch
2 times, most recently
from
September 10, 2026 14:37
3c9746c to
5b268fa
Compare
apascal07
reviewed
Sep 10, 2026
apascal07
reviewed
Sep 10, 2026
apascal07
reviewed
Sep 10, 2026
apascal07
reviewed
Sep 10, 2026
apascal07
reviewed
Sep 10, 2026
apascal07
approved these changes
Sep 10, 2026
Part.from_data(None) is a data part. Empty {} and metadata-only inbound
parts are dropped when a message is read. A thought with an image
summary replays as that same step, and a typed ModelRequest config stays.
huangjeff5
force-pushed
the
feat/py-part-flatten
branch
from
September 17, 2026 09:25
92d0949 to
c918342
Compare
huangjeff5
removed this pull request from stack #6310
September 18, 2026 15:14
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.
Callers already build with
Part.from_text/Part(text=...). This change deletes.root.Part(root=...)raises. The part they put onMessage/Document/ai.generateis the samePartthey read.textfrom.Part.from_data(None)is a data part. Empty{}or metadata-only parts in inbound message content are dropped when the message is read;Part()with no kind still raises.Decisions
Part.from_*orPart(text=...).Part(root=...)raises.from genkit import. Inner objects (ToolRequest,ToolResponse,Media) stay public.custommay ride on another kind, or be the kind when it is the only payload.Part.from_data(None)dumps and reloads as a data part.{}or metadata-only part is dropped when reading a message so a junk empty part does not fail generate. BuildingPart()with no kind still raises.ModelRequeststays that class on the response./generatestill requiresmessages.pendingContentpart reports the kind rule (exactly one of text, media, ...) instead of a generic "must be a part".