Skip to content

Commit b89f2eb

Browse files
google-genai-botcopybara-github
authored andcommitted
refactor: Removing fields that were intended for a future feature
The ADK Python code has pause/resume/rewind functionality. It's going to be some time before ADK Java gets it. For now, it's worth cleaning up the half-baked feature. PiperOrigin-RevId: 869384320
1 parent 8b887fd commit b89f2eb

8 files changed

Lines changed: 11 additions & 590 deletions

File tree

core/src/main/java/com/google/adk/agents/BaseAgentState.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

core/src/main/java/com/google/adk/agents/InvocationContext.java

Lines changed: 2 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,17 @@
1818

1919
import static com.google.common.base.Strings.isNullOrEmpty;
2020

21-
import com.google.adk.apps.ResumabilityConfig;
2221
import com.google.adk.artifacts.BaseArtifactService;
23-
import com.google.adk.events.Event;
2422
import com.google.adk.memory.BaseMemoryService;
2523
import com.google.adk.models.LlmCallsLimitExceededException;
2624
import com.google.adk.plugins.Plugin;
2725
import com.google.adk.plugins.PluginManager;
2826
import com.google.adk.sessions.BaseSessionService;
2927
import com.google.adk.sessions.Session;
3028
import com.google.adk.summarizer.EventsCompactionConfig;
31-
import com.google.common.collect.ImmutableSet;
3229
import com.google.errorprone.annotations.CanIgnoreReturnValue;
3330
import com.google.errorprone.annotations.InlineMe;
3431
import com.google.genai.types.Content;
35-
import com.google.genai.types.FunctionCall;
36-
import java.util.List;
3732
import java.util.Map;
3833
import java.util.Objects;
3934
import java.util.Optional;
@@ -54,9 +49,6 @@ public class InvocationContext {
5449
private final Session session;
5550
private final Optional<Content> userContent;
5651
private final RunConfig runConfig;
57-
private final Map<String, BaseAgentState> agentStates;
58-
private final Map<String, Boolean> endOfAgents;
59-
private final ResumabilityConfig resumabilityConfig;
6052
@Nullable private final EventsCompactionConfig eventsCompactionConfig;
6153
@Nullable private final ContextCacheConfig contextCacheConfig;
6254
private final InvocationCostManager invocationCostManager;
@@ -80,13 +72,10 @@ protected InvocationContext(Builder builder) {
8072
this.userContent = builder.userContent;
8173
this.runConfig = builder.runConfig;
8274
this.endInvocation = builder.endInvocation;
83-
this.agentStates = builder.agentStates;
84-
this.endOfAgents = builder.endOfAgents;
85-
this.resumabilityConfig = builder.resumabilityConfig;
8675
this.eventsCompactionConfig = builder.eventsCompactionConfig;
8776
this.contextCacheConfig = builder.contextCacheConfig;
8877
this.invocationCostManager = builder.invocationCostManager;
89-
this.callbackContextData = builder.callbackContextData;
78+
this.callbackContextData = new ConcurrentHashMap<>(builder.callbackContextData);
9079
}
9180

9281
/**
@@ -267,10 +256,7 @@ public String invocationId() {
267256
/**
268257
* Sets the [branch] ID for the current invocation. A branch represents a fork in the conversation
269258
* history.
270-
*
271-
* @deprecated Use {@link #toBuilder()} and {@link Builder#branch(String)} instead.
272259
*/
273-
@Deprecated(forRemoval = true)
274260
public void branch(@Nullable String branch) {
275261
this.branch = Optional.ofNullable(branch);
276262
}
@@ -321,16 +307,6 @@ public Map<String, Object> callbackContextData() {
321307
return callbackContextData;
322308
}
323309

324-
/** Returns agent-specific state saved within this invocation. */
325-
public Map<String, BaseAgentState> agentStates() {
326-
return agentStates;
327-
}
328-
329-
/** Returns map of agents that ended during this invocation. */
330-
public Map<String, Boolean> endOfAgents() {
331-
return endOfAgents;
332-
}
333-
334310
/**
335311
* Returns whether this invocation should be ended, e.g., due to reaching a terminal state or
336312
* error.
@@ -369,36 +345,6 @@ public void incrementLlmCallsCount() throws LlmCallsLimitExceededException {
369345
this.invocationCostManager.incrementAndEnforceLlmCallsLimit(this.runConfig);
370346
}
371347

372-
/** Returns whether the current invocation is resumable. */
373-
public boolean isResumable() {
374-
return resumabilityConfig.isResumable();
375-
}
376-
377-
/** Returns ResumabilityConfig for this invocation. */
378-
public ResumabilityConfig resumabilityConfig() {
379-
return resumabilityConfig;
380-
}
381-
382-
/**
383-
* Populates agentStates and endOfAgents maps by reading session events for this invocation id.
384-
*/
385-
public void populateAgentStates(List<Event> events) {
386-
events.stream()
387-
.filter(event -> invocationId().equals(event.invocationId()))
388-
.forEach(
389-
event -> {
390-
if (event.actions() != null) {
391-
if (event.actions().agentState() != null
392-
&& !event.actions().agentState().isEmpty()) {
393-
agentStates.putAll(event.actions().agentState());
394-
}
395-
if (event.actions().endOfAgent()) {
396-
endOfAgents.put(event.author(), true);
397-
}
398-
}
399-
});
400-
}
401-
402348
/** Returns the events compaction configuration for the current agent run. */
403349
public Optional<EventsCompactionConfig> eventsCompactionConfig() {
404350
return Optional.ofNullable(eventsCompactionConfig);
@@ -409,23 +355,6 @@ public Optional<ContextCacheConfig> contextCacheConfig() {
409355
return Optional.ofNullable(contextCacheConfig);
410356
}
411357

412-
/** Returns whether to pause the invocation right after this [event]. */
413-
public boolean shouldPauseInvocation(Event event) {
414-
if (!isResumable()) {
415-
return false;
416-
}
417-
418-
var longRunningToolIds = event.longRunningToolIds().orElse(ImmutableSet.of());
419-
if (longRunningToolIds.isEmpty()) {
420-
return false;
421-
}
422-
423-
return event.functionCalls().stream()
424-
.map(FunctionCall::id)
425-
.flatMap(Optional::stream)
426-
.anyMatch(functionCallId -> longRunningToolIds.contains(functionCallId));
427-
}
428-
429358
private static class InvocationCostManager {
430359
private int numberOfLlmCalls = 0;
431360

@@ -477,13 +406,10 @@ private Builder(InvocationContext context) {
477406
this.userContent = context.userContent;
478407
this.runConfig = context.runConfig;
479408
this.endInvocation = context.endInvocation;
480-
this.agentStates = new ConcurrentHashMap<>(context.agentStates);
481-
this.endOfAgents = new ConcurrentHashMap<>(context.endOfAgents);
482-
this.resumabilityConfig = context.resumabilityConfig;
483409
this.eventsCompactionConfig = context.eventsCompactionConfig;
484410
this.contextCacheConfig = context.contextCacheConfig;
485411
this.invocationCostManager = context.invocationCostManager;
486-
this.callbackContextData = context.callbackContextData;
412+
this.callbackContextData = new ConcurrentHashMap<>(context.callbackContextData);
487413
}
488414

489415
private BaseSessionService sessionService;
@@ -499,9 +425,6 @@ private Builder(InvocationContext context) {
499425
private Optional<Content> userContent = Optional.empty();
500426
private RunConfig runConfig = RunConfig.builder().build();
501427
private boolean endInvocation = false;
502-
private Map<String, BaseAgentState> agentStates = new ConcurrentHashMap<>();
503-
private Map<String, Boolean> endOfAgents = new ConcurrentHashMap<>();
504-
private ResumabilityConfig resumabilityConfig = new ResumabilityConfig();
505428
@Nullable private EventsCompactionConfig eventsCompactionConfig;
506429
@Nullable private ContextCacheConfig contextCacheConfig;
507430
private InvocationCostManager invocationCostManager = new InvocationCostManager();
@@ -693,42 +616,6 @@ public Builder endInvocation(boolean endInvocation) {
693616
return this;
694617
}
695618

696-
/**
697-
* Sets agent-specific state saved within this invocation.
698-
*
699-
* @param agentStates agent-specific state saved within this invocation.
700-
* @return this builder instance for chaining.
701-
*/
702-
@CanIgnoreReturnValue
703-
public Builder agentStates(Map<String, BaseAgentState> agentStates) {
704-
this.agentStates = agentStates;
705-
return this;
706-
}
707-
708-
/**
709-
* Sets agent end-of-invocation status.
710-
*
711-
* @param endOfAgents agent end-of-invocation status.
712-
* @return this builder instance for chaining.
713-
*/
714-
@CanIgnoreReturnValue
715-
public Builder endOfAgents(Map<String, Boolean> endOfAgents) {
716-
this.endOfAgents = endOfAgents;
717-
return this;
718-
}
719-
720-
/**
721-
* Sets the resumability configuration for the current agent run.
722-
*
723-
* @param resumabilityConfig the resumability configuration.
724-
* @return this builder instance for chaining.
725-
*/
726-
@CanIgnoreReturnValue
727-
public Builder resumabilityConfig(ResumabilityConfig resumabilityConfig) {
728-
this.resumabilityConfig = resumabilityConfig;
729-
return this;
730-
}
731-
732619
/**
733620
* Sets the events compaction configuration for the current agent run.
734621
*
@@ -818,9 +705,6 @@ public boolean equals(Object o) {
818705
&& Objects.equals(session, that.session)
819706
&& Objects.equals(userContent, that.userContent)
820707
&& Objects.equals(runConfig, that.runConfig)
821-
&& Objects.equals(agentStates, that.agentStates)
822-
&& Objects.equals(endOfAgents, that.endOfAgents)
823-
&& Objects.equals(resumabilityConfig, that.resumabilityConfig)
824708
&& Objects.equals(eventsCompactionConfig, that.eventsCompactionConfig)
825709
&& Objects.equals(contextCacheConfig, that.contextCacheConfig)
826710
&& Objects.equals(invocationCostManager, that.invocationCostManager)
@@ -843,9 +727,6 @@ public int hashCode() {
843727
userContent,
844728
runConfig,
845729
endInvocation,
846-
agentStates,
847-
endOfAgents,
848-
resumabilityConfig,
849730
eventsCompactionConfig,
850731
contextCacheConfig,
851732
invocationCostManager,

core/src/main/java/com/google/adk/apps/App.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,18 @@ public class App {
4141
private final BaseAgent rootAgent;
4242
private final ImmutableList<? extends Plugin> plugins;
4343
@Nullable private final EventsCompactionConfig eventsCompactionConfig;
44-
@Nullable private final ResumabilityConfig resumabilityConfig;
4544
@Nullable private final ContextCacheConfig contextCacheConfig;
4645

4746
private App(
4847
String name,
4948
BaseAgent rootAgent,
5049
List<? extends Plugin> plugins,
5150
@Nullable EventsCompactionConfig eventsCompactionConfig,
52-
@Nullable ResumabilityConfig resumabilityConfig,
5351
@Nullable ContextCacheConfig contextCacheConfig) {
5452
this.name = name;
5553
this.rootAgent = rootAgent;
5654
this.plugins = ImmutableList.copyOf(plugins);
5755
this.eventsCompactionConfig = eventsCompactionConfig;
58-
this.resumabilityConfig = resumabilityConfig;
5956
this.contextCacheConfig = contextCacheConfig;
6057
}
6158

@@ -76,11 +73,6 @@ public EventsCompactionConfig eventsCompactionConfig() {
7673
return eventsCompactionConfig;
7774
}
7875

79-
@Nullable
80-
public ResumabilityConfig resumabilityConfig() {
81-
return resumabilityConfig;
82-
}
83-
8476
@Nullable
8577
public ContextCacheConfig contextCacheConfig() {
8678
return contextCacheConfig;
@@ -92,7 +84,6 @@ public static class Builder {
9284
private BaseAgent rootAgent;
9385
private List<? extends Plugin> plugins = ImmutableList.of();
9486
@Nullable private EventsCompactionConfig eventsCompactionConfig;
95-
@Nullable private ResumabilityConfig resumabilityConfig;
9687
@Nullable private ContextCacheConfig contextCacheConfig;
9788

9889
@CanIgnoreReturnValue
@@ -119,12 +110,6 @@ public Builder eventsCompactionConfig(EventsCompactionConfig eventsCompactionCon
119110
return this;
120111
}
121112

122-
@CanIgnoreReturnValue
123-
public Builder resumabilityConfig(ResumabilityConfig resumabilityConfig) {
124-
this.resumabilityConfig = resumabilityConfig;
125-
return this;
126-
}
127-
128113
@CanIgnoreReturnValue
129114
public Builder contextCacheConfig(ContextCacheConfig contextCacheConfig) {
130115
this.contextCacheConfig = contextCacheConfig;
@@ -139,8 +124,7 @@ public App build() {
139124
throw new IllegalStateException("Root agent must be provided.");
140125
}
141126
validateAppName(name);
142-
return new App(
143-
name, rootAgent, plugins, eventsCompactionConfig, resumabilityConfig, contextCacheConfig);
127+
return new App(name, rootAgent, plugins, eventsCompactionConfig, contextCacheConfig);
144128
}
145129
}
146130

core/src/main/java/com/google/adk/apps/ResumabilityConfig.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)