Add ID to subscription (#317)

This commit is contained in:
Jack Gerrits 2024-08-03 09:30:11 -07:00 committed by GitHub
parent 1c95443db5
commit 37be630dd8
2 changed files with 18 additions and 0 deletions

View File

@ -1,3 +1,5 @@
import uuid
from agnext.core.exceptions import CantHandleException
from ..core import AgentId, Subscription, TopicId
@ -27,6 +29,11 @@ class TypeSubscription(Subscription):
self._topic_type = topic_type
self._agent_type = agent_type
self._id = str(uuid.uuid4())
@property
def id(self) -> str:
return self._id
def is_match(self, topic_id: TopicId) -> bool:
return topic_id.type == self._topic_type

View File

@ -8,6 +8,17 @@ from ._topic import TopicId
class Subscription(Protocol):
"""Subscriptions define the topics that an agent is interested in."""
@property
def id(self) -> str:
"""Get the ID of the subscription.
Implementations should return a unique ID for the subscription. Usually this is a UUID.
Returns:
str: ID of the subscription.
"""
...
def is_match(self, topic_id: TopicId) -> bool:
"""Check if a given topic_id matches the subscription.