# Useful but Little-Known Features of ADK 2.0
🌍 What if you could hook into the entire agent execution lifecycle — observing, intervening, and amending — without touching agent code?
ADK 2.0's Plugin system lets you extend `BasePlugin` and register it on a Runner to apply lifecycle callbacks globally across all agents. Unlike per-agent callbacks, plugins operate at the runner level with cross-cutting scope.
📌 Title: Plugins
🔗 URL:
🧩 Overview
Plugins extend `BasePlugin` and are registered on the Runner. Unlike agent-specific callbacks, they apply globally across all agents. Lifecycle hooks cover the full span: user message receipt, runner start, agent execution, model calls, tool execution, event processing, and runner end. Plugins operate in three modes: Observe (monitoring only), Intervene (modify or block processing), and Amend (modify results after the fact). Plugin callbacks run BEFORE agent callbacks in the execution order.
🛠 How to use it
Extend `BasePlugin` and override the lifecycle hooks you need.
```python
from adk.plugins import BasePlugin
class LoggingPlugin(BasePlugin):
def __init__(self):
super().__init__(name="logging_plugin")
async def on_before_model_call(self, callback_context, llm_request):
print(f"Model call: {llm_request.model}")
return None # returning None continues normal processing
async def on_after_tool_call(self, tool_context, tool_response):
print(f"Tool executed: {tool_context.tool_name}")
return None
# Register on Runner
runner = Runner(
agent=my_agent,
plugins=[LoggingPlugin()]
)
```
In Intervene mode, return a value from the callback to replace the normal processing. In Amend mode, modify results after event processing.
🏗 Building it into production
・Implement logging and metrics collection as Observe-mode plugins to keep agent code clean
・Build guardrails and content filtering as Intervene-mode plugins to block inappropriate I/O
・Add analytics data collection as Amend-mode post-processing
・Leverage prebuilt plugins (Reflect/Retry, BigQuery Analytics, Context Filtering, Global Instructions) to accelerate development
💡 Use cases
📊 Log all model calls and tool executions across every agent to BigQuery
🛡 Centralize input guardrails in a plugin to block harmful requests system-wide
🔄 Implement retry logic for failed model calls using the Reflect/Retry plugin
📋 Apply global instructions (compliance rules, etc.) to all agents via the Global Instructions plugin
⚠️ Watch out
Plugin callbacks execute before agent callbacks — if a plugin blocks processing, the agent callback won't fire. Returning incorrect values in Intervene mode can break agent behavior, so understand the expected return types and semantics before using it. Plugin execution order depends on registration order in the Runner.
✨ Plugins let you separate cross-cutting concerns (logging, security, analytics) from agent core logic, enabling highly maintainable systems.
#
ADK# #
AIAgent#