@@ -116,11 +116,14 @@ async def on_message_send_stream(
116116 body = await request .body ()
117117 params = a2a_pb2 .SendMessageRequest ()
118118 Parse (body , params )
119- async for event in self .request_handler .on_message_send_stream (
120- params , context
121- ):
122- response = proto_utils .to_stream_response (event )
123- yield MessageToDict (response )
119+ stream = self .request_handler .on_message_send_stream (params , context )
120+
121+ async def _generator () -> AsyncIterator [dict [str , Any ]]:
122+ async for event in stream :
123+ response = proto_utils .to_stream_response (event )
124+ yield MessageToDict (response )
125+
126+ return _generator ()
124127
125128 @validate_version (constants .PROTOCOL_VERSION_1_0 )
126129 async def on_cancel_task (
@@ -167,10 +170,15 @@ async def on_subscribe_to_task(
167170 JSON serialized objects containing streaming events
168171 """
169172 task_id = request .path_params ['id' ]
170- async for event in self .request_handler .on_subscribe_to_task (
173+ stream = self .request_handler .on_subscribe_to_task (
171174 SubscribeToTaskRequest (id = task_id ), context
172- ):
173- yield MessageToDict (proto_utils .to_stream_response (event ))
175+ )
176+
177+ async def _generator () -> AsyncIterator [dict [str , Any ]]:
178+ async for event in stream :
179+ yield MessageToDict (proto_utils .to_stream_response (event ))
180+
181+ return _generator ()
174182
175183 @validate_version (constants .PROTOCOL_VERSION_1_0 )
176184 async def get_push_notification (
0 commit comments