From ed74f1b293d8545e9d5746c9bee1486410afd83e Mon Sep 17 00:00:00 2001 From: Google Team Member Date: Tue, 13 Oct 2026 17:55:32 -0700 Subject: [PATCH] feat: Add client.memory_banks.update method. PiperOrigin-RevId: 999011108 --- .../cloud/agentplatform/AsyncMemoryBanks.java | 18 +++ .../cloud/agentplatform/MemoryBanks.java | 141 ++++++++++++++++ .../types/UpdateMemoryBankConfig.java | 132 +++++++++++++++ .../UpdateMemoryBankRequestParameters.java | 153 ++++++++++++++++++ 4 files changed, 444 insertions(+) create mode 100644 src/main/java/com/google/cloud/agentplatform/types/UpdateMemoryBankConfig.java create mode 100644 src/main/java/com/google/cloud/agentplatform/types/UpdateMemoryBankRequestParameters.java diff --git a/src/main/java/com/google/cloud/agentplatform/AsyncMemoryBanks.java b/src/main/java/com/google/cloud/agentplatform/AsyncMemoryBanks.java index df75737..b431606 100644 --- a/src/main/java/com/google/cloud/agentplatform/AsyncMemoryBanks.java +++ b/src/main/java/com/google/cloud/agentplatform/AsyncMemoryBanks.java @@ -32,6 +32,7 @@ import com.google.cloud.agentplatform.types.MemoryGenerationTriggerConfig; import com.google.cloud.agentplatform.types.ReasoningEngine; import com.google.cloud.agentplatform.types.ReasoningEngineContextSpecMemoryBankConfig; +import com.google.cloud.agentplatform.types.UpdateMemoryBankConfig; import com.google.genai.ApiClient; import com.google.genai.ApiResponse; import com.google.genai.Common.BuiltRequest; @@ -66,6 +67,23 @@ CompletableFuture privateCreate( }); } + CompletableFuture privateUpdate( + String name, + ReasoningEngineContextSpecMemoryBankConfig memoryBankConfig, + UpdateMemoryBankConfig config) { + + BuiltRequest builtRequest = + memoryBanks.buildRequestForPrivateUpdate(name, memoryBankConfig, config); + return this.apiClient + .asyncRequest("patch", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions()) + .thenApplyAsync( + response -> { + try (ApiResponse res = response) { + return memoryBanks.processResponseForPrivateUpdate(res, config); + } + }); + } + CompletableFuture privateDelete( String name, boolean force, DeleteMemoryBankConfig config) { diff --git a/src/main/java/com/google/cloud/agentplatform/MemoryBanks.java b/src/main/java/com/google/cloud/agentplatform/MemoryBanks.java index dbdbc0d..0c87d48 100644 --- a/src/main/java/com/google/cloud/agentplatform/MemoryBanks.java +++ b/src/main/java/com/google/cloud/agentplatform/MemoryBanks.java @@ -42,6 +42,8 @@ import com.google.cloud.agentplatform.types.MemoryGenerationTriggerConfig; import com.google.cloud.agentplatform.types.ReasoningEngine; import com.google.cloud.agentplatform.types.ReasoningEngineContextSpecMemoryBankConfig; +import com.google.cloud.agentplatform.types.UpdateMemoryBankConfig; +import com.google.cloud.agentplatform.types.UpdateMemoryBankRequestParameters; import com.google.genai.ApiClient; import com.google.genai.ApiResponse; import com.google.genai.Common; @@ -813,6 +815,59 @@ ObjectNode structuredMemorySchemaConfigToVertex(JsonNode fromObject, ObjectNode return toObject; } + @ExcludeFromGeneratedCoverageReport + ObjectNode updateMemoryBankConfigToVertex(JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode(); + + if (Common.getValueByPath(fromObject, new String[] {"displayName"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"displayName"}, + Common.getValueByPath(fromObject, new String[] {"displayName"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"description"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"description"}, + Common.getValueByPath(fromObject, new String[] {"description"})); + } + + return toObject; + } + + @ExcludeFromGeneratedCoverageReport + ObjectNode updateMemoryBankRequestParametersToVertex( + JsonNode fromObject, ObjectNode parentObject) { + ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode(); + if (Common.getValueByPath(fromObject, new String[] {"name"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"_url", "name"}, + Common.getValueByPath(fromObject, new String[] {"name"})); + } + + if (Common.getValueByPath(fromObject, new String[] {"memoryBankConfig"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"context_spec", "memory_bank_config"}, + reasoningEngineContextSpecMemoryBankConfigToVertex( + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"memoryBankConfig"})), + toObject)); + } + + if (Common.getValueByPath(fromObject, new String[] {"config"}) != null) { + JsonNode unused = + updateMemoryBankConfigToVertex( + JsonSerializable.toJsonNode( + Common.getValueByPath(fromObject, new String[] {"config"})), + toObject); + } + + return toObject; + } + /** A shared buildRequest method for both sync and async methods. */ BuiltRequest buildRequestForPrivateCreate( ReasoningEngineContextSpecMemoryBankConfig memoryBankConfig, CreateMemoryBankConfig config) { @@ -892,6 +947,92 @@ public MemoryBankOperation privateCreate( } } + /** A shared buildRequest method for both sync and async methods. */ + BuiltRequest buildRequestForPrivateUpdate( + String name, + ReasoningEngineContextSpecMemoryBankConfig memoryBankConfig, + UpdateMemoryBankConfig config) { + + UpdateMemoryBankRequestParameters.Builder parameterBuilder = + UpdateMemoryBankRequestParameters.builder(); + + if (!Common.isZero(name)) { + parameterBuilder.name(name); + } + if (!Common.isZero(memoryBankConfig)) { + parameterBuilder.memoryBankConfig(memoryBankConfig); + } + if (!Common.isZero(config)) { + parameterBuilder.config(config); + } + JsonNode parameterNode = JsonSerializable.toJsonNode(parameterBuilder.build()); + + ObjectNode body; + String path; + if (this.apiClient.vertexAI()) { + body = updateMemoryBankRequestParametersToVertex(parameterNode, null); + path = Common.formatMap("{name}", body.get("_url")); + } else { + throw new UnsupportedOperationException( + "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini" + + " Developer API mode."); + } + body.remove("_url"); + + JsonNode queryParams = body.get("_query"); + if (queryParams != null) { + body.remove("_query"); + path = String.format("%s?%s", path, Common.urlEncode((ObjectNode) queryParams)); + } + + // TODO: Remove the hack that removes config. + Optional requestHttpOptions = Optional.empty(); + if (config != null) { + requestHttpOptions = config.httpOptions(); + } + + return new BuiltRequest(path, JsonSerializable.toJsonString(body), requestHttpOptions); + } + + /** A shared processResponse function for both sync and async methods. */ + MemoryBankOperation processResponseForPrivateUpdate( + ApiResponse response, UpdateMemoryBankConfig config) { + ResponseBody responseBody = response.getBody(); + String responseString; + try { + responseString = responseBody.string(); + } catch (IOException e) { + throw new GenAiIOException("Failed to read HTTP response.", e); + } + + JsonNode responseNode = JsonSerializable.stringToJsonNode(responseString); + + if (this.apiClient.vertexAI()) { + responseNode = memoryBankOperationFromVertex(responseNode, null); + } + + if (!this.apiClient.vertexAI()) { + throw new UnsupportedOperationException( + "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini" + + " Developer API mode."); + } + + return JsonSerializable.fromJsonNode(responseNode, MemoryBankOperation.class); + } + + public MemoryBankOperation privateUpdate( + String name, + ReasoningEngineContextSpecMemoryBankConfig memoryBankConfig, + UpdateMemoryBankConfig config) { + BuiltRequest builtRequest = buildRequestForPrivateUpdate(name, memoryBankConfig, config); + + try (ApiResponse response = + this.apiClient.request( + "patch", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())) { + return processResponseForPrivateUpdate(response, config); + } + } + /** A shared buildRequest method for both sync and async methods. */ BuiltRequest buildRequestForPrivateDelete( String name, boolean force, DeleteMemoryBankConfig config) { diff --git a/src/main/java/com/google/cloud/agentplatform/types/UpdateMemoryBankConfig.java b/src/main/java/com/google/cloud/agentplatform/types/UpdateMemoryBankConfig.java new file mode 100644 index 0000000..6322c07 --- /dev/null +++ b/src/main/java/com/google/cloud/agentplatform/types/UpdateMemoryBankConfig.java @@ -0,0 +1,132 @@ +/* + * Copyright 2025 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. + */ + +// Auto-generated code. Do not edit. + +package com.google.cloud.agentplatform.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.auto.value.AutoValue; +import com.google.errorprone.annotations.CanIgnoreReturnValue; +import com.google.genai.JsonSerializable; +import com.google.genai.types.HttpOptions; +import java.util.Optional; + +/** Config for updating a memory bank. */ +@AutoValue +@JsonDeserialize(builder = UpdateMemoryBankConfig.Builder.class) +public abstract class UpdateMemoryBankConfig extends JsonSerializable { + /** Used to override HTTP request options. */ + @JsonProperty("httpOptions") + public abstract Optional httpOptions(); + + /** + * The user-defined name of the Memory Bank. + * + *

The display name can be up to 128 characters long and can comprise any UTF-8 characters. + */ + @JsonProperty("displayName") + public abstract Optional displayName(); + + /** The description of the Memory Bank. */ + @JsonProperty("description") + public abstract Optional description(); + + /** Instantiates a builder for UpdateMemoryBankConfig. */ + @ExcludeFromGeneratedCoverageReport + public static Builder builder() { + return new AutoValue_UpdateMemoryBankConfig.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for UpdateMemoryBankConfig. */ + @AutoValue.Builder + public abstract static class Builder { + /** For internal usage. Please use `UpdateMemoryBankConfig.builder()` for instantiation. */ + @JsonCreator + private static Builder create() { + return new AutoValue_UpdateMemoryBankConfig.Builder(); + } + + /** + * Setter for httpOptions. + * + *

httpOptions: Used to override HTTP request options. + */ + @JsonProperty("httpOptions") + public abstract Builder httpOptions(HttpOptions httpOptions); + + @ExcludeFromGeneratedCoverageReport + abstract Builder httpOptions(Optional httpOptions); + + /** Clears the value of httpOptions field. */ + @ExcludeFromGeneratedCoverageReport + @CanIgnoreReturnValue + public Builder clearHttpOptions() { + return httpOptions(Optional.empty()); + } + + /** + * Setter for displayName. + * + *

displayName: The user-defined name of the Memory Bank. + * + *

The display name can be up to 128 characters long and can comprise any UTF-8 characters. + */ + @JsonProperty("displayName") + public abstract Builder displayName(String displayName); + + @ExcludeFromGeneratedCoverageReport + abstract Builder displayName(Optional displayName); + + /** Clears the value of displayName field. */ + @ExcludeFromGeneratedCoverageReport + @CanIgnoreReturnValue + public Builder clearDisplayName() { + return displayName(Optional.empty()); + } + + /** + * Setter for description. + * + *

description: The description of the Memory Bank. + */ + @JsonProperty("description") + public abstract Builder description(String description); + + @ExcludeFromGeneratedCoverageReport + abstract Builder description(Optional description); + + /** Clears the value of description field. */ + @ExcludeFromGeneratedCoverageReport + @CanIgnoreReturnValue + public Builder clearDescription() { + return description(Optional.empty()); + } + + public abstract UpdateMemoryBankConfig build(); + } + + /** Deserializes a JSON string to a UpdateMemoryBankConfig object. */ + @ExcludeFromGeneratedCoverageReport + public static UpdateMemoryBankConfig fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, UpdateMemoryBankConfig.class); + } +} diff --git a/src/main/java/com/google/cloud/agentplatform/types/UpdateMemoryBankRequestParameters.java b/src/main/java/com/google/cloud/agentplatform/types/UpdateMemoryBankRequestParameters.java new file mode 100644 index 0000000..070d4fd --- /dev/null +++ b/src/main/java/com/google/cloud/agentplatform/types/UpdateMemoryBankRequestParameters.java @@ -0,0 +1,153 @@ +/* + * Copyright 2025 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. + */ + +// Auto-generated code. Do not edit. + +package com.google.cloud.agentplatform.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.google.api.core.InternalApi; +import com.google.auto.value.AutoValue; +import com.google.errorprone.annotations.CanIgnoreReturnValue; +import com.google.genai.JsonSerializable; +import java.util.Optional; + +/** Parameters for updating memory banks. */ +@AutoValue +@InternalApi +@JsonDeserialize(builder = UpdateMemoryBankRequestParameters.Builder.class) +public abstract class UpdateMemoryBankRequestParameters extends JsonSerializable { + /** Name of the memory bank. */ + @JsonProperty("name") + public abstract Optional name(); + + /** */ + @JsonProperty("memoryBankConfig") + public abstract Optional memoryBankConfig(); + + /** */ + @JsonProperty("config") + public abstract Optional config(); + + /** Instantiates a builder for UpdateMemoryBankRequestParameters. */ + @ExcludeFromGeneratedCoverageReport + public static Builder builder() { + return new AutoValue_UpdateMemoryBankRequestParameters.Builder(); + } + + /** Creates a builder with the same values as this instance. */ + public abstract Builder toBuilder(); + + /** Builder for UpdateMemoryBankRequestParameters. */ + @AutoValue.Builder + public abstract static class Builder { + /** + * For internal usage. Please use `UpdateMemoryBankRequestParameters.builder()` for + * instantiation. + */ + @JsonCreator + private static Builder create() { + return new AutoValue_UpdateMemoryBankRequestParameters.Builder(); + } + + /** + * Setter for name. + * + *

