99from collections .abc import Awaitable
1010from typing import TYPE_CHECKING
1111
12+ from ..hooks .registry import HookCallback
1213from ..tools .decorator import DecoratedFunctionTool
13- from .decorator import _WrappedHookCallable
1414
1515if TYPE_CHECKING :
1616 from ..agent import Agent
@@ -27,8 +27,8 @@ class Plugin(ABC):
2727
2828 Attributes:
2929 name: A stable string identifier for the plugin (must be provided by subclass)
30- hooks: List of hooks the plugin provides , auto-discovered from @hook decorated methods
31- tools: List of tools the plugin provides , auto-discovered from @tool decorated methods
30+ hooks: Hooks attached to the agent , auto-discovered from @hook decorated methods during __init__
31+ tools: Tools attached to the agent , auto-discovered from @tool decorated methods during __init__
3232
3333 Example using decorators (recommended):
3434 ```python
@@ -49,6 +49,10 @@ def my_tool(self, param: str) -> str:
4949 return f"Result: {param}"
5050 ```
5151
52+ Note: Decorated methods are registered in declaration order, with parent
53+ class methods registered before child class methods. If a child overrides
54+ a parent's decorated method, only the child's version is registered.
55+
5256 Example with custom initialization:
5357 ```python
5458 class MyPlugin(Plugin):
@@ -57,7 +61,7 @@ class MyPlugin(Plugin):
5761 def init_agent(self, agent: Agent) -> None:
5862 # Custom initialization logic - no super() needed
5963 # Decorated hooks/tools are auto-registered by the plugin registry
60- agent.hooks.add_callback(BeforeModelCallEvent, self.custom_hook)
64+ agent.add_hook( self.custom_hook)
6165
6266 def custom_hook(self, event: BeforeModelCallEvent):
6367 print(event)
@@ -76,12 +80,12 @@ def __init__(self) -> None:
7680 Scans the class for methods decorated with @hook and @tool and stores
7781 references for later registration when the plugin is attached to an agent.
7882 """
79- self ._hooks : list [_WrappedHookCallable ] = []
83+ self ._hooks : list [HookCallback ] = []
8084 self ._tools : list [DecoratedFunctionTool ] = []
8185 self ._discover_decorated_methods ()
8286
8387 @property
84- def hooks (self ) -> list [_WrappedHookCallable ]:
88+ def hooks (self ) -> list [HookCallback ]:
8589 """List of hooks the plugin provides, auto-discovered from @hook decorated methods."""
8690 return self ._hooks
8791
@@ -120,8 +124,7 @@ def init_agent(self, agent: "Agent") -> None | Awaitable[None]:
120124 """Initialize the agent instance.
121125
122126 Override this method to add custom initialization logic. Decorated
123- hooks and tools are automatically registered by the plugin registry,
124- so there's no need to call super().init_agent(agent).
127+ hooks and tools are automatically registered by the plugin registry.
125128
126129 Args:
127130 agent: The agent instance to initialize.
0 commit comments