@@ -51,26 +51,33 @@ async def run_async(
51
51
return
52
52
53
53
request_euc_function_call_ids = set ()
54
- for k in range (len (events ) - 1 , - 1 , - 1 ):
55
- event = events [k ]
56
- # look for first event authored by user
57
- if not event .author or event .author != 'user' :
58
- continue
59
- responses = event .get_function_responses ()
60
- if not responses :
61
- return
54
+ # find the last event with non-None content
55
+ last_event_with_content = None
56
+ for i in range (len (events ) - 1 , - 1 , - 1 ):
57
+ event = events [i ]
58
+ if event .content is not None :
59
+ last_event_with_content = event
60
+ break
62
61
63
- for function_call_response in responses :
64
- if function_call_response .name != REQUEST_EUC_FUNCTION_CALL_NAME :
65
- continue
66
- # found the function call response for the system long running request euc
67
- # function call
68
- request_euc_function_call_ids .add (function_call_response .id )
69
- auth_config = AuthConfig .model_validate (function_call_response .response )
70
- await AuthHandler (
71
- auth_config = auth_config
72
- ).parse_and_store_auth_response (state = invocation_context .session .state )
73
- break
62
+ # check if the last event with content is authored by user
63
+ if not last_event_with_content or last_event_with_content .author != 'user' :
64
+ return
65
+
66
+ responses = last_event_with_content .get_function_responses ()
67
+ if not responses :
68
+ return
69
+
70
+ # look for auth response
71
+ for function_call_response in responses :
72
+ if function_call_response .name != REQUEST_EUC_FUNCTION_CALL_NAME :
73
+ continue
74
+ # found the function call response for the system long running request euc
75
+ # function call
76
+ request_euc_function_call_ids .add (function_call_response .id )
77
+ auth_config = AuthConfig .model_validate (function_call_response .response )
78
+ await AuthHandler (auth_config = auth_config ).parse_and_store_auth_response (
79
+ state = invocation_context .session .state
80
+ )
74
81
75
82
if not request_euc_function_call_ids :
76
83
return
0 commit comments