@@ -169,7 +169,9 @@ async def _handle_messages(
169169 """Initialize orchestrator state and start the conversation loop."""
170170 self ._append_messages (messages )
171171 # Termination condition will also be applied to the input messages
172- if await self ._check_terminate_and_yield (cast (WorkflowContext [Never , AgentResponse ], ctx )):
172+ if await self ._check_terminate_and_yield (
173+ cast (WorkflowContext [Never , AgentResponse | AgentResponseUpdate ], ctx )
174+ ):
173175 return
174176
175177 next_speaker = await self ._get_next_speaker ()
@@ -198,9 +200,13 @@ async def _handle_response(
198200 messages = clean_conversation_for_handoff (messages )
199201 self ._append_messages (messages )
200202
201- if await self ._check_terminate_and_yield (cast (WorkflowContext [Never , AgentResponse ], ctx )):
203+ if await self ._check_terminate_and_yield (
204+ cast (WorkflowContext [Never , AgentResponse | AgentResponseUpdate ], ctx )
205+ ):
202206 return
203- if await self ._check_round_limit_and_yield (cast (WorkflowContext [Never , AgentResponse ], ctx )):
207+ if await self ._check_round_limit_and_yield (
208+ cast (WorkflowContext [Never , AgentResponse | AgentResponseUpdate ], ctx )
209+ ):
204210 return
205211
206212 next_speaker = await self ._get_next_speaker ()
@@ -332,13 +338,15 @@ async def _handle_messages(
332338 """Initialize orchestrator state and start the conversation loop."""
333339 self ._append_messages (messages )
334340 # Termination condition will also be applied to the input messages
335- if await self ._check_terminate_and_yield (cast (WorkflowContext [Never , AgentResponse ], ctx )):
341+ if await self ._check_terminate_and_yield (
342+ cast (WorkflowContext [Never , AgentResponse | AgentResponseUpdate ], ctx )
343+ ):
336344 return
337345
338346 agent_orchestration_output = await self ._invoke_agent ()
339347 if await self ._check_agent_terminate_and_yield (
340348 agent_orchestration_output ,
341- cast (WorkflowContext [Never , AgentResponse ], ctx ),
349+ cast (WorkflowContext [Never , AgentResponse | AgentResponseUpdate ], ctx ),
342350 ):
343351 return
344352
@@ -366,15 +374,19 @@ async def _handle_response(
366374 # Remove tool-related content to prevent API errors from empty messages
367375 messages = clean_conversation_for_handoff (messages )
368376 self ._append_messages (messages )
369- if await self ._check_terminate_and_yield (cast (WorkflowContext [Never , AgentResponse ], ctx )):
377+ if await self ._check_terminate_and_yield (
378+ cast (WorkflowContext [Never , AgentResponse | AgentResponseUpdate ], ctx )
379+ ):
370380 return
371- if await self ._check_round_limit_and_yield (cast (WorkflowContext [Never , AgentResponse ], ctx )):
381+ if await self ._check_round_limit_and_yield (
382+ cast (WorkflowContext [Never , AgentResponse | AgentResponseUpdate ], ctx )
383+ ):
372384 return
373385
374386 agent_orchestration_output = await self ._invoke_agent ()
375387 if await self ._check_agent_terminate_and_yield (
376388 agent_orchestration_output ,
377- cast (WorkflowContext [Never , AgentResponse ], ctx ),
389+ cast (WorkflowContext [Never , AgentResponse | AgentResponseUpdate ], ctx ),
378390 ):
379391 return
380392
0 commit comments