-
Notifications
You must be signed in to change notification settings - Fork 1k
Upgrade a2a to spec v0.2.3 #2144
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
Changes from 20 commits
be6e37f
22e825f
a6d958b
3901954
55f3ced
0a95bf9
5785901
d1ff90a
15df524
1a245a7
ffe8a6e
5fd0dde
872714e
9372d3c
c5dd525
a131482
bfd305f
2f05b6c
a23582a
06b2d88
36fc9e8
a984a68
d50cd8e
d24fcca
270872c
7971e34
3a4c4c6
184cf58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,15 @@ | |
GetTaskRequest, | ||
GetTaskResponse, | ||
Message, | ||
PushNotificationConfig, | ||
SendTaskRequest, | ||
SendTaskResponse, | ||
TaskSendParams, | ||
MessageSendConfiguration, | ||
MessageSendParams, | ||
SendMessageRequest, | ||
SendMessageResponse, | ||
a2a_request_ta, | ||
send_message_request_ta, | ||
send_message_response_ta, | ||
) | ||
|
||
send_task_response_ta = pydantic.TypeAdapter(SendTaskResponse) | ||
get_task_response_ta = pydantic.TypeAdapter(GetTaskResponse) | ||
|
||
try: | ||
|
@@ -37,26 +38,30 @@ def __init__(self, base_url: str = 'http://localhost:8000', http_client: httpx.A | |
self.http_client = http_client | ||
self.http_client.base_url = base_url | ||
|
||
async def send_task( | ||
async def send_message( | ||
self, | ||
message: Message, | ||
history_length: int | None = None, | ||
push_notification: PushNotificationConfig | None = None, | ||
*, | ||
metadata: dict[str, Any] | None = None, | ||
) -> SendTaskResponse: | ||
task = TaskSendParams(message=message, id=str(uuid.uuid4())) | ||
if history_length is not None: | ||
task['history_length'] = history_length | ||
if push_notification is not None: | ||
task['push_notification'] = push_notification | ||
configuration: MessageSendConfiguration | None = None, | ||
) -> SendMessageResponse: | ||
"""Send a message using the A2A protocol. | ||
|
||
Returns a JSON-RPC response containing either a result (Task | Message) or an error. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand by the spec is possible to return both, but we always return Task. |
||
""" | ||
params = MessageSendParams(message=message) | ||
if metadata is not None: | ||
task['metadata'] = metadata | ||
params['metadata'] = metadata | ||
if configuration is not None: | ||
params['configuration'] = configuration | ||
|
||
payload = SendTaskRequest(jsonrpc='2.0', id=None, method='tasks/send', params=task) | ||
content = a2a_request_ta.dump_json(payload, by_alias=True) | ||
request_id = str(uuid.uuid4()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this ID? Is it the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is the request_id for JSON-RPC. Let me know if you think a clarifying comment would be helpful, or if there's something off about the variable names |
||
payload = SendMessageRequest(jsonrpc='2.0', id=request_id, method='message/send', params=params) | ||
content = send_message_request_ta.dump_json(payload, by_alias=True) | ||
response = await self.http_client.post('/', content=content, headers={'Content-Type': 'application/json'}) | ||
self._raise_for_status(response) | ||
return send_task_response_ta.validate_json(response.content) | ||
|
||
return send_message_response_ta.validate_json(response.content) | ||
|
||
async def get_task(self, task_id: str) -> GetTaskResponse: | ||
payload = GetTaskRequest(jsonrpc='2.0', id=None, method='tasks/get', params={'id': task_id}) | ||
|
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.
We already handle all the non supported methods a bit down here, so I'll drop this for now.