Skip to content

Commit

Permalink
refactor!: Remove deprecations (#4853)
Browse files Browse the repository at this point in the history
* Remove deprecations

* imports
  • Loading branch information
jackgerrits authored Dec 30, 2024
1 parent 5ee2190 commit 0b34211
Show file tree
Hide file tree
Showing 23 changed files with 3 additions and 1,542 deletions.
26 changes: 0 additions & 26 deletions python/packages/autogen-core/src/autogen_core/_agent_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from collections.abc import Sequence
from typing import Any, Awaitable, Callable, Mapping, Protocol, Type, TypeVar, overload, runtime_checkable

from typing_extensions import deprecated

from ._agent import Agent
from ._agent_id import AgentId
from ._agent_metadata import AgentMetadata
Expand Down Expand Up @@ -73,30 +71,6 @@ async def publish_message(
"""
...

@deprecated(
"Use your agent's `register` method directly instead of this method. See documentation for latest usage."
)
async def register(
self,
type: str,
agent_factory: Callable[[], T | Awaitable[T]],
subscriptions: Callable[[], list[Subscription] | Awaitable[list[Subscription]]]
| list[Subscription]
| None = None,
) -> AgentType:
"""Register an agent factory with the runtime associated with a specific type. The type must be unique.
.. deprecated:: 0.4.0.dev1
Use a specific agent's `register` method directly instead of this method. For example: :meth:`BaseAgent.register`
Args:
type (str): The type of agent this factory creates. It is not the same as agent class name. The `type` parameter is used to differentiate between different factory functions rather than agent classes.
agent_factory (Callable[[], T]): The factory that creates the agent, where T is a concrete Agent type. Inside the factory, use `autogen_core.AgentInstantiationContext` to access variables like the current runtime and agent ID.
subscriptions (Callable[[], list[Subscription]] | list[Subscription] | None, optional): The subscriptions that the agent should be subscribed to. Defaults to None.
"""
...

async def register_factory(
self,
*,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
from typing import Any, Awaitable, Callable, Dict, List, Mapping, ParamSpec, Set, Type, TypeVar, cast

from opentelemetry.trace import TracerProvider
from typing_extensions import deprecated

from autogen_core._serialization import MessageSerializer, SerializationRegistry

from ._agent import Agent
from ._agent_id import AgentId
Expand All @@ -27,8 +24,8 @@
from ._message_context import MessageContext
from ._message_handler_context import MessageHandlerContext
from ._runtime_impl_helpers import SubscriptionManager, get_impl
from ._serialization import MessageSerializer, SerializationRegistry
from ._subscription import Subscription
from ._subscription_context import SubscriptionInstantiationContext
from ._telemetry import EnvelopeMetadata, MessageRuntimeTracingConfig, TraceHelper, get_telemetry_envelope_metadata
from ._topic import TopicId
from .base.intervention import DropMessage, InterventionHandler
Expand Down Expand Up @@ -559,37 +556,6 @@ async def agent_save_state(self, agent: AgentId) -> Mapping[str, Any]:
async def agent_load_state(self, agent: AgentId, state: Mapping[str, Any]) -> None:
await (await self._get_agent(agent)).load_state(state)

@deprecated(
"Use your agent's `register` method directly instead of this method. See documentation for latest usage."
)
async def register(
self,
type: str,
agent_factory: Callable[[], T | Awaitable[T]] | Callable[[AgentRuntime, AgentId], T | Awaitable[T]],
subscriptions: Callable[[], list[Subscription] | Awaitable[list[Subscription]]]
| list[Subscription]
| None = None,
) -> AgentType:
if type in self._agent_factories:
raise ValueError(f"Agent with type {type} already exists.")

if subscriptions is not None:
if callable(subscriptions):
with SubscriptionInstantiationContext.populate_context(AgentType(type)):
subscriptions_list_result = subscriptions()
if inspect.isawaitable(subscriptions_list_result):
subscriptions_list = await subscriptions_list_result
else:
subscriptions_list = subscriptions_list_result
else:
subscriptions_list = subscriptions

for subscription in subscriptions_list:
await self.add_subscription(subscription)

self._agent_factories[type] = agent_factory
return AgentType(type)

async def register_factory(
self,
*,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from contextvars import ContextVar
from typing import Any, ClassVar, Generator

from autogen_core._agent_type import AgentType
from ._agent_type import AgentType


class SubscriptionInstantiationContext:
Expand Down
Empty file.

This file was deleted.

This file was deleted.

138 changes: 0 additions & 138 deletions python/packages/autogen-core/src/autogen_core/base/__init__.py
Original file line number Diff line number Diff line change
@@ -1,138 +0,0 @@
"""
The :mod:`autogen_core.base` module provides the foundational generic interfaces upon which all else is built. This module must not depend on any other module.
"""

from typing import Any, TypeVar

from typing_extensions import deprecated

from .._agent import Agent as AgentAlias
from .._agent_id import AgentId as AgentIdAlias
from .._agent_instantiation import AgentInstantiationContext as AgentInstantiationContextAlias
from .._agent_metadata import AgentMetadata as AgentMetadataAlias
from .._agent_proxy import AgentProxy as AgentProxyAlias
from .._agent_runtime import AgentRuntime as AgentRuntimeAlias
from .._agent_type import AgentType as AgentTypeAlias
from .._base_agent import BaseAgent as BaseAgentAlias
from .._cancellation_token import CancellationToken as CancellationTokenAlias
from .._message_context import MessageContext as MessageContextAlias
from .._message_handler_context import MessageHandlerContext as MessageHandlerContextAlias
from .._serialization import (
MessageSerializer as MessageSerializerAlias,
)
from .._serialization import (
UnknownPayload as UnknownPayloadAlias,
)
from .._serialization import (
try_get_known_serializers_for_type as try_get_known_serializers_for_type_alias,
)
from .._subscription import Subscription as SubscriptionAlias
from .._subscription_context import SubscriptionInstantiationContext as SubscriptionInstantiationContextAlias
from .._topic import TopicId as TopicIdAlias


@deprecated("autogen_core.base.Agent moved to autogen_core.Agent. This alias will be removed in 0.4.0.")
class Agent(AgentAlias):
pass


@deprecated("autogen_core.base.AgentId moved to autogen_core.AgentId. This alias will be removed in 0.4.0.")
class AgentId(AgentIdAlias):
pass


@deprecated(
"autogen_core.base.AgentInstantiationContext moved to autogen_core.AgentInstantiationContext. This alias will be removed in 0.4.0."
)
class AgentInstantiationContext(AgentInstantiationContextAlias):
pass


@deprecated("autogen_core.base.AgentMetadata moved to autogen_core.AgentMetadata. This alias will be removed in 0.4.0.")
class AgentMetadata(AgentMetadataAlias):
pass


@deprecated("autogen_core.base.AgentProxy moved to autogen_core.AgentProxy. This alias will be removed in 0.4.0.")
class AgentProxy(AgentProxyAlias):
pass


@deprecated("autogen_core.base.AgentRuntime moved to autogen_core.AgentRuntime. This alias will be removed in 0.4.0.")
class AgentRuntime(AgentRuntimeAlias):
pass


@deprecated("autogen_core.base.AgentType moved to autogen_core.AgentType. This alias will be removed in 0.4.0.")
class AgentType(AgentTypeAlias):
pass


@deprecated("autogen_core.base.BaseAgent moved to autogen_core.BaseAgent. This alias will be removed in 0.4.0.")
class BaseAgent(BaseAgentAlias):
pass


@deprecated(
"autogen_core.base.CancellationToken moved to autogen_core.CancellationToken. This alias will be removed in 0.4.0."
)
class CancellationToken(CancellationTokenAlias):
pass


@deprecated(
"autogen_core.base.MessageContext moved to autogen_core.MessageContext. This alias will be removed in 0.4.0."
)
class MessageContext(MessageContextAlias):
pass


@deprecated(
"autogen_core.base.MessageHandlerContext moved to autogen_core.MessageHandlerContext. This alias will be removed in 0.4.0."
)
class MessageHandlerContext(MessageHandlerContextAlias):
pass


@deprecated(
"autogen_core.base.UnknownPayloadAlias moved to autogen_core.UnknownPayloadAlias. This alias will be removed in 0.4.0."
)
class UnknownPayload(UnknownPayloadAlias):
pass


T = TypeVar("T")


@deprecated(
"autogen_core.base.MessageSerializer moved to autogen_core.MessageSerializer. This alias will be removed in 0.4.0."
)
class MessageSerializer(MessageSerializerAlias[T]):
pass


@deprecated("autogen_core.base.Subscription moved to autogen_core.Subscription. This alias will be removed in 0.4.0.")
class Subscription(SubscriptionAlias):
pass


@deprecated(
"autogen_core.base.try_get_known_serializers_for_type moved to autogen_core.try_get_known_serializers_for_type. This alias will be removed in 0.4.0."
)
def try_get_known_serializers_for_type(cls: type[Any]) -> list[MessageSerializerAlias[Any]]:
return try_get_known_serializers_for_type_alias(cls)


@deprecated(
"autogen_core.base.SubscriptionInstantiationContext moved to autogen_core.SubscriptionInstantiationContext. This alias will be removed in 0.4.0."
)
class SubscriptionInstantiationContext(SubscriptionInstantiationContextAlias):
pass


@deprecated("autogen_core.base.TopicId moved to autogen_core.TopicId. This alias will be removed in 0.4.0.")
class TopicId(TopicIdAlias):
pass


__all__ = [] # type: ignore
37 changes: 0 additions & 37 deletions python/packages/autogen-core/src/autogen_core/base/exceptions.py

This file was deleted.

Loading

0 comments on commit 0b34211

Please sign in to comment.