generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 655
Open
Description
Overview
Add a new plugins parameter to the Agent class that accepts a list of Plugin instances for extending agent functionality.
Parent Issue: #1636
Problem Statement
Currently, high-level features are added via the hooks parameter using HookProvider. A dedicated plugins parameter provides clearer semantics for composable agent extensions.
Proposed Solution
Add plugins: list[Plugin] | None = None parameter to Agent.__init__ that initializes plugins after the agent is constructed.
Implementation Requirements
Based on clarification discussion and repository analysis:
Technical Approach
- Dependency: This issue requires [FEATURE] Plugin Protocol Definition #1689 (Plugin Protocol Definition) to be merged first
- No Explicit Type Checking: Do not add isinstance checks for Plugin validation - let failures occur naturally when
init_pluginis called - Async Handling: Use
run_async()helper for asyncinit_pluginmethods (same pattern as existing Agent code)
Agent.init Changes
def __init__(
self,
# ... existing parameters ...
plugins: list[Plugin] | None = None,
hooks: list[HookProvider] | None = None, # Keep for backwards compatibility
):
# ... existing initialization ...
# Register hooks (existing code)
if hooks:
for hook in hooks:
self.hooks.add_hook(hook)
# Initialize plugins after agent is fully constructed
if plugins:
for plugin in plugins:
if inspect.iscoroutinefunction(plugin.init_plugin):
# Handle async init_plugin
run_async(lambda p=plugin: p.init_plugin(self))
else:
plugin.init_plugin(self)
# Fire AgentInitializedEvent after plugins are initialized
self.hooks.invoke_callbacks(AgentInitializedEvent(agent=self))Plugin Initialization Order
- Built-in components initialized (model, tools, hooks registry)
- HookProviders registered (from
hooksparameter - deprecated) - Plugins initialized (from
pluginsparameter) ← New AgentInitializedEventfired
Files to Modify
| File | Changes |
|---|---|
src/strands/agent/agent.py |
Add plugins parameter, import Plugin, add initialization logic |
tests/strands/agent/test_agent.py |
Add unit tests for plugins parameter |
Import Requirements
- Import
Pluginfromstrands.hooksin agent.py (internal) - Add
inspectimport foriscoroutinefunctioncheck
Example Usage
from strands import Agent, Plugin
class LoggingPlugin:
name = "logging"
def init_plugin(self, agent):
agent.add_hook(lambda e: print("Model call starting"), BeforeModelCallEvent)
class SkillsPlugin:
name = "skills"
async def init_plugin(self, agent):
# Async initialization supported
agent.add_hook(self.inject_skills, BeforeModelCallEvent)
def inject_skills(self, event):
pass
# Clean, intuitive API
agent = Agent(
plugins=[
LoggingPlugin(),
SkillsPlugin(),
]
)Acceptance Criteria
-
pluginsparameter added toAgent.__init__with typelist[Plugin] | None = None - Plugins are initialized with the agent instance after construction
- Both sync and async
init_pluginmethods are handled correctly usingrun_async() - Plugin initialization happens after HookProvider registration and before
AgentInitializedEventis fired - Unit tests cover:
- Plugin initialization with sync
init_plugin - Plugin initialization with async
init_plugin - Multiple plugins in order
- Empty/None plugins parameter
- Plugin initialization with sync
- Docstring for
pluginsparameter added toAgent.__init__ -
pluginsparameter documented in Args section
Dependencies
- Blocked by: [FEATURE] Plugin Protocol Definition #1689 (Plugin Protocol Definition) - must be merged first
Technical Notes
- Follow existing patterns in
Agent.__init__for thehooksparameter - No runtime type validation needed - let duck typing handle invalid plugins
- Use
inspect.iscoroutinefunction()to detect asyncinit_pluginmethods - The
run_async()helper is already imported in agent.py
Design References
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels