generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 649
Open
Description
Overview
Create the new Plugin Protocol that will serve as the primary abstraction for high-level agent features, replacing HookProvider.
Parent Issue: #1636
Problem Statement
The current HookProvider naming doesn't clearly communicate its purpose as a mechanism for high-level agent features. The Plugin terminology is more intuitive and widely understood in the industry.
Proposed Solution
Introduce a new Plugin Protocol with clear semantics for extending agent functionality.
Implementation Requirements
Plugin Protocol Definition
- Location:
src/strands/hooks/registry.py(alongside HookProvider) - Properties:
name: str- Identifier for the plugin
- Methods:
init_plugin(self, agent: Agent) -> None- Initialize the plugin with an agent- Support both sync and async implementations
Example Protocol Shape
@runtime_checkable
class Plugin(Protocol):
"""Protocol for objects that extend agent functionality.
Plugins provide a composable way to add behavior changes to agents.
They are initialized with an agent instance and can register hooks,
modify agent attributes, or perform other setup tasks.
Example:
class MyPlugin:
name = "my-plugin"
def init_plugin(self, agent: Agent) -> None:
agent.add_hook(BeforeModelCallEvent, self.on_model_call)
"""
name: str
def init_plugin(self, agent: Agent) -> None | Awaitable[None]:
"""Initialize the plugin with an agent instance.
Args:
agent: The agent instance to extend.
"""
...Files to Modify
src/strands/hooks/registry.py- Add Plugin Protocolsrc/strands/hooks/__init__.py- Export Pluginsrc/strands/__init__.py- Consider exporting Plugin at top leveltests/strands/hooks/test_registry.py- Add Plugin Protocol tests
Acceptance Criteria
- Plugin Protocol is defined with
nameproperty andinit_pluginmethod - Both sync and async
init_pluginimplementations are supported (similar to HookCallback) - Plugin is exported from
strands.hooks - Unit tests verify Protocol behavior with both sync and async implementations
- Docstrings follow Google style with examples
Technical Notes
- Use
@runtime_checkabledecorator for runtime isinstance checks - Consider using
Awaitable[None]return type annotation to support both sync/async - Plugin is intentionally separate from HookProvider (no inheritance relationship)
Dependencies
- None (this is the foundation for other plugin-related sub-issues)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels