generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 650
Open
Description
Overview
Migrate the experimental SteeringHandler from HookProvider to the new Plugin protocol, serving as the first official Plugin implementation in the SDK.
Parent Issue: #1636
Problem Statement
The SteeringHandler currently implements HookProvider, but as an experimental feature, it should be migrated to the new Plugin protocol to demonstrate the pattern and benefit from the cleaner API.
Proposed Solution
Update SteeringHandler to implement the Plugin protocol instead of HookProvider.
Implementation Requirements
Current Implementation
File: src/strands/experimental/steering/core/handler.py
class SteeringHandler(HookProvider, ABC):
def __init__(self, context_providers: list[SteeringContextProvider] | None = None):
super().__init__()
self.steering_context = SteeringContext()
self._context_callbacks = []
for provider in context_providers or []:
self._context_callbacks.extend(provider.context_providers())
def register_hooks(self, registry: HookRegistry, **kwargs: Any) -> None:
# Register callbacks...
passNew Implementation
from strands.hooks import Plugin
class SteeringHandler(ABC):
"""Base class for steering handlers that provide contextual guidance to agents.
Steering handlers maintain local context and register hook callbacks
to populate context data as needed for guidance decisions.
"""
name: str = "steering"
def __init__(self, context_providers: list[SteeringContextProvider] | None = None):
self.steering_context = SteeringContext()
self._context_callbacks = []
for provider in context_providers or []:
self._context_callbacks.extend(provider.context_providers())
def init_plugin(self, agent: Agent) -> None:
"""Initialize the steering handler with an agent.
Args:
agent: The agent instance to attach steering to.
"""
# Use agent.add_hook() instead of registry.add_callback()
agent.add_hook(BeforeModelCallEvent, self._on_before_model_call)
# ... other hook registrationsMigration Changes
- Remove
HookProviderfrom class inheritance - Add
nameclass attribute - Replace
register_hooks(registry)withinit_plugin(agent) - Use
agent.add_hook()instead ofregistry.add_callback()
Files to Modify
src/strands/experimental/steering/core/handler.py- Migrate to Pluginsrc/strands/experimental/steering/__init__.py- Update exports if neededtests/strands/experimental/steering/- Update tests- Any example code using SteeringHandler
Example Usage After Migration
from strands import Agent
from strands.experimental.steering import MySteeringHandler
# New way with plugins
agent = Agent(
plugins=[MySteeringHandler(context_providers=[...])]
)
# Old way still works during deprecation period
agent = Agent(
hooks=[MySteeringHandler(context_providers=[...])] # Will show deprecation warning
)Acceptance Criteria
- SteeringHandler implements Plugin protocol (has
nameandinit_plugin) - SteeringHandler no longer inherits from HookProvider
- All existing steering functionality is preserved
- Unit tests pass with updated implementation
- Works correctly with new
pluginsparameter - Subclasses of SteeringHandler continue to work
Technical Notes
- This serves as the reference implementation for migrating HookProviders to Plugins
- Since steering is experimental, this is a safe place to demonstrate the pattern
- Document the migration in the PR as a guide for others
Dependencies
- Depends on: Plugin Protocol (1636.1), plugins parameter (1636.2), add_hook method (1636.3)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels