From 143b656949d61363d135e0b74ef5696e78eb270a Mon Sep 17 00:00:00 2001 From: Google Team Member Date: Mon, 9 Mar 2026 09:47:49 -0700 Subject: [PATCH] feat: update return type for requestedToolConfirmations getter and setter to Map from ConcurrentMap PiperOrigin-RevId: 880903703 --- .../com/google/adk/events/EventActions.java | 25 +++++++++++++++---- .../google/adk/events/EventActionsTest.java | 24 ++++++++++++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/google/adk/events/EventActions.java b/core/src/main/java/com/google/adk/events/EventActions.java index bf25acfc7..31b096930 100644 --- a/core/src/main/java/com/google/adk/events/EventActions.java +++ b/core/src/main/java/com/google/adk/events/EventActions.java @@ -165,13 +165,20 @@ public void setRequestedAuthConfigs( } @JsonProperty("requestedToolConfirmations") - public ConcurrentMap requestedToolConfirmations() { + public Map requestedToolConfirmations() { return requestedToolConfirmations; } public void setRequestedToolConfirmations( - ConcurrentMap requestedToolConfirmations) { - this.requestedToolConfirmations = requestedToolConfirmations; + Map requestedToolConfirmations) { + if (requestedToolConfirmations == null) { + this.requestedToolConfirmations = new ConcurrentHashMap<>(); + } else if (requestedToolConfirmations instanceof ConcurrentMap) { + this.requestedToolConfirmations = + (ConcurrentMap) requestedToolConfirmations; + } else { + this.requestedToolConfirmations = new ConcurrentHashMap<>(requestedToolConfirmations); + } } @JsonProperty("endOfAgent") @@ -351,8 +358,16 @@ public Builder requestedAuthConfigs( @CanIgnoreReturnValue @JsonProperty("requestedToolConfirmations") - public Builder requestedToolConfirmations(ConcurrentMap value) { - this.requestedToolConfirmations = value; + public Builder requestedToolConfirmations(@Nullable Map value) { + if (value == null) { + this.requestedToolConfirmations = new ConcurrentHashMap<>(); + return this; + } + if (value instanceof ConcurrentMap) { + this.requestedToolConfirmations = (ConcurrentMap) value; + } else { + this.requestedToolConfirmations = new ConcurrentHashMap<>(value); + } return this; } diff --git a/core/src/test/java/com/google/adk/events/EventActionsTest.java b/core/src/test/java/com/google/adk/events/EventActionsTest.java index 28123bab8..2975ca83f 100644 --- a/core/src/test/java/com/google/adk/events/EventActionsTest.java +++ b/core/src/test/java/com/google/adk/events/EventActionsTest.java @@ -26,6 +26,7 @@ import com.google.genai.types.Part; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -165,4 +166,27 @@ public void merge_failsOnMismatchedKeyTypesNestedInStateDelta() { assertThrows( IllegalArgumentException.class, () -> eventActions1.toBuilder().merge(eventActions2)); } + + @Test + public void setRequestedToolConfirmations_withConcurrentMap_usesSameInstance() { + ConcurrentHashMap map = new ConcurrentHashMap<>(); + map.put("tool", TOOL_CONFIRMATION); + + EventActions actions = new EventActions(); + actions.setRequestedToolConfirmations(map); + + assertThat(actions.requestedToolConfirmations()).isSameInstanceAs(map); + } + + @Test + public void setRequestedToolConfirmations_withRegularMap_createsConcurrentMap() { + ImmutableMap map = ImmutableMap.of("tool", TOOL_CONFIRMATION); + + EventActions actions = new EventActions(); + actions.setRequestedToolConfirmations(map); + + assertThat(actions.requestedToolConfirmations()).isNotSameInstanceAs(map); + assertThat(actions.requestedToolConfirmations()).isInstanceOf(ConcurrentMap.class); + assertThat(actions.requestedToolConfirmations()).containsExactly("tool", TOOL_CONFIRMATION); + } }