Skip to content

Commit 882ea5f

Browse files
Merge pull request #1376 from svetanis:fix/eventactions-endofagent-merge
PiperOrigin-RevId: 953232777
2 parents 24a4588 + 03b04fa commit 882ea5f

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ public Builder merge(EventActions other) {
393393
other.escalate().ifPresent(this::escalate);
394394
this.requestedAuthConfigs.putAll(other.requestedAuthConfigs());
395395
this.requestedToolConfirmations.putAll(other.requestedToolConfirmations());
396-
this.endOfAgent = other.endOfAgent();
396+
this.endOfAgent = this.endOfAgent || other.endOfAgent();
397397
other.compaction().ifPresent(this::compaction);
398398
return this;
399399
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@ public void merge_mergesAllFields() {
111111
assertThat(merged.compaction()).hasValue(COMPACTION);
112112
}
113113

114+
@Test
115+
public void merge_endOfAgentIsOrderIndependent() {
116+
// A tool that ends the invocation, and one that leaves the flag at its default false. Folding
117+
// parallel tool responses must keep endOfAgent set whichever order they are merged in.
118+
EventActions requestsStop = EventActions.builder().endOfAgent(true).build();
119+
EventActions leavesUnset = EventActions.builder().build();
120+
121+
EventActions stopFirst = EventActions.builder().merge(requestsStop).merge(leavesUnset).build();
122+
EventActions stopLast = EventActions.builder().merge(leavesUnset).merge(requestsStop).build();
123+
124+
assertThat(stopFirst.endOfAgent()).isTrue();
125+
assertThat(stopLast.endOfAgent()).isTrue();
126+
}
127+
114128
@Test
115129
public void setArtifactDelta_copiesRegularMap() {
116130
EventActions eventActions = new EventActions();

0 commit comments

Comments
 (0)