Skip to content

Commit d011f43

Browse files
damianmomotgooglecopybara-github
authored andcommitted
feat: add Event.isolationScope
PiperOrigin-RevId: 1007156358
1 parent 84bae34 commit d011f43

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

‎core/src/main/java/com/google/adk/events/Event.java‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class Event extends JsonBaseModel {
6464
private @Nullable Double avgLogprobs;
6565
private @Nullable Boolean interrupted;
6666
private @Nullable String branch;
67+
private @Nullable String isolationScope;
6768
private @Nullable GroundingMetadata groundingMetadata;
6869
private @Nullable List<CustomMetadata> customMetadata;
6970
private @Nullable String modelVersion;
@@ -256,6 +257,22 @@ public void branch(@Nullable String branch) {
256257
this.branch = branch;
257258
}
258259

260+
/**
261+
* Returns the isolated conversation this event belongs to, such as a delegated task, so an
262+
* agent's model history can keep only events from its own scope. Returns empty when the event is
263+
* not scoped. This field is internal to the framework and may change without notice.
264+
*/
265+
@Experimental
266+
@JsonProperty("isolationScope")
267+
public Optional<String> isolationScope() {
268+
return Optional.ofNullable(isolationScope);
269+
}
270+
271+
@Experimental
272+
public void setIsolationScope(@Nullable String isolationScope) {
273+
this.isolationScope = isolationScope;
274+
}
275+
259276
/** The grounding metadata of the event. */
260277
@JsonProperty("groundingMetadata")
261278
public Optional<GroundingMetadata> groundingMetadata() {
@@ -480,6 +497,7 @@ public static class Builder {
480497
private @Nullable Double avgLogprobs;
481498
private @Nullable Boolean interrupted;
482499
private @Nullable String branch;
500+
private @Nullable String isolationScope;
483501
private @Nullable GroundingMetadata groundingMetadata;
484502
private @Nullable List<CustomMetadata> customMetadata;
485503
private @Nullable String modelVersion;
@@ -626,6 +644,14 @@ Optional<String> branch() {
626644
return Optional.ofNullable(branch);
627645
}
628646

647+
@Experimental
648+
@CanIgnoreReturnValue
649+
@JsonProperty("isolationScope")
650+
public Builder isolationScope(@Nullable String value) {
651+
this.isolationScope = value;
652+
return this;
653+
}
654+
629655
@CanIgnoreReturnValue
630656
@JsonProperty("groundingMetadata")
631657
public Builder groundingMetadata(@Nullable GroundingMetadata value) {
@@ -704,6 +730,7 @@ public Event build() {
704730
event.setAvgLogprobs(avgLogprobs);
705731
event.setInterrupted(interrupted);
706732
event.branch(branch);
733+
event.setIsolationScope(isolationScope);
707734
event.setGroundingMetadata(groundingMetadata);
708735
event.setCustomMetadata(customMetadata);
709736
event.setModelVersion(modelVersion);
@@ -746,6 +773,7 @@ public Builder toBuilder() {
746773
.avgLogprobs(this.avgLogprobs)
747774
.interrupted(this.interrupted)
748775
.branch(this.branch)
776+
.isolationScope(this.isolationScope)
749777
.groundingMetadata(this.groundingMetadata)
750778
.customMetadata(this.customMetadata)
751779
.modelVersion(this.modelVersion)
@@ -781,6 +809,7 @@ public boolean equals(Object obj) {
781809
&& Objects.equals(avgLogprobs, other.avgLogprobs)
782810
&& Objects.equals(interrupted, other.interrupted)
783811
&& Objects.equals(branch, other.branch)
812+
&& Objects.equals(isolationScope, other.isolationScope)
784813
&& Objects.equals(groundingMetadata, other.groundingMetadata)
785814
&& Objects.equals(customMetadata, other.customMetadata)
786815
&& Objects.equals(modelVersion, other.modelVersion)
@@ -814,6 +843,7 @@ public int hashCode() {
814843
avgLogprobs,
815844
interrupted,
816845
branch,
846+
isolationScope,
817847
groundingMetadata,
818848
customMetadata,
819849
modelVersion,

‎core/src/test/java/com/google/adk/events/EventTest.java‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,31 @@ public void event_cacheMetadata_emptyByDefault() {
407407
assertThat(EVENT.toJson()).doesNotContain("cacheMetadata");
408408
}
409409

410+
@Test
411+
public void event_isolationScope_survivesJsonAndToBuilder() {
412+
Event event = EVENT.toBuilder().isolationScope("wf@1/task@1").build();
413+
414+
assertThat(event.isolationScope()).hasValue("wf@1/task@1");
415+
assertThat(event.toBuilder().build()).isEqualTo(event);
416+
assertThat(Event.fromJson(event.toJson())).isEqualTo(event);
417+
assertThat(event).isNotEqualTo(EVENT);
418+
assertThat(event.hashCode()).isNotEqualTo(EVENT.hashCode());
419+
}
420+
421+
@Test
422+
public void event_isolationScope_emptyByDefault() {
423+
assertThat(EVENT.isolationScope()).isEmpty();
424+
assertThat(EVENT.toJson()).doesNotContain("isolationScope");
425+
}
426+
427+
@Test
428+
public void fromJson_readsIsolationScope() {
429+
Event event =
430+
Event.fromJson("{\"id\":\"event_id\",\"author\":\"agent\",\"isolationScope\":\"fc-1\"}");
431+
432+
assertThat(event.isolationScope()).hasValue("fc-1");
433+
}
434+
410435
@Test
411436
public void finalResponse_returnsTrueIfNoToolCalls() {
412437
Event event =

0 commit comments

Comments
 (0)