-
Notifications
You must be signed in to change notification settings - Fork 274
fix(proto): Adds metadata field to A2A DataPart proto #455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(proto): Adds metadata field to A2A DataPart proto #455
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @a2a-bot, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request updates the A2A specification by introducing a new metadata field to the Part message within the protobuf definition. This enhancement provides a flexible mechanism to embed arbitrary structured data directly into message parts, significantly improving the extensibility and information richness of A2A messages. The corresponding Python generated files have been updated to incorporate these changes.
Highlights
- Protobuf
Partmessage enhancement: Added ametadatafield of typegoogle.protobuf.Structto thePartmessage in the A2A protobuf definition. This allows for associating arbitrary structured data with individual message parts. - Generated files update: Regenerated the Python protobuf files (
a2a_pb2.pyanda2a_pb2.pyi) to reflect the updated specification, ensuring type safety and correct serialization.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request updates the protobuf specification to add a metadata field to the Part message. While the generated Python files (a2a_pb2.py and a2a_pb2.pyi) correctly reflect this change, a critical piece of logic is missing. The conversion utility in src/a2a/utils/proto_utils.py has not been updated to handle this new field, which will cause the metadata to be lost during serialization and deserialization. This must be addressed before merging.
|
@gemini-code-assist review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds a metadata field to the Part protobuf message, allowing for metadata to be associated with any type of message part. The changes are correctly reflected in the generated protobuf files. The proto_utils.py file has been updated to handle the new field during type conversions.
My review focuses on improving the maintainability and correctness of the conversion logic in proto_utils.py. I've suggested refactoring the ToProto.part and FromProto.part methods to reduce code duplication. More importantly, I've identified a potential bug in FromProto.part where the check for metadata presence is incorrect, and I've provided a suggestion to fix it while also making the code cleaner.
| def part(cls, part: a2a_pb2.Part) -> types.Part: | ||
| if part.HasField('text'): | ||
| return types.Part(root=types.TextPart(text=part.text)) | ||
| return types.Part( | ||
| root=types.TextPart( | ||
| text=part.text, | ||
| metadata=cls.metadata(part.metadata) | ||
| if part.metadata | ||
| else None, | ||
| ), | ||
| ) | ||
| if part.HasField('file'): | ||
| return types.Part(root=types.FilePart(file=cls.file(part.file))) | ||
| return types.Part( | ||
| root=types.FilePart( | ||
| file=cls.file(part.file), | ||
| metadata=cls.metadata(part.metadata) | ||
| if part.metadata | ||
| else None, | ||
| ), | ||
| ) | ||
| if part.HasField('data'): | ||
| return types.Part(root=types.DataPart(data=cls.data(part.data))) | ||
| return types.Part( | ||
| root=types.DataPart( | ||
| data=cls.data(part.data), | ||
| metadata=cls.metadata(part.metadata) | ||
| if part.metadata | ||
| else None, | ||
| ), | ||
| ) | ||
| raise ValueError(f'Unsupported part type: {part}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for handling metadata is repeated in each branch, and the condition if part.metadata is incorrect because a protobuf message object is always truthy. This means the else None branch is unreachable, and empty metadata will be converted to an empty dictionary {} instead of None. This can be a subtle bug if downstream code expects None.
I suggest refactoring to extract the common metadata handling logic, which also fixes the bug and makes the code more readable and maintainable.
def part(cls, part: a2a_pb2.Part) -> types.Part:
metadata = cls.metadata(part.metadata) if part.metadata.fields else None
if part.HasField('text'):
return types.Part(
root=types.TextPart(
text=part.text,
metadata=metadata,
),
)
if part.HasField('file'):
return types.Part(
root=types.FilePart(
file=cls.file(part.file),
metadata=metadata,
),
)
if part.HasField('data'):
return types.Part(
root=types.DataPart(
data=cls.data(part.data),
metadata=metadata,
),
)
raise ValueError(f'Unsupported part type: {part}')| def part(cls, part: types.Part) -> a2a_pb2.Part: | ||
| if isinstance(part.root, types.TextPart): | ||
| return a2a_pb2.Part(text=part.root.text) | ||
| return a2a_pb2.Part( | ||
| text=part.root.text, metadata=cls.metadata(part.root.metadata) | ||
| ) | ||
| if isinstance(part.root, types.FilePart): | ||
| return a2a_pb2.Part(file=cls.file(part.root.file)) | ||
| return a2a_pb2.Part( | ||
| file=cls.file(part.root.file), | ||
| metadata=cls.metadata(part.root.metadata), | ||
| ) | ||
| if isinstance(part.root, types.DataPart): | ||
| return a2a_pb2.Part(data=cls.data(part.root.data)) | ||
| return a2a_pb2.Part( | ||
| data=cls.data(part.root.data), | ||
| metadata=cls.metadata(part.root.metadata), | ||
| ) | ||
| raise ValueError(f'Unsupported part type: {part.root}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for creating the a2a_pb2.Part is repeated across the different if statements. You can refactor this to be more DRY (Don't Repeat Yourself) by preparing the arguments for a2a_pb2.Part and calling it only once at the end. This improves maintainability.
def part(cls, part: types.Part) -> a2a_pb2.Part:
kwargs = {"metadata": cls.metadata(part.root.metadata)}
if isinstance(part.root, types.TextPart):
kwargs["text"] = part.root.text
elif isinstance(part.root, types.FilePart):
kwargs["file"] = cls.file(part.root.file)
elif isinstance(part.root, types.DataPart):
kwargs["data"] = cls.data(part.root.data)
else:
raise ValueError(f'Unsupported part type: {part.root}')
return a2a_pb2.Part(**kwargs)🤖 I have created a release *beep* *boop* --- ## [0.3.5](v0.3.4...v0.3.5) (2025-09-08) ### Bug Fixes * Prevent client disconnect from stopping task execution ([#440](#440)) ([58b4c81](58b4c81)), closes [#296](#296) * **proto:** Adds metadata field to A2A DataPart proto ([#455](#455)) ([6d0ef59](6d0ef59)) ### Documentation * add example docs for `[@Validate](https://github.com/validate)` and `[@Validate](https://github.com/validate)_async_generator` ([#422](#422)) ([18289eb](18289eb)) * Restructure README ([9758f78](9758f78)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Uh oh!
There was an error while loading. Please reload this page.