memories) {
+ return memories(ImmutableList.copyOf(memories));
}
/** Builds the immutable {@link SearchMemoryResponse} object. */
diff --git a/core/src/main/java/com/google/adk/models/ChatCompletionsResponse.java b/core/src/main/java/com/google/adk/models/ChatCompletionsResponse.java
new file mode 100644
index 000000000..fe5cdd116
--- /dev/null
+++ b/core/src/main/java/com/google/adk/models/ChatCompletionsResponse.java
@@ -0,0 +1,224 @@
+/*
+ * Copyright 2026 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.adk.models;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Data Transfer Objects for Chat Completion and Chat Completion Chunk API responses.
+ *
+ * These classes are used for deserializing JSON responses from the `/chat/completions` endpoint.
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+final class ChatCompletionsResponse {
+
+ private ChatCompletionsResponse() {}
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ static class ChatCompletion {
+ public String id;
+ public List choices;
+ public Long created;
+ public String model;
+ public String object;
+
+ @JsonProperty("service_tier")
+ public String serviceTier;
+
+ @JsonProperty("system_fingerprint")
+ public String systemFingerprint;
+
+ public Usage usage;
+ }
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ static class Choice {
+ @JsonProperty("finish_reason")
+ public String finishReason;
+
+ public Integer index;
+ public Logprobs logprobs;
+ public Message message;
+ }
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ static class ChatCompletionChunk {
+ public String id;
+ public List choices;
+ public Long created;
+ public String model;
+ public String object;
+
+ @JsonProperty("service_tier")
+ public String serviceTier;
+
+ @JsonProperty("system_fingerprint")
+ public String systemFingerprint;
+
+ public Usage usage;
+ }
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ static class ChunkChoice {
+ @JsonProperty("finish_reason")
+ public String finishReason;
+
+ public Integer index;
+ public Logprobs logprobs;
+ public Message delta;
+ }
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ static class Message {
+ public String content;
+ public String refusal;
+ public String role;
+
+ @JsonProperty("tool_calls")
+ public List toolCalls;
+
+ // function_call is not supported in ChatCompletionChunk and ChatCompletion support is
+ // deprecated.
+ @JsonProperty("function_call")
+ public Function functionCall; // Fallback for deprecated top-level function calls
+
+ public List annotations;
+ public Audio audio;
+ }
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ static class ToolCall {
+ // Index is only used in ChatCompletionChunk.
+ public Integer index;
+ public String id;
+ public String type;
+ public Function function;
+ public Custom custom;
+
+ @JsonProperty("extra_content")
+ public Map extraContent;
+ }
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ static class Function {
+ public String name;
+ public String arguments; // JSON string
+ }
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ static class Custom {
+ public String input;
+ public String name;
+ }
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ static class Logprobs {
+ public List content;
+ public List refusal;
+ }
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ static class TokenLogprob {
+ public String token;
+ public List bytes;
+ public Double logprob;
+
+ @JsonProperty("top_logprobs")
+ public List topLogprobs;
+ }
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ static class Usage {
+ @JsonProperty("completion_tokens")
+ public Integer completionTokens;
+
+ @JsonProperty("prompt_tokens")
+ public Integer promptTokens;
+
+ @JsonProperty("total_tokens")
+ public Integer totalTokens;
+
+ @JsonProperty("thoughts_token_count")
+ public Integer thoughtsTokenCount; // Gemini-specific extension
+
+ @JsonProperty("completion_tokens_details")
+ public CompletionTokensDetails completionTokensDetails;
+
+ @JsonProperty("prompt_tokens_details")
+ public PromptTokensDetails promptTokensDetails;
+ }
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ static class CompletionTokensDetails {
+ @JsonProperty("accepted_prediction_tokens")
+ public Integer acceptedPredictionTokens;
+
+ @JsonProperty("audio_tokens")
+ public Integer audioTokens;
+
+ @JsonProperty("reasoning_tokens")
+ public Integer reasoningTokens;
+
+ @JsonProperty("rejected_prediction_tokens")
+ public Integer rejectedPredictionTokens;
+ }
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ static class PromptTokensDetails {
+ @JsonProperty("audio_tokens")
+ public Integer audioTokens;
+
+ @JsonProperty("cached_tokens")
+ public Integer cachedTokens;
+ }
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ static class Annotation {
+ public String type;
+
+ @JsonProperty("url_citation")
+ public UrlCitation urlCitation;
+ }
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ static class UrlCitation {
+ @JsonProperty("end_index")
+ public Integer endIndex;
+
+ @JsonProperty("start_index")
+ public Integer startIndex;
+
+ public String title;
+ public String url;
+ }
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ static class Audio {
+ public String id;
+ public String data;
+
+ @JsonProperty("expires_at")
+ public Long expiresAt;
+
+ public String transcript;
+ }
+}
diff --git a/core/src/main/java/com/google/adk/models/Claude.java b/core/src/main/java/com/google/adk/models/Claude.java
index 01feda1d4..79201c261 100644
--- a/core/src/main/java/com/google/adk/models/Claude.java
+++ b/core/src/main/java/com/google/adk/models/Claude.java
@@ -172,17 +172,11 @@ private ContentBlockParam partToAnthropicMessageBlock(Part part) {
if (part.functionResponse().get().response().isPresent()) {
Map responseData = part.functionResponse().get().response().get();
- Object contentObj = responseData.get("content");
Object resultObj = responseData.get("result");
-
- if (contentObj instanceof List> list && !list.isEmpty()) {
- // Native MCP format: list of content blocks
- content = extractMcpContentBlocks(list);
- } else if (resultObj != null) {
- // ADK tool result object
- content = resultObj instanceof String s ? s : serializeToJson(resultObj);
- } else if (!responseData.isEmpty()) {
- // Fallback: arbitrary JSON structure
+ if (resultObj != null) {
+ content = resultObj.toString();
+ } else {
+ // Fallback to json serialization of the function response.
content = serializeToJson(responseData);
}
}
@@ -196,21 +190,6 @@ private ContentBlockParam partToAnthropicMessageBlock(Part part) {
throw new UnsupportedOperationException("Not supported yet.");
}
- private String extractMcpContentBlocks(List> list) {
- List textBlocks = new ArrayList<>();
- for (Object item : list) {
- if (item instanceof Map, ?> m && "text".equals(m.get("type"))) {
- Object textObj = m.get("text");
- textBlocks.add(textObj != null ? String.valueOf(textObj) : "");
- } else if (item instanceof String s) {
- textBlocks.add(s);
- } else {
- textBlocks.add(serializeToJson(item));
- }
- }
- return String.join("\n", textBlocks);
- }
-
private String serializeToJson(Object obj) {
try {
return JsonBaseModel.getMapper().writeValueAsString(obj);
diff --git a/core/src/main/java/com/google/adk/models/LlmResponse.java b/core/src/main/java/com/google/adk/models/LlmResponse.java
index 1ca381e23..560e2abcc 100644
--- a/core/src/main/java/com/google/adk/models/LlmResponse.java
+++ b/core/src/main/java/com/google/adk/models/LlmResponse.java
@@ -33,7 +33,7 @@
import com.google.genai.types.GroundingMetadata;
import java.util.List;
import java.util.Optional;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/** Represents a response received from the LLM. */
@AutoValue
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 93dc05ec1..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,8 +18,9 @@
import com.google.auth.oauth2.GoogleCredentials;
import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.Optional;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/** Credentials for accessing Gemini models through Vertex. */
@AutoValue
@@ -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 aa5bf37de..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,12 +20,13 @@
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;
import java.util.Optional;
import java.util.function.BiFunction;
-import javax.annotation.Nullable;
+import org.jspecify.annotations.Nullable;
/** Configuration for the BigQueryAgentAnalyticsPlugin. */
@AutoValue
@@ -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