feat: Add Graceful Plugin Shutdown to Runner

This change introduces a shutdown lifecycle hook for plugins. The `PluginManager` now has an `async def shutdown()` method that will call `await plugin.shutdown()` on any registered plugins that implement the method. This is called from `Runner.close()`, allowing plugins to perform cleanup tasks like flushing logs or closing connections when the runner instance is being closed. This improves the reliability of plugins that perform background operations.

PiperOrigin-RevId: 831037737
This commit is contained in:
Google Team Member
2025-11-11 13:05:03 -08:00
committed by Copybara-Service
parent 01bac62f0c
commit 249216e890
7 changed files with 152 additions and 7 deletions
+8
View File
@@ -187,6 +187,14 @@ class BasePlugin(ABC):
"""
pass
async def close(self) -> None:
"""Method executed when the runner is closed.
This method is used for cleanup tasks such as closing network connections
or releasing resources.
"""
pass
async def before_agent_callback(
self, *, agent: BaseAgent, callback_context: CallbackContext
) -> Optional[types.Content]: