Skip to content

[FEATURE] Plugin Protocol Definition #1689

@github-actions

Description

@github-actions

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 Protocol
  • src/strands/hooks/__init__.py - Export Plugin
  • src/strands/__init__.py - Consider exporting Plugin at top level
  • tests/strands/hooks/test_registry.py - Add Plugin Protocol tests

Acceptance Criteria

  • Plugin Protocol is defined with name property and init_plugin method
  • Both sync and async init_plugin implementations 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_checkable decorator 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)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions