Skip to content

[FEATURE] Add plugins Parameter to Agent #1687

@github-actions

Description

@github-actions

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

Agent.init Changes

def __init__(
    self,
    # ... existing parameters ...
    plugins: list[Plugin] | None = None,
    hooks: list[HookProvider] | None = None,  # Keep for backwards compatibility
):
    # ... existing initialization ...
    
    # 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

  1. Built-in components initialized (model, tools, hooks registry)
  2. HookProviders registered (from hooks parameter - deprecated)
  3. Plugins initialized (from plugins parameter)
  4. AgentInitializedEvent fired

Files to Modify

  • src/strands/agent/agent.py - Add plugins parameter and initialization logic
  • tests/strands/agent/test_agent.py - Add tests for plugins parameter

Example Usage

from strands import Agent
from strands.hooks import Plugin

class LoggingPlugin:
    name = "logging"
    
    def init_plugin(self, agent):
        agent.add_hook(BeforeModelCallEvent, lambda e: print("Model call starting"))

agent = Agent(
    plugins=[
        LoggingPlugin(),
        SkillsPlugin(),
    ]
)

Acceptance Criteria

  • plugins parameter added to Agent.init
  • Plugins are initialized with the agent instance after construction
  • Both sync and async init_plugin methods are handled correctly
  • Plugin initialization happens before AgentInitializedEvent is fired
  • Unit tests cover plugin initialization with various scenarios
  • Docstrings updated for Agent class

Dependencies

  • Depends on: Plugin Protocol Definition (sub-issue 1636.1)

Metadata

Metadata

Assignees

No one assigned

    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