From 14ee28ba593a9f6f5f7b9bb6003441539fe33a18 Mon Sep 17 00:00:00 2001 From: Google Team Member Date: Tue, 10 Mar 2026 08:01:55 -0700 Subject: [PATCH] fix: Make sure that `InvocationContext.callbackContextData` remains the same instance `InvocationContext.callbackContextData` is used by plugins to keep track of things like invocation start times in `before` and then read in `after` callbacks PiperOrigin-RevId: 881432816 --- .../java/com/google/adk/agents/InvocationContext.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 7602ca9f2..7f0e49d0c 100644 --- a/core/src/main/java/com/google/adk/agents/InvocationContext.java +++ b/core/src/main/java/com/google/adk/agents/InvocationContext.java @@ -75,7 +75,10 @@ protected InvocationContext(Builder builder) { this.eventsCompactionConfig = builder.eventsCompactionConfig; this.contextCacheConfig = builder.contextCacheConfig; this.invocationCostManager = builder.invocationCostManager; - this.callbackContextData = new ConcurrentHashMap<>(builder.callbackContextData); + // Don't copy the callback context data. This should be the same instance for the full + // invocation invocation so that Plugins can access the same data it during the invocation + // across all types of callbacks. + this.callbackContextData = builder.callbackContextData; } /** @@ -345,7 +348,10 @@ private Builder(InvocationContext context) { this.eventsCompactionConfig = context.eventsCompactionConfig; this.contextCacheConfig = context.contextCacheConfig; this.invocationCostManager = context.invocationCostManager; - this.callbackContextData = new ConcurrentHashMap<>(context.callbackContextData); + // Don't copy the callback context data. This should be the same instance for the full + // invocation invocation so that Plugins can access the same data it during the invocation + // across all types of callbacks. + this.callbackContextData = context.callbackContextData; } private BaseSessionService sessionService;