Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/strands/hooks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def log_end(self, event: AfterInvocationEvent) -> None:
BeforeToolCallEvent,
MessageAddedEvent,
)
from .registry import HookCallback, HookEvent, HookProvider, HookRegistry
from .registry import BaseHookEvent, HookCallback, HookEvent, HookProvider, HookRegistry

__all__ = [
"AgentInitializedEvent",
Expand All @@ -54,4 +54,6 @@ def log_end(self, event: AfterInvocationEvent) -> None:
"HookProvider",
"HookCallback",
"HookRegistry",
"HookEvent",
"BaseHookEvent",
]
25 changes: 15 additions & 10 deletions src/strands/hooks/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@


@dataclass
class HookEvent:
"""Base class for all hook events.

Attributes:
agent: The agent instance that triggered this event.
"""

agent: "Agent"
class BaseHookEvent:
"""Base class for all hook events."""

@property
def should_reverse_callbacks(self) -> bool:
Expand Down Expand Up @@ -66,10 +60,21 @@ def __setattr__(self, name: str, value: Any) -> None:
raise AttributeError(f"Property {name} is not writable")


TEvent = TypeVar("TEvent", bound=HookEvent, contravariant=True)
@dataclass
class HookEvent(BaseHookEvent):
"""Base class for single agent hook events.

Attributes:
agent: The agent instance that triggered this event.
"""

agent: "Agent"


TEvent = TypeVar("TEvent", bound=BaseHookEvent, contravariant=True)
"""Generic for adding callback handlers - contravariant to allow adding handlers which take in base classes."""

TInvokeEvent = TypeVar("TInvokeEvent", bound=HookEvent)
TInvokeEvent = TypeVar("TInvokeEvent", bound=BaseHookEvent)
"""Generic for invoking events - non-contravariant to enable returning events."""


Expand Down
Loading