@@ -48,6 +48,7 @@ class ExternalAgentRegistry:
4848 def __init__ (self ):
4949 """Initialize the registry with built-in integrations."""
5050 self ._integrations : Dict [str , Type [BaseCLIIntegration ]] = {}
51+ self ._lock = threading .Lock ()
5152 self ._register_builtin_integrations ()
5253
5354 @classmethod
@@ -108,7 +109,7 @@ def register(self, name: str, integration_class: Type[BaseCLIIntegration]) -> No
108109 )
109110
110111 # Thread-safe registration
111- with self ._instance_lock :
112+ with self ._lock :
112113 self ._integrations [name ] = integration_class
113114
114115 def unregister (self , name : str ) -> bool :
@@ -122,11 +123,8 @@ def unregister(self, name: str) -> bool:
122123 bool: True if the integration was found and removed, False otherwise
123124 """
124125 # Thread-safe unregistration with atomic check-then-delete
125- with self ._instance_lock :
126- if name in self ._integrations :
127- del self ._integrations [name ]
128- return True
129- return False
126+ with self ._lock :
127+ return self ._integrations .pop (name , None ) is not None
130128
131129 def create (self , name : str , ** kwargs : Any ) -> Optional [BaseCLIIntegration ]:
132130 """
@@ -139,7 +137,9 @@ def create(self, name: str, **kwargs: Any) -> Optional[BaseCLIIntegration]:
139137 Returns:
140138 BaseCLIIntegration: Instance of the integration, or None if not found
141139 """
142- integration_class = self ._integrations .get (name )
140+ with self ._lock :
141+ integration_class = self ._integrations .get (name )
142+
143143 if integration_class is None :
144144 return None
145145
@@ -152,7 +152,8 @@ def list_registered(self) -> List[str]:
152152 Returns:
153153 List[str]: List of registered integration names
154154 """
155- return list (self ._integrations .keys ())
155+ with self ._lock :
156+ return list (self ._integrations .keys ())
156157
157158 async def get_available (self ) -> Dict [str , bool ]:
158159 """
@@ -164,7 +165,10 @@ async def get_available(self) -> Dict[str, bool]:
164165 import inspect
165166 availability = {}
166167
167- for name , integration_class in self ._integrations .items ():
168+ with self ._lock :
169+ snapshot = list (self ._integrations .items ())
170+
171+ for name , integration_class in snapshot :
168172 try :
169173 # Check if constructor requires parameters beyond self
170174 sig = inspect .signature (integration_class .__init__ )
0 commit comments