diff --git a/src/google/adk/flows/llm_flows/functions.py b/src/google/adk/flows/llm_flows/functions.py index 1f85bee3a8..10eb2796f7 100644 --- a/src/google/adk/flows/llm_flows/functions.py +++ b/src/google/adk/flows/llm_flows/functions.py @@ -1151,12 +1151,10 @@ def __build_response_event( def deep_merge_dicts(d1: dict, d2: dict) -> dict: - """Recursively merges d2 into d1, extending lists where keys collide.""" + """Recursively merges d2 into d1.""" for key, value in d2.items(): if key in d1 and isinstance(d1[key], dict) and isinstance(value, dict): d1[key] = deep_merge_dicts(d1[key], value) - elif key in d1 and isinstance(d1[key], list) and isinstance(value, list): - d1[key].extend(value) else: d1[key] = value return d1 @@ -1181,14 +1179,23 @@ def merge_parallel_function_response_events( # Merge actions from all events merged_actions_data: dict[str, Any] = {} + aggregated_ui_widgets = [] for event in function_response_events: if event.actions: + actions_dict = event.actions.model_dump(exclude_none=True, by_alias=True) + ui_widgets = actions_dict.pop('render_ui_widgets', None) + if ui_widgets: + aggregated_ui_widgets.extend(ui_widgets) + # Use `by_alias=True` because it converts the model to a dictionary while respecting field aliases, ensuring that the enum fields are correctly handled without creating a duplicate. merged_actions_data = deep_merge_dicts( merged_actions_data, - event.actions.model_dump(exclude_none=True, by_alias=True), + actions_dict, ) + if aggregated_ui_widgets: + merged_actions_data['render_ui_widgets'] = aggregated_ui_widgets + merged_actions = EventActions.model_validate(merged_actions_data) # Create the new merged event