|
7 | 7 | via hook provider objects. |
8 | 8 | """ |
9 | 9 |
|
10 | | -from dataclasses import dataclass, field |
| 10 | +from dataclasses import dataclass |
11 | 11 | from typing import TYPE_CHECKING, Any, Generator, Generic, Protocol, Type, TypeVar |
12 | 12 |
|
13 | 13 | if TYPE_CHECKING: |
14 | 14 | from ..agent import Agent |
15 | 15 |
|
| 16 | + |
16 | 17 | @dataclass |
17 | | -class HookEventBase: |
| 18 | +class BaseHookEvent: |
| 19 | + """Base class for all hook events.""" |
| 20 | + |
18 | 21 | @property |
19 | 22 | def should_reverse_callbacks(self) -> bool: |
20 | 23 | """Determine if callbacks for this event should be invoked in reverse order. |
@@ -56,27 +59,22 @@ def __setattr__(self, name: str, value: Any) -> None: |
56 | 59 |
|
57 | 60 | raise AttributeError(f"Property {name} is not writable") |
58 | 61 |
|
59 | | -@dataclass |
60 | | -class MultiAgentHookEvent(HookEventBase): |
61 | | - pass |
62 | | - |
63 | 62 |
|
64 | 63 | @dataclass |
65 | | -class HookEvent(HookEventBase): |
66 | | - """Base class for all hook events. |
| 64 | +class HookEvent(BaseHookEvent): |
| 65 | + """Base class for single agent hook events. |
67 | 66 |
|
68 | 67 | Attributes: |
69 | 68 | agent: The agent instance that triggered this event. |
70 | 69 | """ |
71 | 70 |
|
72 | | - # agent: "Agent | None" = field(default=None, kw_only=True) |
73 | | - agent : "Agent" |
| 71 | + agent: "Agent" |
74 | 72 |
|
75 | 73 |
|
76 | | -TEvent = TypeVar("TEvent", bound=HookEventBase, contravariant=True) |
| 74 | +TEvent = TypeVar("TEvent", bound=BaseHookEvent, contravariant=True) |
77 | 75 | """Generic for adding callback handlers - contravariant to allow adding handlers which take in base classes.""" |
78 | 76 |
|
79 | | -TInvokeEvent = TypeVar("TInvokeEvent", bound=HookEventBase) |
| 77 | +TInvokeEvent = TypeVar("TInvokeEvent", bound=BaseHookEvent) |
80 | 78 | """Generic for invoking events - non-contravariant to enable returning events.""" |
81 | 79 |
|
82 | 80 |
|
|
0 commit comments