fix: Only process the auth responses in the last event with content (if applicable i.e. it's authored by user)

fixes : https://github.com/google/adk-python/issues/1944
PiperOrigin-RevId: 800560805
This commit is contained in:
Xiang (Sean) Zhou
2025-08-28 12:09:21 -07:00
committed by Copybara-Service
parent 7975e8e196
commit 3b922a2f6d
2 changed files with 567 additions and 19 deletions
+17 -10
View File
@@ -51,15 +51,23 @@ class _AuthLlmRequestProcessor(BaseLlmRequestProcessor):
return return
request_euc_function_call_ids = set() request_euc_function_call_ids = set()
for k in range(len(events) - 1, -1, -1): # find the last event with non-None content
event = events[k] last_event_with_content = None
# look for first event authored by user for i in range(len(events) - 1, -1, -1):
if not event.author or event.author != 'user': event = events[i]
continue if event.content is not None:
responses = event.get_function_responses() last_event_with_content = event
break
# check if the last event with content is authored by user
if not last_event_with_content or last_event_with_content.author != 'user':
return
responses = last_event_with_content.get_function_responses()
if not responses: if not responses:
return return
# look for auth response
for function_call_response in responses: for function_call_response in responses:
if function_call_response.name != REQUEST_EUC_FUNCTION_CALL_NAME: if function_call_response.name != REQUEST_EUC_FUNCTION_CALL_NAME:
continue continue
@@ -67,10 +75,9 @@ class _AuthLlmRequestProcessor(BaseLlmRequestProcessor):
# function call # function call
request_euc_function_call_ids.add(function_call_response.id) request_euc_function_call_ids.add(function_call_response.id)
auth_config = AuthConfig.model_validate(function_call_response.response) auth_config = AuthConfig.model_validate(function_call_response.response)
await AuthHandler( await AuthHandler(auth_config=auth_config).parse_and_store_auth_response(
auth_config=auth_config state=invocation_context.session.state
).parse_and_store_auth_response(state=invocation_context.session.state) )
break
if not request_euc_function_call_ids: if not request_euc_function_call_ids:
return return
File diff suppressed because it is too large Load Diff