-
Notifications
You must be signed in to change notification settings - Fork 311
refactor!: upgrade SDK to A2A 1.0 specs #572
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
Draft
muscariello
wants to merge
9
commits into
a2aproject:1.0-a2a_proto_refactor
Choose a base branch
from
muscariello:a2a_proto_refactor
base: 1.0-a2a_proto_refactor
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b348735
[DRAFT] feat: Upgrade A2A to v1.0
Tehsmash 74c5a19
feat!: migrate from Pydantic types to protobuf-generated types
muscariello 2d698df
fix: update E2E tests and push notification handlers for proto migration
muscariello 424dd7e
fix: resolve all linter errors and add pyright type fixes
muscariello 7405dc7
refactor: Remove redundant JSON-RPC Pydantic types, use jsonrpc libra…
muscariello 6462801
Address PR review feedback: rename methods, update types, clean up al…
muscariello 42c72f2
refactor: remove extras.py and consolidate error types in utils/error…
muscariello ac1050d
chore: remove AIP-discussion-response.md from tracking
muscariello 601ef0b
ci: Update a2a types generation workflow
holtskinner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| # Response to AIP Discussion #1247 | ||
|
|
||
| > Re: [Respecting AIP response payloads in HTTP](https://github.com/a2aproject/A2A/discussions/1247) | ||
|
|
||
| Thanks for this detailed explanation of the AIP conventions, @darrelmiller. I've been working on the a2a-python SDK migration from Pydantic to protobuf types ([PR #572](https://github.com/a2aproject/a2a-python/pull/572)) and wanted to share how we've implemented this. | ||
|
|
||
| ## How we handle `SetTaskPushNotificationConfig` in the SDK | ||
|
|
||
| The key insight is that the request and response types serve different purposes: | ||
|
|
||
| **Request (`SetTaskPushNotificationConfigRequest`):** | ||
| ```protobuf | ||
| message SetTaskPushNotificationConfigRequest { | ||
| string parent = 1; // e.g., "tasks/{task_id}" | ||
| string config_id = 2; // e.g., "my-config-id" | ||
| TaskPushNotificationConfig config = 3; | ||
| } | ||
| ``` | ||
|
|
||
| **Response (`TaskPushNotificationConfig`):** | ||
| ```protobuf | ||
| message TaskPushNotificationConfig { | ||
| string name = 1; // Full resource name: "tasks/{task_id}/pushNotificationConfigs/{config_id}" | ||
| PushNotificationConfig push_notification_config = 2; | ||
| } | ||
| ``` | ||
|
|
||
| ## Implementation in Python | ||
|
|
||
| In our `DefaultRequestHandler`, we construct the proper `name` field from the request's `parent` and `config_id`: | ||
|
|
||
| ```python | ||
| async def on_set_task_push_notification_config( | ||
| self, | ||
| params: SetTaskPushNotificationConfigRequest, | ||
| context: ServerCallContext | None = None, | ||
| ) -> TaskPushNotificationConfig: | ||
| task_id = _extract_task_id(params.parent) # Extract from "tasks/{task_id}" | ||
|
|
||
| # Store the config | ||
| await self._push_config_store.set_info( | ||
| task_id, | ||
| params.config.push_notification_config, | ||
| ) | ||
|
|
||
| # Build response with proper AIP resource name | ||
| return TaskPushNotificationConfig( | ||
| name=f'{params.parent}/pushNotificationConfigs/{params.config_id}', | ||
| push_notification_config=params.config.push_notification_config, | ||
| ) | ||
| ``` | ||
|
|
||
| ## REST Handler Translation | ||
|
|
||
| For the HTTP binding, the REST handler extracts path parameters and constructs the request: | ||
|
|
||
| ```python | ||
| async def set_push_notification(self, request: Request, context: ServerCallContext): | ||
| task_id = request.path_params['id'] | ||
| body = await request.body() | ||
|
|
||
| params = SetTaskPushNotificationConfigRequest() | ||
| Parse(body, params) | ||
| params.parent = f'tasks/{task_id}' # Set from URL path | ||
|
|
||
| config = await self.request_handler.on_set_task_push_notification_config(params, context) | ||
| return MessageToDict(config) # Returns with proper `name` field | ||
| ``` | ||
|
|
||
| ## JSON-RPC Handler | ||
|
|
||
| The JSON-RPC handler passes the full request directly: | ||
|
|
||
| ```python | ||
| async def set_push_notification_config( | ||
| self, | ||
| request: SetTaskPushNotificationConfigRequest, | ||
| context: ServerCallContext | None = None, | ||
| ) -> SetTaskPushNotificationConfigResponse: | ||
| result = await self.request_handler.on_set_task_push_notification_config( | ||
| request, context | ||
| ) | ||
| return prepare_response_object(...) | ||
| ``` | ||
|
|
||
| ## Key Takeaways | ||
|
|
||
| 1. **The `name` field is constructed, not passed in** - The server builds the full resource name from `parent` + `config_id` | ||
|
|
||
| 2. **Consistent across bindings** - Both gRPC and HTTP handlers ultimately call the same `on_set_task_push_notification_config` method | ||
|
|
||
| 3. **AIP compliance** - The response always includes the full `name` field as required by [AIP-122](https://google.aip.dev/122) | ||
|
|
||
| 4. **Helper functions for resource name parsing**: | ||
| ```python | ||
| def _extract_task_id(resource_name: str) -> str: | ||
| """Extract task ID from a resource name like 'tasks/{task_id}' or 'tasks/{task_id}/...'.""" | ||
| match = re.match(r'^tasks/([^/]+)', resource_name) | ||
| if match: | ||
| return match.group(1) | ||
| return resource_name # Fall back for backwards compatibility | ||
|
|
||
| def _extract_config_id(resource_name: str) -> str | None: | ||
| """Extract config ID from 'tasks/{task_id}/pushNotificationConfigs/{config_id}'.""" | ||
| match = re.match(r'^tasks/[^/]+/pushNotificationConfigs/([^/]+)$', resource_name) | ||
| if match: | ||
| return match.group(1) | ||
| return None | ||
| ``` | ||
|
|
||
| ## E2E Test Example | ||
|
|
||
| Here's how a client uses this in practice: | ||
|
|
||
| ```python | ||
| # Client sets the push notification config | ||
| await a2a_client.set_task_callback( | ||
| SetTaskPushNotificationConfigRequest( | ||
| parent=f'tasks/{task.id}', | ||
| config_id='my-notification-config', | ||
| config=TaskPushNotificationConfig( | ||
| push_notification_config=PushNotificationConfig( | ||
| id='my-notification-config', | ||
| url=f'{notifications_server}/notifications', | ||
| token=token, | ||
| ), | ||
| ), | ||
| ) | ||
| ) | ||
| ``` | ||
|
|
||
| This approach keeps the abstract handler logic clean while ensuring AIP compliance at the protocol binding level. | ||
|
|
||
| --- | ||
|
|
||
| **Related PRs:** | ||
| - [a2a-python PR #572](https://github.com/a2aproject/a2a-python/pull/572) - Proto migration with these changes |
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
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
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
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
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
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
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
Oops, something went wrong.
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.
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.
I think this change has just proven my point about moving this inline in the function below and changing how the "match" is done.