feat: Add support for more Task Message and Artifact fields in the Vertex Task Store#908
feat: Add support for more Task Message and Artifact fields in the Vertex Task Store#908gaborfeher wants to merge 2 commits intoa2aproject:mainfrom
Conversation
🧪 Code Coverage (vs
|
| Base | PR | Delta | |
|---|---|---|---|
| src/a2a/contrib/tasks/vertex_task_converter.py | 96.36% | 90.91% | 🔴 -5.45% |
| Total | 91.73% | 91.65% | 🔴 -0.08% |
Generated by coverage-comment.yml
There was a problem hiding this comment.
Code Review
This pull request enhances the Vertex AI task converter by implementing comprehensive metadata handling and message conversion logic. It introduces versioned metadata packing/unpacking and updates artifact and task conversion to include fields such as name, description, and status details. Review feedback highlights a potential Pydantic validation error when handling invalid roles in to_sdk_message and suggests improving naming consistency for reference task IDs within the metadata dictionary.
| role = None | ||
| if stored_msg.role: | ||
| try: | ||
| role = Role(stored_msg.role) | ||
| except ValueError: | ||
| role = None | ||
|
|
There was a problem hiding this comment.
The role field in the Message model is required, but this logic allows role to be None if stored_msg.role is invalid, not present, or an empty string. This will cause a pydantic.ValidationError at runtime when Message is instantiated. The # type: ignore on line 276 suppresses the static type error, but hides this potential runtime crash.
To ensure type safety and prevent runtime errors, you should handle the case where a valid Role cannot be determined more explicitly by raising a ValueError.
try:
role = Role(stored_msg.role)
except (ValueError, TypeError) as e:
raise ValueError(f"Invalid or missing role in stored message: {stored_msg.role!r}") from eReferences
- For unsupported input values, fail explicitly by raising an error instead of silently falling back to a default value.
| return { | ||
| 'original_metadata': stored_metadata.get(_ORIGINAL_METADATA_KEY), | ||
| 'extensions': stored_metadata.get(_EXTENSIONS_KEY), | ||
| 'reference_tasks': stored_metadata.get(_REFERENCE_TASK_IDS_KEY), |
There was a problem hiding this comment.
For consistency with the Message model's field name (reference_task_ids), it would be clearer to use 'reference_task_ids' as the key here. This would improve readability and reduce potential confusion.
This change would also require updating the key used in to_sdk_message on line 278 from 'reference_tasks' to 'reference_task_ids'.
| 'reference_tasks': stored_metadata.get(_REFERENCE_TASK_IDS_KEY), | |
| 'reference_task_ids': stored_metadata.get(_REFERENCE_TASK_IDS_KEY), |
WIP
For #751