Skip to content

Commit 9e427fb

Browse files
committed
refactor(events): standardize handler typing across event buses
Make event subscription signatures explicit and reusable so outbound/inbound bus implementations and agent adapter wiring share one typed contract. This reduces annotation drift and keeps bus integration safer as event layers evolve.
1 parent c900660 commit 9e427fb

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

agents-core/vision_agents/core/agents/agents.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import logging
44
import time
55
import uuid
6-
from collections.abc import Awaitable, Callable
76
from contextlib import asynccontextmanager, contextmanager
87
from pathlib import Path
98
from typing import (
@@ -33,7 +32,7 @@
3332
)
3433
from ..edge.types import Connection, Participant, TrackType, User
3534
from ..events import AgentConnectionEvent, EdgeCustomEventOutboundAdapter
36-
from ..events.bus import EventBus, InMemoryEventBus
35+
from ..events.bus import EventBus, EventHandler, InMemoryEventBus
3736
from ..events.manager import EventManager
3837
from ..instructions import Instructions
3938
from ..llm import events as llm_events
@@ -1541,7 +1540,7 @@ def _register_default_outbound_adapter_if_needed(self) -> None:
15411540

15421541
def _resolve_adapter_deliver(
15431542
self, adapter: OutboundEventAdapter
1544-
) -> Callable[[AgentConnectionEvent], Awaitable[None]]:
1543+
) -> EventHandler[AgentConnectionEvent]:
15451544
deliver = getattr(adapter, "deliver", None)
15461545
if deliver is None:
15471546
raise ValueError(

agents-core/vision_agents/core/events/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
VideoProcessorDetectionEvent,
88
)
99
from .adapters import EdgeCustomEventOutboundAdapter
10-
from .bus import EventBus, InMemoryEventBus
10+
from .bus import EventBus, EventHandler, InMemoryEventBus
1111
from .manager import EventManager
1212

1313
__all__ = [
@@ -17,6 +17,7 @@
1717
"ConnectionState",
1818
"EdgeCustomEventOutboundAdapter",
1919
"EventBus",
20+
"EventHandler",
2021
"EventManager",
2122
"InMemoryEventBus",
2223
"PluginBaseEvent",

agents-core/vision_agents/core/events/bus.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import asyncio
2+
import inspect
23
from collections.abc import Awaitable, Callable
34
from typing import Generic, Protocol, TypeVar
45

56
T = TypeVar("T")
7+
EventHandler = Callable[[T], Awaitable[None]]
68

79

810
class EventBus(Protocol[T]):
9-
def subscribe(self, handler: Callable[[T], Awaitable[None]]) -> None: ...
11+
def subscribe(self, handler: EventHandler[T]) -> None: ...
1012

1113
async def publish(self, event: T) -> None: ...
1214

1315

1416
class InMemoryEventBus(Generic[T]):
1517
def __init__(self) -> None:
16-
self._handlers: list[Callable[[T], Awaitable[None]]] = []
18+
self._handlers: list[EventHandler[T]] = []
1719

18-
def subscribe(self, handler: Callable[[T], Awaitable[None]]) -> None:
19-
if not asyncio.iscoroutinefunction(handler):
20+
def subscribe(self, handler: EventHandler[T]) -> None:
21+
if not inspect.iscoroutinefunction(handler):
2022
raise RuntimeError(
2123
"Handlers must be coroutines. Use async def handler(event):"
2224
)

0 commit comments

Comments
 (0)