Skip to content

Commit 8f7d7ea

Browse files
google-genai-botcopybara-github
authored andcommitted
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
1 parent 0c6e61c commit 8f7d7ea

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.adk.plugins.PluginManager;
2626
import com.google.adk.sessions.BaseSessionService;
2727
import com.google.adk.sessions.Session;
28+
import com.google.adk.summarizer.EventsCompactionConfig;
2829
import com.google.common.collect.ImmutableSet;
2930
import com.google.errorprone.annotations.CanIgnoreReturnValue;
3031
import 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
}

core/src/main/java/com/google/adk/runner/Runner.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ private InvocationContext.Builder newInvocationContextBuilder(Session session) {
634634
.agent(rootAgent)
635635
.session(session)
636636
.resumabilityConfig(this.resumabilityConfig)
637+
.eventsCompactionConfig(this.eventsCompactionConfig)
637638
.agent(this.findAgentToRun(session, rootAgent));
638639
}
639640

0 commit comments

Comments
 (0)