strands.plugins.registry
Plugin registry for managing plugins attached to an agent.
This module provides the _PluginRegistry class for tracking and managing plugins that have been initialized with an agent instance.
_PluginRegistry
Section titled “_PluginRegistry”class _PluginRegistry()Defined in: src/strands/plugins/registry.py:21
Registry for managing plugins attached to an agent.
The _PluginRegistry tracks plugins that have been initialized with an agent, providing methods to add plugins and invoke their initialization.
The registry handles:
- Calling the plugin’s init_agent() method for custom initialization
- Auto-registering discovered @hook decorated methods with the agent
- Auto-registering discovered @tool decorated methods with the agent
Example:
registry = _PluginRegistry(agent)
class MyPlugin(Plugin): name = "my-plugin"
@hook def on_event(self, event: BeforeModelCallEvent): pass # Auto-registered by registry
def init_agent(self, agent: Agent) -> None: # Custom logic only - no super() needed pass
plugin = MyPlugin()registry.add_and_init(plugin)__init__
Section titled “__init__”def __init__(agent: "Agent") -> NoneDefined in: src/strands/plugins/registry.py:52
Initialize a plugin registry with an agent reference.
Arguments:
agent- The agent instance that plugins will be initialized with.
add_and_init
Section titled “add_and_init”def add_and_init(plugin: Plugin) -> NoneDefined in: src/strands/plugins/registry.py:61
Add and initialize a plugin with the agent.
This method:
- Registers the plugin in the registry
- Calls the plugin’s init_agent method for custom initialization
- Auto-registers all discovered @hook methods with the agent’s hook registry
- Auto-registers all discovered @tool methods with the agent’s tool registry
Handles both sync and async init_agent implementations automatically.
Arguments:
plugin- The plugin to add and initialize.
Raises:
ValueError- If a plugin with the same name is already registered.