Skip to content

Commit c7a29a9

Browse files
committed
fix: rely on agent executor implementation for stream termination
1 parent 25e2a7d commit c7a29a9

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/a2a/server/request_handlers/default_request_handler_v2.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,15 @@ async def on_message_send( # noqa: D102
271271
):
272272
self._validate_task_id_match(task_id, event.id)
273273
result = event
274+
# DO break here as it's "return_immediately".
275+
# AgentExecutor will continue to run in the background.
274276
break
275277

276278
if isinstance(event, Message):
277279
result = event
278-
break
280+
# Do NOT break here as Message is supposed to be the only
281+
# event in "Message-only" interaction.
282+
# We rely on AgentExecutor here to simplify wrong implementations detection.
279283

280284
if result is None:
281285
logger.debug('Missing result for task %s', request_context.task_id)
@@ -311,15 +315,14 @@ async def on_message_send_stream( # noqa: D102
311315
request=request_context,
312316
include_initial_task=False,
313317
):
318+
# Do NOT break here as we rely on AgentExecutor to yield control
319+
# to simplify wrong implementations detection.
314320
if isinstance(event, Task):
315321
self._validate_task_id_match(task_id, event.id)
316322
yield apply_history_length(event, params.configuration)
317323
else:
318324
yield event
319325

320-
if isinstance(event, Message):
321-
break
322-
323326
@validate_request_params
324327
@validate(
325328
lambda self: self._agent_card.capabilities.push_notifications,

0 commit comments

Comments
 (0)