2525import com .google .adk .plugins .PluginManager ;
2626import com .google .adk .sessions .BaseSessionService ;
2727import com .google .adk .sessions .Session ;
28+ import com .google .adk .summarizer .EventsCompactionConfig ;
2829import com .google .common .collect .ImmutableSet ;
2930import com .google .errorprone .annotations .CanIgnoreReturnValue ;
3031import com .google .errorprone .annotations .InlineMe ;
@@ -53,6 +54,7 @@ public class InvocationContext {
5354 private final Map <String , BaseAgentState > agentStates ;
5455 private final Map <String , Boolean > endOfAgents ;
5556 private final ResumabilityConfig resumabilityConfig ;
57+ @ Nullable private final EventsCompactionConfig eventsCompactionConfig ;
5658 private final InvocationCostManager invocationCostManager ;
5759
5860 private Optional <String > branch ;
@@ -76,6 +78,7 @@ protected InvocationContext(Builder builder) {
7678 this .agentStates = builder .agentStates ;
7779 this .endOfAgents = builder .endOfAgents ;
7880 this .resumabilityConfig = builder .resumabilityConfig ;
81+ this .eventsCompactionConfig = builder .eventsCompactionConfig ;
7982 this .invocationCostManager = builder .invocationCostManager ;
8083 }
8184
@@ -356,6 +359,11 @@ public boolean isResumable() {
356359 return resumabilityConfig .isResumable ();
357360 }
358361
362+ /** Returns the events compaction configuration for the current agent run. */
363+ public Optional <EventsCompactionConfig > eventsCompactionConfig () {
364+ return Optional .ofNullable (eventsCompactionConfig );
365+ }
366+
359367 /** Returns whether to pause the invocation right after this [event]. */
360368 public boolean shouldPauseInvocation (Event event ) {
361369 if (!isResumable ()) {
@@ -427,6 +435,7 @@ private Builder(InvocationContext context) {
427435 this .agentStates = new ConcurrentHashMap <>(context .agentStates );
428436 this .endOfAgents = new ConcurrentHashMap <>(context .endOfAgents );
429437 this .resumabilityConfig = context .resumabilityConfig ;
438+ this .eventsCompactionConfig = context .eventsCompactionConfig ;
430439 this .invocationCostManager = context .invocationCostManager ;
431440 }
432441
@@ -446,6 +455,7 @@ private Builder(InvocationContext context) {
446455 private Map <String , BaseAgentState > agentStates = new ConcurrentHashMap <>();
447456 private Map <String , Boolean > endOfAgents = new ConcurrentHashMap <>();
448457 private ResumabilityConfig resumabilityConfig = new ResumabilityConfig ();
458+ @ Nullable private EventsCompactionConfig eventsCompactionConfig ;
449459 private InvocationCostManager invocationCostManager = new InvocationCostManager ();
450460
451461 /**
@@ -670,6 +680,18 @@ public Builder resumabilityConfig(ResumabilityConfig resumabilityConfig) {
670680 return this ;
671681 }
672682
683+ /**
684+ * Sets the events compaction configuration for the current agent run.
685+ *
686+ * @param eventsCompactionConfig the events compaction configuration.
687+ * @return this builder instance for chaining.
688+ */
689+ @ CanIgnoreReturnValue
690+ public Builder eventsCompactionConfig (@ Nullable EventsCompactionConfig eventsCompactionConfig ) {
691+ this .eventsCompactionConfig = eventsCompactionConfig ;
692+ return this ;
693+ }
694+
673695 /**
674696 * Builds the {@link InvocationContext} instance.
675697 *
@@ -705,6 +727,7 @@ public boolean equals(Object o) {
705727 && Objects .equals (agentStates , that .agentStates )
706728 && Objects .equals (endOfAgents , that .endOfAgents )
707729 && Objects .equals (resumabilityConfig , that .resumabilityConfig )
730+ && Objects .equals (eventsCompactionConfig , that .eventsCompactionConfig )
708731 && Objects .equals (invocationCostManager , that .invocationCostManager );
709732 }
710733
@@ -727,6 +750,7 @@ public int hashCode() {
727750 agentStates ,
728751 endOfAgents ,
729752 resumabilityConfig ,
753+ eventsCompactionConfig ,
730754 invocationCostManager );
731755 }
732756}
0 commit comments