From 37c18a9950640bf7526eb84d818abd25c014f7da Mon Sep 17 00:00:00 2001 From: Google Team Member Date: Mon, 30 Mar 2026 14:42:06 -0700 Subject: [PATCH] feat: Add custom session id functionality to vertex ai session service PiperOrigin-RevId: 891919371 --- .../google/cloud/vertexai/genai/Sessions.java | 14 +++++++++ .../types/CreateAgentEngineSessionConfig.java | 30 +++++++++++++++++++ .../types/UpdateAgentEngineSessionConfig.java | 30 +++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/genai/Sessions.java b/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/genai/Sessions.java index 15f555a..0af5408 100644 --- a/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/genai/Sessions.java +++ b/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/genai/Sessions.java @@ -96,6 +96,13 @@ ObjectNode createAgentEngineSessionConfigToVertex(JsonNode fromObject, ObjectNod Common.getValueByPath(fromObject, new String[] {"labels"})); } + if (Common.getValueByPath(fromObject, new String[] {"sessionId"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"_query", "sessionId"}, + Common.getValueByPath(fromObject, new String[] {"sessionId"})); + } + return toObject; } @@ -259,6 +266,13 @@ ObjectNode updateAgentEngineSessionConfigToVertex(JsonNode fromObject, ObjectNod Common.getValueByPath(fromObject, new String[] {"labels"})); } + if (Common.getValueByPath(fromObject, new String[] {"sessionId"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"_query", "sessionId"}, + Common.getValueByPath(fromObject, new String[] {"sessionId"})); + } + if (Common.getValueByPath(fromObject, new String[] {"updateMask"}) != null) { Common.setValueByPath( parentObject, diff --git a/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/genai/types/CreateAgentEngineSessionConfig.java b/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/genai/types/CreateAgentEngineSessionConfig.java index 31fc0a1..15cfffc 100644 --- a/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/genai/types/CreateAgentEngineSessionConfig.java +++ b/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/genai/types/CreateAgentEngineSessionConfig.java @@ -74,6 +74,15 @@ public abstract class CreateAgentEngineSessionConfig extends JsonSerializable { @JsonProperty("labels") public abstract Optional> labels(); + /** + * Optional. The user defined ID to use for session, which will become the final component of the + * session resource name. If not provided, Vertex AI will generate a value for this ID. This value + * may be up to 63 characters, and valid characters are `[a-z0-9-]`. The first character must be a + * letter, and the last character must be a letter or number. + */ + @JsonProperty("sessionId") + public abstract Optional sessionId(); + /** Instantiates a builder for CreateAgentEngineSessionConfig. */ @ExcludeFromGeneratedCoverageReport public static Builder builder() { @@ -226,6 +235,27 @@ public Builder clearLabels() { return labels(Optional.empty()); } + /** + * Setter for sessionId. + * + *

sessionId: Optional. The user defined ID to use for session, which will become the final + * component of the session resource name. If not provided, Vertex AI will generate a value for + * this ID. This value may be up to 63 characters, and valid characters are `[a-z0-9-]`. The + * first character must be a letter, and the last character must be a letter or number. + */ + @JsonProperty("sessionId") + public abstract Builder sessionId(String sessionId); + + @ExcludeFromGeneratedCoverageReport + abstract Builder sessionId(Optional sessionId); + + /** Clears the value of sessionId field. */ + @ExcludeFromGeneratedCoverageReport + @CanIgnoreReturnValue + public Builder clearSessionId() { + return sessionId(Optional.empty()); + } + public abstract CreateAgentEngineSessionConfig build(); } diff --git a/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/genai/types/UpdateAgentEngineSessionConfig.java b/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/genai/types/UpdateAgentEngineSessionConfig.java index 8da2e24..135dd00 100644 --- a/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/genai/types/UpdateAgentEngineSessionConfig.java +++ b/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/genai/types/UpdateAgentEngineSessionConfig.java @@ -74,6 +74,15 @@ public abstract class UpdateAgentEngineSessionConfig extends JsonSerializable { @JsonProperty("labels") public abstract Optional> labels(); + /** + * Optional. The user defined ID to use for session, which will become the final component of the + * session resource name. If not provided, Vertex AI will generate a value for this ID. This value + * may be up to 63 characters, and valid characters are `[a-z0-9-]`. The first character must be a + * letter, and the last character must be a letter or number. + */ + @JsonProperty("sessionId") + public abstract Optional sessionId(); + /** * The update mask to apply. For the `FieldMask` definition, see * https://protobuf.dev/reference/protobuf/google.protobuf/#field-mask. @@ -237,6 +246,27 @@ public Builder clearLabels() { return labels(Optional.empty()); } + /** + * Setter for sessionId. + * + *

sessionId: Optional. The user defined ID to use for session, which will become the final + * component of the session resource name. If not provided, Vertex AI will generate a value for + * this ID. This value may be up to 63 characters, and valid characters are `[a-z0-9-]`. The + * first character must be a letter, and the last character must be a letter or number. + */ + @JsonProperty("sessionId") + public abstract Builder sessionId(String sessionId); + + @ExcludeFromGeneratedCoverageReport + abstract Builder sessionId(Optional sessionId); + + /** Clears the value of sessionId field. */ + @ExcludeFromGeneratedCoverageReport + @CanIgnoreReturnValue + public Builder clearSessionId() { + return sessionId(Optional.empty()); + } + /** * Setter for updateMask. *