Skip to content

Commit c9875a0

Browse files
author
agent
committed
fix(plugins): duck-typed InvocationContext resolution to avoid NameError; all plugin tests pass
1 parent 679f7ba commit c9875a0

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/google/adk/plugins/llm_resilience_plugin.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,15 @@ async def on_model_error_callback(
163163
# Let the original error propagate if all attempts failed
164164
return None
165165

166-
def _get_invocation_context(self, callback_context: CallbackContext | InvocationContext):
167-
# Accept both Context (CallbackContext alias) and InvocationContext for flexibility in tests
168-
if isinstance(callback_context, InvocationContext):
166+
def _get_invocation_context(self, callback_context):
167+
# Accept both Context (CallbackContext alias) and InvocationContext via duck typing
168+
# If this looks like an InvocationContext (has agent and run_config), use it directly
169+
if hasattr(callback_context, "agent") and hasattr(callback_context, "run_config"):
169170
return callback_context
170-
# Fallback for Context which wraps InvocationContext
171+
# Otherwise expect a Context-like object exposing the private _invocation_context
171172
ic = getattr(callback_context, "_invocation_context", None)
172173
if ic is None:
173-
raise TypeError("callback_context must be Context or InvocationContext")
174+
raise TypeError("callback_context must be Context or InvocationContext-like")
174175
return ic
175176

176177
async def _retry_same_model(

0 commit comments

Comments
 (0)