Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions src/google/adk/flows/llm_flows/base_llm_flow.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -534,8 +534,32 @@ async def run_live(
llm_request,
)

attempt = 1
try:
# A caller can resume an earlier live session by handing the flow a
# handle it obtained from a previous run, which request assembly has by
# now put on the connect config (from `RunConfig.session_resumption`).
# Seed the invocation with it so the very first connection is treated as
# a resumption like any mid-session reconnect: the history the server
# already holds is not replayed, and if this connection drops before the
# server has pushed its first `session_resumption_update`, the reconnect
# path still has the caller's handle to retry with instead of failing the
# run. Without this the handle only reached the connect config while the
# rest of the run still behaved as if the session were new.
session_resumption = (
llm_request.live_connect_config.session_resumption
if llm_request.live_connect_config
else None
)
if (
not invocation_context.live_session_resumption_handle
and session_resumption is not None
and session_resumption.handle
):
invocation_context.live_session_resumption_handle = (
session_resumption.handle
)

attempt = 1
while True:
try:
# On subsequent attempts, use the saved token to reconnect
Expand DownExpand Up@@ -730,9 +754,9 @@ async def run_live(
logger.error('Connection closed: %s.', e)
raise
except errors.APIError as e:
# Error code 1000and 1006 indicates a recoverable connection drop.
# Error code 1000, 1006 and 1011 indicates a recoverable connection drop.
# In that case, we attempt to reconnect with session handle if available.
if e.code in [1000, 1006]:
if e.code in [1000, 1006, 1011]:
if invocation_context.live_session_resumption_handle:
if attempt > DEFAULT_MAX_RECONNECT_ATTEMPTS:
logger.error('Max reconnection attempts reached (%s).', e)
Expand Down
Loading
Loading