1818
1919import static com .google .common .base .Strings .isNullOrEmpty ;
2020
21- import com .google .adk .apps .ResumabilityConfig ;
2221import com .google .adk .artifacts .BaseArtifactService ;
23- import com .google .adk .events .Event ;
2422import com .google .adk .memory .BaseMemoryService ;
2523import com .google .adk .models .LlmCallsLimitExceededException ;
2624import com .google .adk .plugins .Plugin ;
2725import com .google .adk .plugins .PluginManager ;
2826import com .google .adk .sessions .BaseSessionService ;
2927import com .google .adk .sessions .Session ;
3028import com .google .adk .summarizer .EventsCompactionConfig ;
31- import com .google .common .collect .ImmutableSet ;
3229import com .google .errorprone .annotations .CanIgnoreReturnValue ;
3330import com .google .errorprone .annotations .InlineMe ;
3431import com .google .genai .types .Content ;
35- import com .google .genai .types .FunctionCall ;
36- import java .util .List ;
3732import java .util .Map ;
3833import java .util .Objects ;
3934import 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 ,
0 commit comments