Skip to content
Open
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
48 changes: 23 additions & 25 deletions core/src/main/java/com/google/adk/agents/InvocationContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ public class InvocationContext {
private final BaseArtifactService artifactService;
private final BaseMemoryService memoryService;
private final Plugin pluginManager;
private final Optional<LiveRequestQueue> liveRequestQueue;
@Nullable private final LiveRequestQueue liveRequestQueue;
private final Map<String, ActiveStreamingTool> activeStreamingTools;
private final String invocationId;
private final Session session;
private final Optional<Content> userContent;
@Nullable private final Content userContent;
private final RunConfig runConfig;
@Nullable private final EventsCompactionConfig eventsCompactionConfig;
@Nullable private final ContextCacheConfig contextCacheConfig;
private final InvocationCostManager invocationCostManager;
private final Map<String, Object> callbackContextData;

private Optional<String> branch;
@Nullable private String branch;
private BaseAgent agent;
private boolean endInvocation;

Expand Down Expand Up @@ -153,10 +153,10 @@ public InvocationContext(
+ ".invocationId(invocationId)"
+ ".agent(agent)"
+ ".session(session)"
+ ".userContent(Optional.ofNullable(userContent))"
+ ".userContent(userContent)"
+ ".runConfig(runConfig)"
+ ".build()",
imports = {"com.google.adk.agents.InvocationContext", "java.util.Optional"})
imports = {"com.google.adk.agents.InvocationContext"})
@Deprecated(forRemoval = true)
public static InvocationContext create(
BaseSessionService sessionService,
Expand All @@ -172,7 +172,7 @@ public static InvocationContext create(
.invocationId(invocationId)
.agent(agent)
.session(session)
.userContent(Optional.ofNullable(userContent))
.userContent(userContent)
.runConfig(runConfig)
.build();
}
Expand Down Expand Up @@ -245,7 +245,7 @@ public Map<String, ActiveStreamingTool> activeStreamingTools() {

/** Returns the queue for managing live requests, if available for this invocation. */
public Optional<LiveRequestQueue> liveRequestQueue() {
return liveRequestQueue;
return Optional.ofNullable(liveRequestQueue);
}

/** Returns the unique ID for this invocation. */
Expand All @@ -258,15 +258,15 @@ public String invocationId() {
* history.
*/
public void branch(@Nullable String branch) {
this.branch = Optional.ofNullable(branch);
this.branch = branch;
}

/**
* Returns the branch ID for the current invocation, if one is set. A branch represents a fork in
* the conversation history.
*/
public Optional<String> branch() {
return branch;
return Optional.ofNullable(branch);
}

/** Returns the agent being invoked. */
Expand All @@ -291,7 +291,7 @@ public Session session() {

/** Returns the user content that triggered this invocation, if any. */
public Optional<Content> userContent() {
return userContent;
return Optional.ofNullable(userContent);
}

/** Returns the configuration for the current agent run. */
Expand Down Expand Up @@ -416,13 +416,13 @@ private Builder(InvocationContext context) {
private BaseArtifactService artifactService;
private BaseMemoryService memoryService;
private Plugin pluginManager = new PluginManager();
private Optional<LiveRequestQueue> liveRequestQueue = Optional.empty();
@Nullable private LiveRequestQueue liveRequestQueue = null;
private Map<String, ActiveStreamingTool> activeStreamingTools = new ConcurrentHashMap<>();
private Optional<String> branch = Optional.empty();
@Nullable private String branch = null;
private String invocationId = newInvocationContextId();
private BaseAgent agent;
private Session session;
private Optional<Content> userContent = Optional.empty();
@Nullable private Content userContent = null;
private RunConfig runConfig = RunConfig.builder().build();
private boolean endInvocation = false;
@Nullable private EventsCompactionConfig eventsCompactionConfig;
Expand Down Expand Up @@ -489,7 +489,7 @@ public Builder pluginManager(Plugin pluginManager) {
@Deprecated(forRemoval = true)
@CanIgnoreReturnValue
public Builder liveRequestQueue(Optional<LiveRequestQueue> liveRequestQueue) {
this.liveRequestQueue = liveRequestQueue;
this.liveRequestQueue = liveRequestQueue.orElse(null);
return this;
}

Expand All @@ -501,7 +501,7 @@ public Builder liveRequestQueue(Optional<LiveRequestQueue> liveRequestQueue) {
*/
@CanIgnoreReturnValue
public Builder liveRequestQueue(@Nullable LiveRequestQueue liveRequestQueue) {
this.liveRequestQueue = Optional.ofNullable(liveRequestQueue);
this.liveRequestQueue = liveRequestQueue;
return this;
}

Expand All @@ -516,7 +516,7 @@ public Builder liveRequestQueue(@Nullable LiveRequestQueue liveRequestQueue) {
@Deprecated(forRemoval = true)
@CanIgnoreReturnValue
public Builder branch(Optional<String> branch) {
this.branch = branch;
this.branch = branch.orElse(null);
return this;
}

Expand All @@ -527,8 +527,8 @@ public Builder branch(Optional<String> branch) {
* @return this builder instance for chaining.
*/
@CanIgnoreReturnValue
public Builder branch(String branch) {
this.branch = Optional.of(branch);
public Builder branch(@Nullable String branch) {
this.branch = branch;
return this;
}

Expand Down Expand Up @@ -569,14 +569,12 @@ public Builder session(Session session) {
}

/**
* Sets the user content that triggered this invocation.
*
* @param userContent the user content that triggered this invocation.
* @return this builder instance for chaining.
* @deprecated Use {@link #userContent(Content)} instead.
*/
@CanIgnoreReturnValue
@Deprecated
public Builder userContent(Optional<Content> userContent) {
this.userContent = userContent;
this.userContent = userContent.orElse(null);
return this;
}

Expand All @@ -587,8 +585,8 @@ public Builder userContent(Optional<Content> userContent) {
* @return this builder instance for chaining.
*/
@CanIgnoreReturnValue
public Builder userContent(Content userContent) {
this.userContent = Optional.of(userContent);
public Builder userContent(@Nullable Content userContent) {
this.userContent = userContent;
return this;
}

Expand Down