Skip to content

A programming framework for agentic AI

SingleThreadedAgentRuntime to use subclass check for factory_wrapper instead of equality (#6731)

Zen4ccac43b0276
diff --git a/python/packages/autogen-core/src/autogen_core/_single_threaded_agent_runtime.py b/python/packages/autogen-core/src/autogen_core/_single_threaded_agent_runtime.py
index 08627756f..3a8a8d714 100644
--- a/python/packages/autogen-core/src/autogen_core/_single_threaded_agent_runtime.py
+++ b/python/packages/autogen-core/src/autogen_core/_single_threaded_agent_runtime.py
@@ -903,9 +903,10 @@ class SingleThreadedAgentRuntime(AgentRuntime):
else:
agent_instance = maybe_agent_instance
- if expected_class is not None and type_func_alias(agent_instance) != expected_class:
- raise ValueError("Factory registered using the wrong type.")
-
+ if expected_class is not None and not issubclass(type_func_alias(agent_instance), expected_class):
+ raise ValueError(
+ f"Factory registered using the wrong type: expected {expected_class.__name__}, got {type_func_alias(agent_instance).__name__}"
+ )
return agent_instance
self._agent_factories[type.type] = factory_wrapper