A programming framework for agentic AI
Make ChatAgent an ABC (#5129)
Jack Gerrits226b37d07b9e
diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/base/_chat_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/base/_chat_agent.pyindex 256f752bf..36a80efe0 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/base/_chat_agent.py+++ b/python/packages/autogen-agentchat/src/autogen_agentchat/base/_chat_agent.py@@ -1,5 +1,6 @@+from abc import ABC, abstractmethodfrom dataclasses import dataclass-from typing import Any, AsyncGenerator, Mapping, Protocol, Sequence, runtime_checkable+from typing import Any, AsyncGenerator, Mapping, Sequencefrom autogen_core import CancellationToken@@ -19,17 +20,18 @@ class Response:or :class:`ChatMessage`."""-@runtime_checkable-class ChatAgent(TaskRunner, Protocol):+class ChatAgent(ABC, TaskRunner):"""Protocol for a chat agent."""@property+ @abstractmethoddef name(self) -> str:"""The name of the agent. This is used by team to uniquely identifythe agent. It should be unique within the team."""...@property+ @abstractmethoddef description(self) -> str:"""The description of the agent. This is used by team tomake decisions about which agents to use. The description should@@ -37,15 +39,18 @@ class ChatAgent(TaskRunner, Protocol):...@property+ @abstractmethoddef produced_message_types(self) -> Sequence[type[ChatMessage]]:"""The types of messages that the agent produces in the:attr:`Response.chat_message` field. They must be :class:`ChatMessage` types."""...+ @abstractmethodasync def on_messages(self, messages: Sequence[ChatMessage], cancellation_token: CancellationToken) -> Response:"""Handles incoming messages and returns a response."""...+ @abstractmethoddef on_messages_stream(self, messages: Sequence[ChatMessage], cancellation_token: CancellationToken) -> AsyncGenerator[AgentEvent | ChatMessage | Response, None]:@@ -53,18 +58,22 @@ class ChatAgent(TaskRunner, Protocol):and the final item is the response."""...+ @abstractmethodasync def on_reset(self, cancellation_token: CancellationToken) -> None:"""Resets the agent to its initialization state."""...+ @abstractmethodasync def save_state(self) -> Mapping[str, Any]:"""Save agent state for later restoration"""...+ @abstractmethodasync def load_state(self, state: Mapping[str, Any]) -> None:"""Restore agent from saved state"""...+ @abstractmethodasync def close(self) -> None:"""Called when the runtime is stopped or any stop method is called"""...