Skip to content

A programming framework for agentic AI

Add ID to subscription (#317)

Jack Gerrits37be630dd8c6
diff --git a/python/src/agnext/components/_type_subscription.py b/python/src/agnext/components/_type_subscription.py
index cb77cfde6..899feaa7e 100644
--- a/python/src/agnext/components/_type_subscription.py
+++ b/python/src/agnext/components/_type_subscription.py
@@ -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
diff --git a/python/src/agnext/core/_subscription.py b/python/src/agnext/core/_subscription.py
index 1805cf443..a75492d71 100644
--- a/python/src/agnext/core/_subscription.py
+++ b/python/src/agnext/core/_subscription.py
@@ -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.