Skip to content

Commit 37c18a9

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: Add custom session id functionality to vertex ai session service
PiperOrigin-RevId: 891919371
1 parent 6204b7d commit 37c18a9

3 files changed

Lines changed: 74 additions & 0 deletions

File tree

google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/genai/Sessions.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ ObjectNode createAgentEngineSessionConfigToVertex(JsonNode fromObject, ObjectNod
9696
Common.getValueByPath(fromObject, new String[] {"labels"}));
9797
}
9898

99+
if (Common.getValueByPath(fromObject, new String[] {"sessionId"}) != null) {
100+
Common.setValueByPath(
101+
parentObject,
102+
new String[] {"_query", "sessionId"},
103+
Common.getValueByPath(fromObject, new String[] {"sessionId"}));
104+
}
105+
99106
return toObject;
100107
}
101108

@@ -259,6 +266,13 @@ ObjectNode updateAgentEngineSessionConfigToVertex(JsonNode fromObject, ObjectNod
259266
Common.getValueByPath(fromObject, new String[] {"labels"}));
260267
}
261268

269+
if (Common.getValueByPath(fromObject, new String[] {"sessionId"}) != null) {
270+
Common.setValueByPath(
271+
parentObject,
272+
new String[] {"_query", "sessionId"},
273+
Common.getValueByPath(fromObject, new String[] {"sessionId"}));
274+
}
275+
262276
if (Common.getValueByPath(fromObject, new String[] {"updateMask"}) != null) {
263277
Common.setValueByPath(
264278
parentObject,

google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/genai/types/CreateAgentEngineSessionConfig.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ public abstract class CreateAgentEngineSessionConfig extends JsonSerializable {
7474
@JsonProperty("labels")
7575
public abstract Optional<Map<String, String>> labels();
7676

77+
/**
78+
* Optional. The user defined ID to use for session, which will become the final component of the
79+
* session resource name. If not provided, Vertex AI will generate a value for this ID. This value
80+
* may be up to 63 characters, and valid characters are `[a-z0-9-]`. The first character must be a
81+
* letter, and the last character must be a letter or number.
82+
*/
83+
@JsonProperty("sessionId")
84+
public abstract Optional<String> sessionId();
85+
7786
/** Instantiates a builder for CreateAgentEngineSessionConfig. */
7887
@ExcludeFromGeneratedCoverageReport
7988
public static Builder builder() {
@@ -226,6 +235,27 @@ public Builder clearLabels() {
226235
return labels(Optional.empty());
227236
}
228237

238+
/**
239+
* Setter for sessionId.
240+
*
241+
* <p>sessionId: Optional. The user defined ID to use for session, which will become the final
242+
* component of the session resource name. If not provided, Vertex AI will generate a value for
243+
* this ID. This value may be up to 63 characters, and valid characters are `[a-z0-9-]`. The
244+
* first character must be a letter, and the last character must be a letter or number.
245+
*/
246+
@JsonProperty("sessionId")
247+
public abstract Builder sessionId(String sessionId);
248+
249+
@ExcludeFromGeneratedCoverageReport
250+
abstract Builder sessionId(Optional<String> sessionId);
251+
252+
/** Clears the value of sessionId field. */
253+
@ExcludeFromGeneratedCoverageReport
254+
@CanIgnoreReturnValue
255+
public Builder clearSessionId() {
256+
return sessionId(Optional.empty());
257+
}
258+
229259
public abstract CreateAgentEngineSessionConfig build();
230260
}
231261

google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/genai/types/UpdateAgentEngineSessionConfig.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ public abstract class UpdateAgentEngineSessionConfig extends JsonSerializable {
7474
@JsonProperty("labels")
7575
public abstract Optional<Map<String, String>> labels();
7676

77+
/**
78+
* Optional. The user defined ID to use for session, which will become the final component of the
79+
* session resource name. If not provided, Vertex AI will generate a value for this ID. This value
80+
* may be up to 63 characters, and valid characters are `[a-z0-9-]`. The first character must be a
81+
* letter, and the last character must be a letter or number.
82+
*/
83+
@JsonProperty("sessionId")
84+
public abstract Optional<String> sessionId();
85+
7786
/**
7887
* The update mask to apply. For the `FieldMask` definition, see
7988
* https://protobuf.dev/reference/protobuf/google.protobuf/#field-mask.
@@ -237,6 +246,27 @@ public Builder clearLabels() {
237246
return labels(Optional.empty());
238247
}
239248

249+
/**
250+
* Setter for sessionId.
251+
*
252+
* <p>sessionId: Optional. The user defined ID to use for session, which will become the final
253+
* component of the session resource name. If not provided, Vertex AI will generate a value for
254+
* this ID. This value may be up to 63 characters, and valid characters are `[a-z0-9-]`. The
255+
* first character must be a letter, and the last character must be a letter or number.
256+
*/
257+
@JsonProperty("sessionId")
258+
public abstract Builder sessionId(String sessionId);
259+
260+
@ExcludeFromGeneratedCoverageReport
261+
abstract Builder sessionId(Optional<String> sessionId);
262+
263+
/** Clears the value of sessionId field. */
264+
@ExcludeFromGeneratedCoverageReport
265+
@CanIgnoreReturnValue
266+
public Builder clearSessionId() {
267+
return sessionId(Optional.empty());
268+
}
269+
240270
/**
241271
* Setter for updateMask.
242272
*

0 commit comments

Comments
 (0)