name: Name of the memory bank. + */ + @JsonProperty("name") + public abstract Builder name(String name); + + @ExcludeFromGeneratedCoverageReport + abstract Builder name(Optional name); + + /** Clears the value of name field. */ + @ExcludeFromGeneratedCoverageReport + @CanIgnoreReturnValue + public Builder clearName() { + return name(Optional.empty()); + } + + /** + * Setter for memoryBankConfig. + * + *

memoryBankConfig: + */ + @JsonProperty("memoryBankConfig") + public abstract Builder memoryBankConfig( + ReasoningEngineContextSpecMemoryBankConfig memoryBankConfig); + + /** + * Setter for memoryBankConfig builder. + * + *

memoryBankConfig: + */ + @CanIgnoreReturnValue + public Builder memoryBankConfig( + ReasoningEngineContextSpecMemoryBankConfig.Builder memoryBankConfigBuilder) { + return memoryBankConfig(memoryBankConfigBuilder.build()); + } + + @ExcludeFromGeneratedCoverageReport + abstract Builder memoryBankConfig( + Optional memoryBankConfig); + + /** Clears the value of memoryBankConfig field. */ + @ExcludeFromGeneratedCoverageReport + @CanIgnoreReturnValue + public Builder clearMemoryBankConfig() { + return memoryBankConfig(Optional.empty()); + } + + /** + * Setter for config. + * + *

config: + */ + @JsonProperty("config") + public abstract Builder config(UpdateMemoryBankConfig config); + + /** + * Setter for config builder. + * + *

config: + */ + @CanIgnoreReturnValue + public Builder config(UpdateMemoryBankConfig.Builder configBuilder) { + return config(configBuilder.build()); + } + + @ExcludeFromGeneratedCoverageReport + abstract Builder config(Optional config); + + /** Clears the value of config field. */ + @ExcludeFromGeneratedCoverageReport + @CanIgnoreReturnValue + public Builder clearConfig() { + return config(Optional.empty()); + } + + public abstract UpdateMemoryBankRequestParameters build(); + } + + /** Deserializes a JSON string to a UpdateMemoryBankRequestParameters object. */ + @ExcludeFromGeneratedCoverageReport + public static UpdateMemoryBankRequestParameters fromJson(String jsonString) { + return JsonSerializable.fromJsonString(jsonString, UpdateMemoryBankRequestParameters.class); + } +}