-
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
base: main
Are you sure you want to change the base?
Changes from 5 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
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 |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
a2a_request_ta, | ||
a2a_response_ta, | ||
agent_card_ta, | ||
send_message_request_ta, | ||
) | ||
from .storage import Storage | ||
from .task_manager import TaskManager | ||
|
@@ -116,8 +117,17 @@ async def _agent_run_endpoint(self, request: Request) -> Response: | |
data = await request.body() | ||
a2a_request = a2a_request_ta.validate_json(data) | ||
|
||
if a2a_request['method'] == 'tasks/send': | ||
jsonrpc_response = await self.task_manager.send_task(a2a_request) | ||
if a2a_request['method'] == 'message/send': | ||
message_request = send_message_request_ta.validate_json(data) | ||
jsonrpc_response = await self.task_manager.send_message(message_request) | ||
physicsrob marked this conversation as resolved.
Show resolved
Hide resolved
|
||
elif a2a_request['method'] == 'message/stream': | ||
# Streaming support not yet implemented | ||
physicsrob marked this conversation as resolved.
Show resolved
Hide resolved
|
||
raise NotImplementedError( | ||
'message/stream method is not implemented yet. Streaming support will be added in a future update.' | ||
) | ||
elif a2a_request['method'] == 'tasks/send': # type: ignore[comparison-overlap] | ||
# Legacy method - no longer supported | ||
raise NotImplementedError('tasks/send is deprecated. Use message/send instead.') | ||
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. There's no need for this. Just drop it. 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. 👍 |
||
elif a2a_request['method'] == 'tasks/get': | ||
jsonrpc_response = await self.task_manager.get_task(a2a_request) | ||
elif a2a_request['method'] == 'tasks/cancel': | ||
|
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}) | ||
|
Uh oh!
There was an error while loading. Please reload this page.