A programming framework for agentic AI
Accept agent type in more places (#4829)
Jack Gerrits5bd91fb15ee9
diff --git a/python/packages/autogen-core/src/autogen_core/_default_subscription.py b/python/packages/autogen-core/src/autogen_core/_default_subscription.pyindex d47c62109..4c5251c85 100644--- a/python/packages/autogen-core/src/autogen_core/_default_subscription.py+++ b/python/packages/autogen-core/src/autogen_core/_default_subscription.py@@ -1,5 +1,6 @@from typing import Callable, Type, TypeVar, overload+from ._agent_type import AgentTypefrom ._base_agent import BaseAgent, subscription_factoryfrom ._subscription_context import SubscriptionInstantiationContextfrom ._type_subscription import TypeSubscription@@ -16,7 +17,7 @@ class DefaultSubscription(TypeSubscription):agent_type (str, optional): The agent type to use for the subscription. Defaults to None, in which case it will attempt to detect the agent type based on the instantiation context."""- def __init__(self, topic_type: str = "default", agent_type: str | None = None):+ def __init__(self, topic_type: str = "default", agent_type: str | AgentType | None = None):if agent_type is None:try:agent_type = SubscriptionInstantiationContext.agent_type().typediff --git a/python/packages/autogen-core/src/autogen_core/_type_prefix_subscription.py b/python/packages/autogen-core/src/autogen_core/_type_prefix_subscription.pyindex 4c88f12a4..9e0d52683 100644--- a/python/packages/autogen-core/src/autogen_core/_type_prefix_subscription.py+++ b/python/packages/autogen-core/src/autogen_core/_type_prefix_subscription.py@@ -1,6 +1,7 @@import uuidfrom ._agent_id import AgentId+from ._agent_type import AgentTypefrom ._subscription import Subscriptionfrom ._topic import TopicIdfrom .exceptions import CantHandleException@@ -30,9 +31,12 @@ class TypePrefixSubscription(Subscription):agent_type (str): Agent type to handle this subscription"""- def __init__(self, topic_type_prefix: str, agent_type: str):+ def __init__(self, topic_type_prefix: str, agent_type: str | AgentType):self._topic_type_prefix = topic_type_prefix- self._agent_type = agent_type+ if isinstance(agent_type, AgentType):+ self._agent_type = agent_type.type+ else:+ self._agent_type = agent_typeself._id = str(uuid.uuid4())@propertydiff --git a/python/packages/autogen-core/src/autogen_core/_type_subscription.py b/python/packages/autogen-core/src/autogen_core/_type_subscription.pyindex 4ad815418..14d599b56 100644--- a/python/packages/autogen-core/src/autogen_core/_type_subscription.py+++ b/python/packages/autogen-core/src/autogen_core/_type_subscription.py@@ -1,6 +1,7 @@import uuidfrom ._agent_id import AgentId+from ._agent_type import AgentTypefrom ._subscription import Subscriptionfrom ._topic import TopicIdfrom .exceptions import CantHandleException@@ -29,9 +30,12 @@ class TypeSubscription(Subscription):agent_type (str): Agent type to handle this subscription"""- def __init__(self, topic_type: str, agent_type: str):+ def __init__(self, topic_type: str, agent_type: str | AgentType):self._topic_type = topic_type- self._agent_type = agent_type+ if isinstance(agent_type, AgentType):+ self._agent_type = agent_type.type+ else:+ self._agent_type = agent_typeself._id = str(uuid.uuid4())@property