feat: migrate invocation_context to callback_context

Update plugin manager and built-in plugins to prioritize CallbackContext. Keep InvocationContext access for legacy plugins with adapter. Change callback docs/tests to cover the new context.

PiperOrigin-RevId: 818822267
This commit is contained in:
Google Team Member
2025-10-13 14:05:44 -07:00
committed by Copybara-Service
parent 2158b3c915
commit df05ed6b3b
10 changed files with 110 additions and 240 deletions
+16 -8
View File
@@ -103,15 +103,19 @@ async def test_base_plugin_default_callbacks_return_none():
assert (
await plugin.on_user_message_callback(
user_message=mock_user_message,
callback_context=mock_context,
invocation_context=mock_context,
)
is None
)
assert await plugin.before_run_callback(callback_context=mock_context) is None
assert await plugin.after_run_callback(callback_context=mock_context) is None
assert (
await plugin.before_run_callback(invocation_context=mock_context) is None
)
assert (
await plugin.after_run_callback(invocation_context=mock_context) is None
)
assert (
await plugin.on_event_callback(
callback_context=mock_context, event=mock_context
invocation_context=mock_context, event=mock_context
)
is None
)
@@ -196,21 +200,25 @@ async def test_base_plugin_all_callbacks_can_be_overridden():
assert (
await plugin.on_user_message_callback(
user_message=mock_user_message,
callback_context=mock_callback_context,
invocation_context=mock_invocation_context,
)
== "overridden_on_user_message"
)
assert (
await plugin.before_run_callback(callback_context=mock_callback_context)
await plugin.before_run_callback(
invocation_context=mock_invocation_context
)
== "overridden_before_run"
)
assert (
await plugin.after_run_callback(callback_context=mock_callback_context)
await plugin.after_run_callback(
invocation_context=mock_invocation_context
)
== "overridden_after_run"
)
assert (
await plugin.on_event_callback(
callback_context=mock_callback_context, event=mock_event
invocation_context=mock_invocation_context, event=mock_event
)
== "overridden_on_event"
)