From 8f7d7eac95cc606b5c5716612d0b08c41f951167 Mon Sep 17 00:00:00 2001 From: Google Team Member Date: Wed, 28 Jan 2026 13:18:35 -0800 Subject: [PATCH] feat: Add event compaction config to InvocationContext This CL integrates event compaction configuration into the InvocationContext, allowing agent to access the configs during execution. PiperOrigin-RevId: 862366865 --- .../google/adk/agents/InvocationContext.java | 24 +++++++++++++++++++ .../java/com/google/adk/runner/Runner.java | 1 + 2 files changed, 25 insertions(+) diff --git a/core/src/main/java/com/google/adk/agents/InvocationContext.java b/core/src/main/java/com/google/adk/agents/InvocationContext.java index ace00db4c..ed9b21062 100644 --- a/core/src/main/java/com/google/adk/agents/InvocationContext.java +++ b/core/src/main/java/com/google/adk/agents/InvocationContext.java @@ -25,6 +25,7 @@ import com.google.adk.plugins.PluginManager; import com.google.adk.sessions.BaseSessionService; import com.google.adk.sessions.Session; +import com.google.adk.summarizer.EventsCompactionConfig; import com.google.common.collect.ImmutableSet; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.InlineMe; @@ -53,6 +54,7 @@ public class InvocationContext { private final Map agentStates; private final Map endOfAgents; private final ResumabilityConfig resumabilityConfig; + @Nullable private final EventsCompactionConfig eventsCompactionConfig; private final InvocationCostManager invocationCostManager; private Optional branch; @@ -76,6 +78,7 @@ protected InvocationContext(Builder builder) { this.agentStates = builder.agentStates; this.endOfAgents = builder.endOfAgents; this.resumabilityConfig = builder.resumabilityConfig; + this.eventsCompactionConfig = builder.eventsCompactionConfig; this.invocationCostManager = builder.invocationCostManager; } @@ -356,6 +359,11 @@ public boolean isResumable() { return resumabilityConfig.isResumable(); } + /** Returns the events compaction configuration for the current agent run. */ + public Optional eventsCompactionConfig() { + return Optional.ofNullable(eventsCompactionConfig); + } + /** Returns whether to pause the invocation right after this [event]. */ public boolean shouldPauseInvocation(Event event) { if (!isResumable()) { @@ -427,6 +435,7 @@ private Builder(InvocationContext context) { this.agentStates = new ConcurrentHashMap<>(context.agentStates); this.endOfAgents = new ConcurrentHashMap<>(context.endOfAgents); this.resumabilityConfig = context.resumabilityConfig; + this.eventsCompactionConfig = context.eventsCompactionConfig; this.invocationCostManager = context.invocationCostManager; } @@ -446,6 +455,7 @@ private Builder(InvocationContext context) { private Map agentStates = new ConcurrentHashMap<>(); private Map endOfAgents = new ConcurrentHashMap<>(); private ResumabilityConfig resumabilityConfig = new ResumabilityConfig(); + @Nullable private EventsCompactionConfig eventsCompactionConfig; private InvocationCostManager invocationCostManager = new InvocationCostManager(); /** @@ -670,6 +680,18 @@ public Builder resumabilityConfig(ResumabilityConfig resumabilityConfig) { return this; } + /** + * Sets the events compaction configuration for the current agent run. + * + * @param eventsCompactionConfig the events compaction configuration. + * @return this builder instance for chaining. + */ + @CanIgnoreReturnValue + public Builder eventsCompactionConfig(@Nullable EventsCompactionConfig eventsCompactionConfig) { + this.eventsCompactionConfig = eventsCompactionConfig; + return this; + } + /** * Builds the {@link InvocationContext} instance. * @@ -705,6 +727,7 @@ public boolean equals(Object o) { && Objects.equals(agentStates, that.agentStates) && Objects.equals(endOfAgents, that.endOfAgents) && Objects.equals(resumabilityConfig, that.resumabilityConfig) + && Objects.equals(eventsCompactionConfig, that.eventsCompactionConfig) && Objects.equals(invocationCostManager, that.invocationCostManager); } @@ -727,6 +750,7 @@ public int hashCode() { agentStates, endOfAgents, resumabilityConfig, + eventsCompactionConfig, invocationCostManager); } } diff --git a/core/src/main/java/com/google/adk/runner/Runner.java b/core/src/main/java/com/google/adk/runner/Runner.java index 574c3dcf0..66bb58606 100644 --- a/core/src/main/java/com/google/adk/runner/Runner.java +++ b/core/src/main/java/com/google/adk/runner/Runner.java @@ -634,6 +634,7 @@ private InvocationContext.Builder newInvocationContextBuilder(Session session) { .agent(rootAgent) .session(session) .resumabilityConfig(this.resumabilityConfig) + .eventsCompactionConfig(this.eventsCompactionConfig) .agent(this.findAgentToRun(session, rootAgent)); }