Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 28 additions & 56 deletions core/src/main/java/com/google/adk/events/EventActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,32 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.annotation.Nullable;
import org.jspecify.annotations.Nullable;

/** Represents the actions attached to an event. */
// TODO - b/414081262 make json wire camelCase
@JsonDeserialize(builder = EventActions.Builder.class)
public class EventActions extends JsonBaseModel {

private Optional<Boolean> skipSummarization;
private @Nullable Boolean skipSummarization;
private ConcurrentMap<String, Object> stateDelta;
private ConcurrentMap<String, Integer> artifactDelta;
private Set<String> deletedArtifactIds;
private Optional<String> transferToAgent;
private Optional<Boolean> escalate;
private @Nullable String transferToAgent;
private @Nullable Boolean escalate;
private ConcurrentMap<String, ConcurrentMap<String, Object>> requestedAuthConfigs;
private ConcurrentMap<String, ToolConfirmation> requestedToolConfirmations;
private boolean endOfAgent;
private Optional<EventCompaction> compaction;
private @Nullable EventCompaction compaction;

/** Default constructor for Jackson. */
public EventActions() {
this.skipSummarization = Optional.empty();
this.stateDelta = new ConcurrentHashMap<>();
this.artifactDelta = new ConcurrentHashMap<>();
this.deletedArtifactIds = new HashSet<>();
this.transferToAgent = Optional.empty();
this.escalate = Optional.empty();
this.requestedAuthConfigs = new ConcurrentHashMap<>();
this.requestedToolConfirmations = new ConcurrentHashMap<>();
this.endOfAgent = false;
this.compaction = Optional.empty();
}

private EventActions(Builder builder) {
Expand All @@ -75,19 +71,15 @@ private EventActions(Builder builder) {

@JsonProperty("skipSummarization")
public Optional<Boolean> skipSummarization() {
return skipSummarization;
return Optional.ofNullable(skipSummarization);
}

public void setSkipSummarization(@Nullable Boolean skipSummarization) {
this.skipSummarization = Optional.ofNullable(skipSummarization);
}

public void setSkipSummarization(Optional<Boolean> skipSummarization) {
this.skipSummarization = skipSummarization;
}

public void setSkipSummarization(boolean skipSummarization) {
this.skipSummarization = Optional.of(skipSummarization);
this.skipSummarization = skipSummarization;
}

@JsonProperty("stateDelta")
Expand Down Expand Up @@ -130,30 +122,22 @@ public void setDeletedArtifactIds(Set<String> deletedArtifactIds) {

@JsonProperty("transferToAgent")
public Optional<String> transferToAgent() {
return transferToAgent;
return Optional.ofNullable(transferToAgent);
}

public void setTransferToAgent(Optional<String> transferToAgent) {
public void setTransferToAgent(@Nullable String transferToAgent) {
this.transferToAgent = transferToAgent;
}

public void setTransferToAgent(String transferToAgent) {
this.transferToAgent = Optional.ofNullable(transferToAgent);
}

@JsonProperty("escalate")
public Optional<Boolean> escalate() {
return escalate;
return Optional.ofNullable(escalate);
}

public void setEscalate(Optional<Boolean> escalate) {
public void setEscalate(@Nullable Boolean escalate) {
this.escalate = escalate;
}

public void setEscalate(boolean escalate) {
this.escalate = Optional.of(escalate);
}

@JsonProperty("requestedAuthConfigs")
public ConcurrentMap<String, ConcurrentMap<String, Object>> requestedAuthConfigs() {
return requestedAuthConfigs;
Expand Down Expand Up @@ -199,14 +183,6 @@ public Optional<Boolean> endInvocation() {
return endOfAgent ? Optional.of(true) : Optional.empty();
}

/**
* @deprecated Use {@link #setEndOfAgent(boolean)} instead.
*/
@Deprecated
public void setEndInvocation(Optional<Boolean> endInvocation) {
this.endOfAgent = endInvocation.orElse(false);
}

/**
* @deprecated Use {@link #setEndOfAgent(boolean)} instead.
*/
Expand All @@ -217,10 +193,10 @@ public void setEndInvocation(boolean endInvocation) {

@JsonProperty("compaction")
public Optional<EventCompaction> compaction() {
return compaction;
return Optional.ofNullable(compaction);
}

public void setCompaction(Optional<EventCompaction> compaction) {
public void setCompaction(@Nullable EventCompaction compaction) {
this.compaction = compaction;
}

Expand Down Expand Up @@ -269,47 +245,43 @@ public int hashCode() {

/** Builder for {@link EventActions}. */
public static class Builder {
private Optional<Boolean> skipSummarization;
private @Nullable Boolean skipSummarization;
private ConcurrentMap<String, Object> stateDelta;
private ConcurrentMap<String, Integer> artifactDelta;
private Set<String> deletedArtifactIds;
private Optional<String> transferToAgent;
private Optional<Boolean> escalate;
private @Nullable String transferToAgent;
private @Nullable Boolean escalate;
private ConcurrentMap<String, ConcurrentMap<String, Object>> requestedAuthConfigs;
private ConcurrentMap<String, ToolConfirmation> requestedToolConfirmations;
private boolean endOfAgent = false;
private Optional<EventCompaction> compaction;
private @Nullable EventCompaction compaction;

public Builder() {
this.skipSummarization = Optional.empty();
this.stateDelta = new ConcurrentHashMap<>();
this.artifactDelta = new ConcurrentHashMap<>();
this.deletedArtifactIds = new HashSet<>();
this.transferToAgent = Optional.empty();
this.escalate = Optional.empty();
this.requestedAuthConfigs = new ConcurrentHashMap<>();
this.requestedToolConfirmations = new ConcurrentHashMap<>();
this.compaction = Optional.empty();
}

private Builder(EventActions eventActions) {
this.skipSummarization = eventActions.skipSummarization();
this.skipSummarization = eventActions.skipSummarization;
this.stateDelta = new ConcurrentHashMap<>(eventActions.stateDelta());
this.artifactDelta = new ConcurrentHashMap<>(eventActions.artifactDelta());
this.deletedArtifactIds = new HashSet<>(eventActions.deletedArtifactIds());
this.transferToAgent = eventActions.transferToAgent();
this.escalate = eventActions.escalate();
this.transferToAgent = eventActions.transferToAgent;
this.escalate = eventActions.escalate;
this.requestedAuthConfigs = new ConcurrentHashMap<>(eventActions.requestedAuthConfigs());
this.requestedToolConfirmations =
new ConcurrentHashMap<>(eventActions.requestedToolConfirmations());
this.endOfAgent = eventActions.endOfAgent();
this.compaction = eventActions.compaction();
this.endOfAgent = eventActions.endOfAgent;
this.compaction = eventActions.compaction;
}

@CanIgnoreReturnValue
@JsonProperty("skipSummarization")
public Builder skipSummarization(boolean skipSummarization) {
this.skipSummarization = Optional.of(skipSummarization);
this.skipSummarization = skipSummarization;
return this;
}

Expand All @@ -336,15 +308,15 @@ public Builder deletedArtifactIds(Set<String> value) {

@CanIgnoreReturnValue
@JsonProperty("transferToAgent")
public Builder transferToAgent(String agentId) {
this.transferToAgent = Optional.ofNullable(agentId);
public Builder transferToAgent(@Nullable String agentId) {
this.transferToAgent = agentId;
return this;
}

@CanIgnoreReturnValue
@JsonProperty("escalate")
public Builder escalate(boolean escalate) {
this.escalate = Optional.of(escalate);
this.escalate = escalate;
return this;
}

Expand Down Expand Up @@ -391,8 +363,8 @@ public Builder endInvocation(boolean endInvocation) {

@CanIgnoreReturnValue
@JsonProperty("compaction")
public Builder compaction(EventCompaction value) {
this.compaction = Optional.ofNullable(value);
public Builder compaction(@Nullable EventCompaction value) {
this.compaction = value;
return this;
}

Expand Down