From b8dc9fce616eef2ca53c5c35ffeb27d8e79ec6f1 Mon Sep 17 00:00:00 2001 From: Jack Gerrits Date: Thu, 19 Sep 2024 10:01:03 -0400 Subject: [PATCH] Fix subscription decorator sharing class instances among children (#571) --- .../autogen-core/src/autogen_core/base/_base_agent.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python/packages/autogen-core/src/autogen_core/base/_base_agent.py b/python/packages/autogen-core/src/autogen_core/base/_base_agent.py index 83fec3300..cb0da711c 100644 --- a/python/packages/autogen-core/src/autogen_core/base/_base_agent.py +++ b/python/packages/autogen-core/src/autogen_core/base/_base_agent.py @@ -58,6 +58,12 @@ class BaseAgent(ABC, Agent): _unbound_subscriptions_list: ClassVar[List[UnboundSubscription]] = [] _extra_handles_types: ClassVar[List[Tuple[Type[Any], List[MessageSerializer[Any]]]]] = [] + def __init_subclass__(cls, **kwargs: Any) -> None: + super().__init_subclass__(**kwargs) + # Automatically set class_variable in each subclass so that they are not shared between subclasses + cls._extra_handles_types = [] + cls._unbound_subscriptions_list = [] + @classmethod def _handles_types(cls) -> List[Tuple[Type[Any], List[MessageSerializer[Any]]]]: return cls._extra_handles_types