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
request_euc_function_call_ids = set()
for k in range(len(events) - 1, -1, -1):
event = events[k]
# look for first event authored by user
if not event.author or event.author != 'user':
continue
responses = event.get_function_responses()
# find the last event with non-None content
last_event_with_content = None
for i in range(len(events) - 1, -1, -1):
event = events[i]
if event.content is not None:
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:
return
# look for auth response
for function_call_response in responses:
if function_call_response.name != REQUEST_EUC_FUNCTION_CALL_NAME:
continue
@@ -67,10 +75,9 @@ class _AuthLlmRequestProcessor(BaseLlmRequestProcessor):
# function call
request_euc_function_call_ids.add(function_call_response.id)
auth_config = AuthConfig.model_validate(function_call_response.response)
await AuthHandler(
auth_config=auth_config
).parse_and_store_auth_response(state=invocation_context.session.state)
break
await AuthHandler(auth_config=auth_config).parse_and_store_auth_response(
state=invocation_context.session.state
)
if not request_euc_function_call_ids:
return
File diff suppressed because it is too large Load Diff