5757# Prefix used by toolset auth credential IDs
5858TOOLSET_AUTH_CREDENTIAL_ID_PREFIX = '_adk_toolset_auth_'
5959
60+
61+ class _ReconnectSentinel (Event ):
62+ """Internal sentinel event to signal a silent reconnection request."""
63+
64+
6065if TYPE_CHECKING :
6166 from ...agents .llm_agent import LlmAgent
6267 from ...models .base_llm import BaseLlm
@@ -577,6 +582,7 @@ async def run_live(
577582 self ._send_to_model (llm_connection , invocation_context )
578583 )
579584
585+ should_reconnect = False
580586 try :
581587 async with Aclosing (
582588 self ._receive_from_model (
@@ -587,6 +593,9 @@ async def run_live(
587593 )
588594 ) as agen :
589595 async for event in agen :
596+ if isinstance (event , _ReconnectSentinel ):
597+ should_reconnect = True
598+ break
590599 # Empty event means the queue is closed.
591600 if not event :
592601 break
@@ -667,6 +676,9 @@ async def run_live(
667676 await send_task
668677 except asyncio .CancelledError :
669678 pass
679+ if should_reconnect :
680+ continue
681+ break
670682 except (ConnectionClosed , ConnectionClosedOK ) as e :
671683 # If we have a session resumption handle, we attempt to reconnect.
672684 # This handle is updated dynamically during the session.
@@ -805,9 +817,9 @@ def get_author_for_event(llm_response: LlmResponse) -> str:
805817 if llm_response .go_away :
806818 logger .info (f'Received go away signal: { llm_response .go_away } ' )
807819 # The server signals that it will close the connection soon.
808- # We proactively raise ConnectionClosed to trigger the reconnection
809- # logic in run_live, which will use the latest session handle.
810- raise ConnectionClosed ( None , None )
820+ # We yield a sentinel event to request reconnection internally.
821+ yield _ReconnectSentinel ( author = 'system' )
822+ return
811823
812824 model_response_event = Event (
813825 id = Event .new_id (),
0 commit comments