From 4b53375610979175397068c5add8ac200bb41076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Sobczyk?= Date: Fri, 27 Mar 2026 05:51:51 -0700 Subject: [PATCH] refactor: standarize AutoValue Builder setter names Updates AutoValue Builders to use the `property(value)` naming convention for setters, instead of the `setProperty(value)` convention. This change promotes consistency across the codebase. Deprecated `setProperty()` methods are retained where necessary for backward compatibility, and now delegate to the new `property()` methods. PiperOrigin-RevId: 890404260 --- .../java/com/google/adk/agents/RunConfig.java | 104 +++++-- .../adk/memory/SearchMemoryResponse.java | 23 +- .../google/adk/models/VertexCredentials.java | 28 +- .../agentanalytics/BigQueryLoggerConfig.java | 260 +++++++++++++++--- .../com/google/adk/tools/ExampleTool.java | 26 +- 5 files changed, 362 insertions(+), 79 deletions(-) diff --git a/core/src/main/java/com/google/adk/agents/RunConfig.java b/core/src/main/java/com/google/adk/agents/RunConfig.java index 661a5cddf..3ec02e1da 100644 --- a/core/src/main/java/com/google/adk/agents/RunConfig.java +++ b/core/src/main/java/com/google/adk/agents/RunConfig.java @@ -76,59 +76,115 @@ public enum ToolExecutionMode { public static Builder builder() { return new AutoValue_RunConfig.Builder() - .setSaveInputBlobsAsArtifacts(false) - .setResponseModalities(ImmutableList.of()) - .setStreamingMode(StreamingMode.NONE) - .setToolExecutionMode(ToolExecutionMode.NONE) - .setMaxLlmCalls(500) - .setAutoCreateSession(false); + .saveInputBlobsAsArtifacts(false) + .responseModalities(ImmutableList.of()) + .streamingMode(StreamingMode.NONE) + .toolExecutionMode(ToolExecutionMode.NONE) + .maxLlmCalls(500) + .autoCreateSession(false); } public static Builder builder(RunConfig runConfig) { return new AutoValue_RunConfig.Builder() - .setSaveInputBlobsAsArtifacts(runConfig.saveInputBlobsAsArtifacts()) - .setStreamingMode(runConfig.streamingMode()) - .setToolExecutionMode(runConfig.toolExecutionMode()) - .setMaxLlmCalls(runConfig.maxLlmCalls()) - .setResponseModalities(runConfig.responseModalities()) - .setSpeechConfig(runConfig.speechConfig()) - .setOutputAudioTranscription(runConfig.outputAudioTranscription()) - .setInputAudioTranscription(runConfig.inputAudioTranscription()) - .setAutoCreateSession(runConfig.autoCreateSession()); + .saveInputBlobsAsArtifacts(runConfig.saveInputBlobsAsArtifacts()) + .streamingMode(runConfig.streamingMode()) + .toolExecutionMode(runConfig.toolExecutionMode()) + .maxLlmCalls(runConfig.maxLlmCalls()) + .responseModalities(runConfig.responseModalities()) + .speechConfig(runConfig.speechConfig()) + .outputAudioTranscription(runConfig.outputAudioTranscription()) + .inputAudioTranscription(runConfig.inputAudioTranscription()) + .autoCreateSession(runConfig.autoCreateSession()); } /** Builder for {@link RunConfig}. */ @AutoValue.Builder public abstract static class Builder { + @Deprecated @CanIgnoreReturnValue - public abstract Builder setSpeechConfig(@Nullable SpeechConfig speechConfig); + public final Builder setSpeechConfig(@Nullable SpeechConfig speechConfig) { + return speechConfig(speechConfig); + } + + @CanIgnoreReturnValue + public abstract Builder speechConfig(@Nullable SpeechConfig speechConfig); + + @Deprecated + @CanIgnoreReturnValue + public final Builder setResponseModalities(Iterable responseModalities) { + return responseModalities(responseModalities); + } + + @CanIgnoreReturnValue + public abstract Builder responseModalities(Iterable responseModalities); + @Deprecated @CanIgnoreReturnValue - public abstract Builder setResponseModalities(Iterable responseModalities); + public final Builder setSaveInputBlobsAsArtifacts(boolean saveInputBlobsAsArtifacts) { + return saveInputBlobsAsArtifacts(saveInputBlobsAsArtifacts); + } @CanIgnoreReturnValue - public abstract Builder setSaveInputBlobsAsArtifacts(boolean saveInputBlobsAsArtifacts); + public abstract Builder saveInputBlobsAsArtifacts(boolean saveInputBlobsAsArtifacts); + @Deprecated @CanIgnoreReturnValue - public abstract Builder setStreamingMode(StreamingMode streamingMode); + public final Builder setStreamingMode(StreamingMode streamingMode) { + return streamingMode(streamingMode); + } @CanIgnoreReturnValue - public abstract Builder setToolExecutionMode(ToolExecutionMode toolExecutionMode); + public abstract Builder streamingMode(StreamingMode streamingMode); + @Deprecated @CanIgnoreReturnValue - public abstract Builder setOutputAudioTranscription( + public final Builder setToolExecutionMode(ToolExecutionMode toolExecutionMode) { + return toolExecutionMode(toolExecutionMode); + } + + @CanIgnoreReturnValue + public abstract Builder toolExecutionMode(ToolExecutionMode toolExecutionMode); + + @Deprecated + @CanIgnoreReturnValue + public final Builder setOutputAudioTranscription( + @Nullable AudioTranscriptionConfig outputAudioTranscription) { + return outputAudioTranscription(outputAudioTranscription); + } + + @CanIgnoreReturnValue + public abstract Builder outputAudioTranscription( @Nullable AudioTranscriptionConfig outputAudioTranscription); + @Deprecated + @CanIgnoreReturnValue + public final Builder setInputAudioTranscription( + @Nullable AudioTranscriptionConfig inputAudioTranscription) { + return inputAudioTranscription(inputAudioTranscription); + } + @CanIgnoreReturnValue - public abstract Builder setInputAudioTranscription( + public abstract Builder inputAudioTranscription( @Nullable AudioTranscriptionConfig inputAudioTranscription); + @Deprecated @CanIgnoreReturnValue - public abstract Builder setMaxLlmCalls(int maxLlmCalls); + public final Builder setMaxLlmCalls(int maxLlmCalls) { + return maxLlmCalls(maxLlmCalls); + } + + @CanIgnoreReturnValue + public abstract Builder maxLlmCalls(int maxLlmCalls); + + @Deprecated + @CanIgnoreReturnValue + public final Builder setAutoCreateSession(boolean autoCreateSession) { + return autoCreateSession(autoCreateSession); + } @CanIgnoreReturnValue - public abstract Builder setAutoCreateSession(boolean autoCreateSession); + public abstract Builder autoCreateSession(boolean autoCreateSession); abstract RunConfig autoBuild(); diff --git a/core/src/main/java/com/google/adk/memory/SearchMemoryResponse.java b/core/src/main/java/com/google/adk/memory/SearchMemoryResponse.java index b282bdfc8..b14e1d156 100644 --- a/core/src/main/java/com/google/adk/memory/SearchMemoryResponse.java +++ b/core/src/main/java/com/google/adk/memory/SearchMemoryResponse.java @@ -18,6 +18,7 @@ import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.List; /** Represents the response from a memory search. */ @@ -29,18 +30,32 @@ public abstract class SearchMemoryResponse { /** Creates a new builder for {@link SearchMemoryResponse}. */ public static Builder builder() { - return new AutoValue_SearchMemoryResponse.Builder().setMemories(ImmutableList.of()); + return new AutoValue_SearchMemoryResponse.Builder().memories(ImmutableList.of()); } /** Builder for {@link SearchMemoryResponse}. */ @AutoValue.Builder public abstract static class Builder { - abstract Builder setMemories(ImmutableList memories); + @Deprecated + @CanIgnoreReturnValue + public final Builder setMemories(ImmutableList memories) { + return memories(memories); + } /** Sets the list of memory entries using a list. */ - public Builder setMemories(List memories) { - return setMemories(ImmutableList.copyOf(memories)); + @Deprecated + @CanIgnoreReturnValue + public final Builder setMemories(List memories) { + return memories(ImmutableList.copyOf(memories)); + } + + @CanIgnoreReturnValue + public abstract Builder memories(ImmutableList memories); + + @CanIgnoreReturnValue + public Builder memories(List memories) { + return memories(ImmutableList.copyOf(memories)); } /** Builds the immutable {@link SearchMemoryResponse} object. */ diff --git a/core/src/main/java/com/google/adk/models/VertexCredentials.java b/core/src/main/java/com/google/adk/models/VertexCredentials.java index 0ae81c2a4..2c069b0dd 100644 --- a/core/src/main/java/com/google/adk/models/VertexCredentials.java +++ b/core/src/main/java/com/google/adk/models/VertexCredentials.java @@ -18,6 +18,7 @@ import com.google.auth.oauth2.GoogleCredentials; import com.google.auto.value.AutoValue; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.Optional; import org.jspecify.annotations.Nullable; @@ -39,11 +40,32 @@ public static Builder builder() { @AutoValue.Builder public abstract static class Builder { - public abstract Builder setProject(@Nullable String value); + @Deprecated + @CanIgnoreReturnValue + public final Builder setProject(@Nullable String value) { + return project(value); + } - public abstract Builder setLocation(@Nullable String value); + @CanIgnoreReturnValue + public abstract Builder project(@Nullable String value); - public abstract Builder setCredentials(@Nullable GoogleCredentials value); + @Deprecated + @CanIgnoreReturnValue + public final Builder setLocation(@Nullable String value) { + return location(value); + } + + @CanIgnoreReturnValue + public abstract Builder location(@Nullable String value); + + @Deprecated + @CanIgnoreReturnValue + public final Builder setCredentials(@Nullable GoogleCredentials value) { + return credentials(value); + } + + @CanIgnoreReturnValue + public abstract Builder credentials(@Nullable GoogleCredentials value); public abstract VertexCredentials build(); } diff --git a/core/src/main/java/com/google/adk/plugins/agentanalytics/BigQueryLoggerConfig.java b/core/src/main/java/com/google/adk/plugins/agentanalytics/BigQueryLoggerConfig.java index a7bae007f..22ced137e 100644 --- a/core/src/main/java/com/google/adk/plugins/agentanalytics/BigQueryLoggerConfig.java +++ b/core/src/main/java/com/google/adk/plugins/agentanalytics/BigQueryLoggerConfig.java @@ -20,6 +20,7 @@ import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.time.Duration; import java.util.List; import java.util.Map; @@ -104,66 +105,208 @@ public abstract class BigQueryLoggerConfig { public static Builder builder() { return new AutoValue_BigQueryLoggerConfig.Builder() - .setEnabled(true) - .setMaxContentLength(500 * 1024) - .setDatasetId("agent_analytics") - .setTableName("events") - .setClusteringFields(ImmutableList.of("event_type", "agent", "user_id")) - .setLogMultiModalContent(true) - .setRetryConfig(RetryConfig.builder().build()) - .setBatchSize(1) - .setBatchFlushInterval(Duration.ofSeconds(1)) - .setShutdownTimeout(Duration.ofSeconds(10)) - .setQueueMaxSize(10000) - .setLogSessionMetadata(true) - .setCustomTags(ImmutableMap.of()) + .enabled(true) + .maxContentLength(500 * 1024) + .datasetId("agent_analytics") + .tableName("events") + .clusteringFields(ImmutableList.of("event_type", "agent", "user_id")) + .logMultiModalContent(true) + .retryConfig(RetryConfig.builder().build()) + .batchSize(1) + .batchFlushInterval(Duration.ofSeconds(1)) + .shutdownTimeout(Duration.ofSeconds(10)) + .queueMaxSize(10000) + .logSessionMetadata(true) + .customTags(ImmutableMap.of()) // TODO(b/491851868): Enable auto-schema upgrade once implemented. - .setAutoSchemaUpgrade(false); + .autoSchemaUpgrade(false); } /** Builder for {@link BigQueryLoggerConfig}. */ @AutoValue.Builder public abstract static class Builder { - public abstract Builder setEnabled(boolean enabled); - public abstract Builder setEventAllowlist(@Nullable List eventAllowlist); + @Deprecated + @CanIgnoreReturnValue + public final Builder setEnabled(boolean enabled) { + return enabled(enabled); + } + + @CanIgnoreReturnValue + public abstract Builder enabled(boolean enabled); + + @Deprecated + @CanIgnoreReturnValue + public final Builder setEventAllowlist(@Nullable List eventAllowlist) { + return eventAllowlist(eventAllowlist); + } + + @CanIgnoreReturnValue + public abstract Builder eventAllowlist(@Nullable List eventAllowlist); + + @Deprecated + @CanIgnoreReturnValue + public final Builder setEventDenylist(@Nullable List eventDenylist) { + return eventDenylist(eventDenylist); + } + + @CanIgnoreReturnValue + public abstract Builder eventDenylist(@Nullable List eventDenylist); + + @Deprecated + @CanIgnoreReturnValue + public final Builder setMaxContentLength(int maxContentLength) { + return maxContentLength(maxContentLength); + } + + @CanIgnoreReturnValue + public abstract Builder maxContentLength(int maxContentLength); - public abstract Builder setEventDenylist(@Nullable List eventDenylist); + @Deprecated + @CanIgnoreReturnValue + public final Builder setProjectId(String projectId) { + return projectId(projectId); + } - public abstract Builder setMaxContentLength(int maxContentLength); + @CanIgnoreReturnValue + public abstract Builder projectId(String projectId); - public abstract Builder setProjectId(String projectId); + @Deprecated + @CanIgnoreReturnValue + public final Builder setDatasetId(String datasetId) { + return datasetId(datasetId); + } - public abstract Builder setDatasetId(String datasetId); + @CanIgnoreReturnValue + public abstract Builder datasetId(String datasetId); - public abstract Builder setTableName(String tableName); + @Deprecated + @CanIgnoreReturnValue + public final Builder setTableName(String tableName) { + return tableName(tableName); + } - public abstract Builder setClusteringFields(List clusteringFields); + @CanIgnoreReturnValue + public abstract Builder tableName(String tableName); - public abstract Builder setLogMultiModalContent(boolean logMultiModalContent); + @Deprecated + @CanIgnoreReturnValue + public final Builder setClusteringFields(List clusteringFields) { + return clusteringFields(clusteringFields); + } - public abstract Builder setRetryConfig(RetryConfig retryConfig); + @CanIgnoreReturnValue + public abstract Builder clusteringFields(List clusteringFields); - public abstract Builder setBatchSize(int batchSize); + @Deprecated + @CanIgnoreReturnValue + public final Builder setLogMultiModalContent(boolean logMultiModalContent) { + return logMultiModalContent(logMultiModalContent); + } - public abstract Builder setBatchFlushInterval(Duration batchFlushInterval); + @CanIgnoreReturnValue + public abstract Builder logMultiModalContent(boolean logMultiModalContent); - public abstract Builder setShutdownTimeout(Duration shutdownTimeout); + @Deprecated + @CanIgnoreReturnValue + public final Builder setRetryConfig(RetryConfig retryConfig) { + return retryConfig(retryConfig); + } - public abstract Builder setQueueMaxSize(int queueMaxSize); + @CanIgnoreReturnValue + public abstract Builder retryConfig(RetryConfig retryConfig); + + @Deprecated + @CanIgnoreReturnValue + public final Builder setBatchSize(int batchSize) { + return batchSize(batchSize); + } + + @CanIgnoreReturnValue + public abstract Builder batchSize(int batchSize); + + @Deprecated + @CanIgnoreReturnValue + public final Builder setBatchFlushInterval(Duration batchFlushInterval) { + return batchFlushInterval(batchFlushInterval); + } - public abstract Builder setContentFormatter( + @CanIgnoreReturnValue + public abstract Builder batchFlushInterval(Duration batchFlushInterval); + + @Deprecated + @CanIgnoreReturnValue + public final Builder setShutdownTimeout(Duration shutdownTimeout) { + return shutdownTimeout(shutdownTimeout); + } + + @CanIgnoreReturnValue + public abstract Builder shutdownTimeout(Duration shutdownTimeout); + + @Deprecated + @CanIgnoreReturnValue + public final Builder setQueueMaxSize(int queueMaxSize) { + return queueMaxSize(queueMaxSize); + } + + @CanIgnoreReturnValue + public abstract Builder queueMaxSize(int queueMaxSize); + + @Deprecated + @CanIgnoreReturnValue + public final Builder setContentFormatter( + @Nullable BiFunction contentFormatter) { + return contentFormatter(contentFormatter); + } + + @CanIgnoreReturnValue + public abstract Builder contentFormatter( @Nullable BiFunction contentFormatter); - public abstract Builder setConnectionId(String connectionId); + @Deprecated + @CanIgnoreReturnValue + public final Builder setConnectionId(String connectionId) { + return connectionId(connectionId); + } - public abstract Builder setLogSessionMetadata(boolean logSessionMetadata); + @CanIgnoreReturnValue + public abstract Builder connectionId(String connectionId); - public abstract Builder setCustomTags(Map customTags); + @Deprecated + @CanIgnoreReturnValue + public final Builder setLogSessionMetadata(boolean logSessionMetadata) { + return logSessionMetadata(logSessionMetadata); + } - public abstract Builder setAutoSchemaUpgrade(boolean autoSchemaUpgrade); + @CanIgnoreReturnValue + public abstract Builder logSessionMetadata(boolean logSessionMetadata); - public abstract Builder setCredentials(Credentials credentials); + @Deprecated + @CanIgnoreReturnValue + public final Builder setCustomTags(Map customTags) { + return customTags(customTags); + } + + @CanIgnoreReturnValue + public abstract Builder customTags(Map customTags); + + @Deprecated + @CanIgnoreReturnValue + public final Builder setAutoSchemaUpgrade(boolean autoSchemaUpgrade) { + return autoSchemaUpgrade(autoSchemaUpgrade); + } + + @CanIgnoreReturnValue + public abstract Builder autoSchemaUpgrade(boolean autoSchemaUpgrade); + + @Deprecated + @CanIgnoreReturnValue + public final Builder setCredentials(Credentials credentials) { + return credentials(credentials); + } + + @CanIgnoreReturnValue + public abstract Builder credentials(Credentials credentials); public abstract BigQueryLoggerConfig build(); } @@ -181,22 +324,51 @@ public abstract static class RetryConfig { public static Builder builder() { return new AutoValue_BigQueryLoggerConfig_RetryConfig.Builder() - .setMaxRetries(3) - .setInitialDelay(Duration.ofSeconds(1)) - .setMultiplier(2.0) - .setMaxDelay(Duration.ofSeconds(10)); + .maxRetries(3) + .initialDelay(Duration.ofSeconds(1)) + .multiplier(2.0) + .maxDelay(Duration.ofSeconds(10)); } /** Builder for {@link RetryConfig}. */ @AutoValue.Builder public abstract static class Builder { - public abstract Builder setMaxRetries(int maxRetries); - - public abstract Builder setInitialDelay(Duration initialDelay); - - public abstract Builder setMultiplier(double multiplier); - public abstract Builder setMaxDelay(Duration maxDelay); + @Deprecated + @CanIgnoreReturnValue + public final Builder setMaxRetries(int maxRetries) { + return maxRetries(maxRetries); + } + + @CanIgnoreReturnValue + public abstract Builder maxRetries(int maxRetries); + + @Deprecated + @CanIgnoreReturnValue + public final Builder setInitialDelay(Duration initialDelay) { + return initialDelay(initialDelay); + } + + @CanIgnoreReturnValue + public abstract Builder initialDelay(Duration initialDelay); + + @Deprecated + @CanIgnoreReturnValue + public final Builder setMultiplier(double multiplier) { + return multiplier(multiplier); + } + + @CanIgnoreReturnValue + public abstract Builder multiplier(double multiplier); + + @Deprecated + @CanIgnoreReturnValue + public final Builder setMaxDelay(Duration maxDelay) { + return maxDelay(maxDelay); + } + + @CanIgnoreReturnValue + public abstract Builder maxDelay(Duration maxDelay); public abstract RetryConfig build(); } diff --git a/core/src/main/java/com/google/adk/tools/ExampleTool.java b/core/src/main/java/com/google/adk/tools/ExampleTool.java index d03c2e4f1..c11259c52 100644 --- a/core/src/main/java/com/google/adk/tools/ExampleTool.java +++ b/core/src/main/java/com/google/adk/tools/ExampleTool.java @@ -102,7 +102,7 @@ public static ExampleTool fromConfig(ToolArgsConfig args, String configAbsPath) var maybeExamplesProvider = args.getOrEmpty("examples", new TypeReference() {}); if (maybeExamplesProvider.isPresent()) { BaseExampleProvider provider = resolveExampleProvider(maybeExamplesProvider.get()); - return ExampleTool.builder().setExampleProvider(provider).build(); + return ExampleTool.builder().exampleProvider(provider).build(); } var maybeListOfExamples = args.getOrEmpty("examples", new TypeReference>() {}); if (maybeListOfExamples.isPresent()) { @@ -166,14 +166,26 @@ public static final class Builder { private String description = "Adds few-shot examples to the request"; private Optional provider = Optional.empty(); + @Deprecated @CanIgnoreReturnValue - public Builder setName(String name) { + public final Builder setName(String name) { + return name(name); + } + + @CanIgnoreReturnValue + public Builder name(String name) { this.name = name; return this; } + @Deprecated @CanIgnoreReturnValue - public Builder setDescription(String description) { + public final Builder setDescription(String description) { + return description(description); + } + + @CanIgnoreReturnValue + public Builder description(String description) { this.description = description; return this; } @@ -184,8 +196,14 @@ public Builder addExample(Example ex) { return this; } + @Deprecated + @CanIgnoreReturnValue + public final Builder setExampleProvider(BaseExampleProvider provider) { + return exampleProvider(provider); + } + @CanIgnoreReturnValue - public Builder setExampleProvider(BaseExampleProvider provider) { + public Builder exampleProvider(BaseExampleProvider provider) { this.provider = Optional.ofNullable(provider); return this; }