Skip to content

Commit d5e8a32

Browse files
Annhiluccopybara-github
authored andcommitted
feat: Add types to support continuous sessions with a sliding window
PiperOrigin-RevId: 745348707
1 parent be93305 commit d5e8a32

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Auto-generated code. Do not edit.
18+
19+
package com.google.genai.types;
20+
21+
import com.fasterxml.jackson.annotation.JsonCreator;
22+
import com.fasterxml.jackson.annotation.JsonProperty;
23+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
24+
import com.google.auto.value.AutoValue;
25+
import com.google.genai.JsonSerializable;
26+
import java.util.Optional;
27+
28+
/**
29+
* Enables context window compression -- mechanism managing model context window so it does not
30+
* exceed given length.
31+
*/
32+
@AutoValue
33+
@JsonDeserialize(builder = ContextWindowCompressionConfig.Builder.class)
34+
public abstract class ContextWindowCompressionConfig extends JsonSerializable {
35+
/** Number of tokens (before running turn) that triggers context window compression mechanism. */
36+
@JsonProperty("triggerTokens")
37+
public abstract Optional<Long> triggerTokens();
38+
39+
/** Sliding window compression mechanism. */
40+
@JsonProperty("slidingWindow")
41+
public abstract Optional<SlidingWindow> slidingWindow();
42+
43+
/** Instantiates a builder for ContextWindowCompressionConfig. */
44+
public static Builder builder() {
45+
return new AutoValue_ContextWindowCompressionConfig.Builder();
46+
}
47+
48+
/** Creates a builder with the same values as this instance. */
49+
public abstract Builder toBuilder();
50+
51+
/** Builder for ContextWindowCompressionConfig. */
52+
@AutoValue.Builder
53+
public abstract static class Builder {
54+
/**
55+
* For internal usage. Please use `ContextWindowCompressionConfig.builder()` for instantiation.
56+
*/
57+
@JsonCreator
58+
private static Builder create() {
59+
return new AutoValue_ContextWindowCompressionConfig.Builder();
60+
}
61+
62+
@JsonProperty("triggerTokens")
63+
public abstract Builder triggerTokens(Long triggerTokens);
64+
65+
@JsonProperty("slidingWindow")
66+
public abstract Builder slidingWindow(SlidingWindow slidingWindow);
67+
68+
public abstract ContextWindowCompressionConfig build();
69+
}
70+
71+
/** Deserializes a JSON string to a ContextWindowCompressionConfig object. */
72+
public static ContextWindowCompressionConfig fromJson(String jsonString) {
73+
return JsonSerializable.fromJsonString(jsonString, ContextWindowCompressionConfig.class);
74+
}
75+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Auto-generated code. Do not edit.
18+
19+
package com.google.genai.types;
20+
21+
import com.fasterxml.jackson.annotation.JsonCreator;
22+
import com.fasterxml.jackson.annotation.JsonProperty;
23+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
24+
import com.google.auto.value.AutoValue;
25+
import com.google.genai.JsonSerializable;
26+
import java.util.Optional;
27+
28+
/**
29+
* Context window will be truncated by keeping only suffix of it.
30+
*
31+
* <p>Context window will always be cut at start of USER role turn. System instructions and
32+
* `BidiGenerateContentSetup.prefix_turns` will not be subject to the sliding window mechanism, they
33+
* will always stay at the beginning of context window.
34+
*/
35+
@AutoValue
36+
@JsonDeserialize(builder = SlidingWindow.Builder.class)
37+
public abstract class SlidingWindow extends JsonSerializable {
38+
/**
39+
* Session reduction target -- how many tokens we should keep. Window shortening operation has
40+
* some latency costs, so we should avoid running it on every turn. Should be < trigger_tokens. If
41+
* not set, trigger_tokens/2 is assumed.
42+
*/
43+
@JsonProperty("targetTokens")
44+
public abstract Optional<Long> targetTokens();
45+
46+
/** Instantiates a builder for SlidingWindow. */
47+
public static Builder builder() {
48+
return new AutoValue_SlidingWindow.Builder();
49+
}
50+
51+
/** Creates a builder with the same values as this instance. */
52+
public abstract Builder toBuilder();
53+
54+
/** Builder for SlidingWindow. */
55+
@AutoValue.Builder
56+
public abstract static class Builder {
57+
/** For internal usage. Please use `SlidingWindow.builder()` for instantiation. */
58+
@JsonCreator
59+
private static Builder create() {
60+
return new AutoValue_SlidingWindow.Builder();
61+
}
62+
63+
@JsonProperty("targetTokens")
64+
public abstract Builder targetTokens(Long targetTokens);
65+
66+
public abstract SlidingWindow build();
67+
}
68+
69+
/** Deserializes a JSON string to a SlidingWindow object. */
70+
public static SlidingWindow fromJson(String jsonString) {
71+
return JsonSerializable.fromJsonString(jsonString, SlidingWindow.class);
72+
}
73+
}

0 commit comments

Comments
 (0)