Skip to content

Commit 34b9395

Browse files
committed
feat: send task as a first subscribe event
Following > The operation MUST return a Task object as the first event in the stream introduced in 1.0: https://a2a-protocol.org/latest/specification/#316-subscribe-to-task
1 parent 427a75b commit 34b9395

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/a2a/server/request_handlers/default_request_handler.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,15 @@ async def on_subscribe_to_task(
555555

556556
if task.status.state in TERMINAL_TASK_STATES:
557557
raise ServerError(
558-
error=InvalidParamsError(
558+
error=UnsupportedOperationError(
559559
message=f'Task {task.id} is in terminal state: {task.status.state}'
560560
)
561561
)
562562

563+
# The operation MUST return a Task object as the first event in the stream
564+
# https://a2a-protocol.org/latest/specification/#316-subscribe-to-task
565+
yield task
566+
563567
task_manager = TaskManager(
564568
task_id=task.id,
565569
context_id=task.context_id,

tests/server/request_handlers/test_default_request_handler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,9 @@ async def exec_side_effect(_request, queue: EventQueue):
14991499
# Allow producer to emit the next event
15001500
allow_second_event.set()
15011501

1502+
first_subscribe_event = await anext(resub_gen)
1503+
assert first_subscribe_event == task_for_resub
1504+
15021505
received = await resub_gen.__anext__()
15031506
assert received == second_event
15041507

@@ -2706,7 +2709,7 @@ async def test_on_subscribe_to_task_in_terminal_state(terminal_state):
27062709
async for _ in request_handler.on_subscribe_to_task(params, context):
27072710
pass # pragma: no cover
27082711

2709-
assert isinstance(exc_info.value.error, InvalidParamsError)
2712+
assert isinstance(exc_info.value.error, UnsupportedOperationError)
27102713
assert exc_info.value.error.message
27112714
assert (
27122715
f'Task {task_id} is in terminal state: {terminal_state}'

0 commit comments

Comments
 (0)