@@ -453,7 +453,7 @@ async def run_async(
453453 last_non_streaming_event = None
454454
455455 # Track accumulated partial text for cancellation handling
456- temp_text = ""
456+ temp_text_parts : list [ str ] = []
457457
458458 try :
459459 # Support multiple levels of agent transfers
@@ -463,15 +463,15 @@ async def run_async(
463463
464464 transfer_requested = False
465465 async for event in current_agent .run_async (invocation_context ):
466- # Track partial text accumulation
466+ # Track partial text accumulation (store refs; join only on cancel)
467467 if event .partial :
468468 if event .content and event .content .parts :
469469 for part in event .content .parts :
470470 if part .text :
471- temp_text += part .text
471+ temp_text_parts . append ( part .text )
472472 else :
473- # Clear temp_text on full event
474- temp_text = ""
473+ # Clear accumulated parts on full event
474+ temp_text_parts . clear ()
475475
476476 if not event .partial :
477477 await self .session_service .append_event (session = session , event = event )
@@ -583,6 +583,7 @@ async def run_async(
583583
584584 # Capture partial state at cancellation point
585585 state_partial = dict (session .state )
586+ temp_text = "" .join (temp_text_parts )
586587
587588 # Handle session cleanup for cancellation (two scenarios: streaming vs non-streaming)
588589 await cancel .handle_cancellation_session_cleanup (
0 commit comments