mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
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:
committed by
Copybara-Service
parent
7975e8e196
commit
3b922a2f6d
@@ -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
Reference in New Issue
Block a user