From ff07d13e4ab68eb8b3bc245fa1af377dc28cae76 Mon Sep 17 00:00:00 2001 From: Mark Sze <66362098+marklysze@users.noreply.github.com> Date: Thu, 27 Feb 2025 11:18:02 +1100 Subject: [PATCH] Fix inits to take in name and system_message and allows non-keyword arguments (#1159) --- autogen/agents/experimental/discord/discord.py | 17 +++++++++-------- autogen/agents/experimental/slack/slack.py | 17 +++++++++-------- .../agents/experimental/telegram/telegram.py | 14 +++++++------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/autogen/agents/experimental/discord/discord.py b/autogen/agents/experimental/discord/discord.py index e92992f5cc..ff430a1d7d 100644 --- a/autogen/agents/experimental/discord/discord.py +++ b/autogen/agents/experimental/discord/discord.py @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: Apache-2.0 -from typing import Any +from typing import Any, Optional from .... import ConversableAgent from ....doc_utils import export_module @@ -23,6 +23,9 @@ class DiscordAgent(ConversableAgent): def __init__( self, + name: str, + system_message: Optional[str] = None, + *, bot_token: str, channel_name: str, guild_name: str, @@ -32,13 +35,14 @@ def __init__( """Initialize the DiscordAgent. Args: - llm_config (dict[str, Any]): The LLM configuration. + name (str): name of the agent. + system_message (str or list): system message for the ChatCompletion inference. bot_token (str): Discord bot token channel_name (str): Channel name where messages will be sent / retrieved guild_name (str): Guild (server) name where the channel is located has_writing_instructions (bool): Whether to add writing instructions to the system message. Defaults to True. """ - system_message = kwargs.pop("system_message", self.DEFAULT_SYSTEM_MESSAGE) + discord_system_message = system_message or self.DEFAULT_SYSTEM_MESSAGE self._send_tool = DiscordSendTool(bot_token=bot_token, channel_name=channel_name, guild_name=guild_name) self._retrieve_tool = DiscordRetrieveTool(bot_token=bot_token, channel_name=channel_name, guild_name=guild_name) @@ -53,12 +57,9 @@ def __init__( "4. Consider using appropriate emojis when suitable\n" ) - if isinstance(system_message, str): - system_message = system_message + formatting_instructions - elif isinstance(system_message, list): - system_message = system_message + [formatting_instructions] + discord_system_message = discord_system_message + formatting_instructions - super().__init__(system_message=system_message, **kwargs) + super().__init__(name=name, system_message=discord_system_message, **kwargs) self.register_for_llm()(self._send_tool) self.register_for_llm()(self._retrieve_tool) diff --git a/autogen/agents/experimental/slack/slack.py b/autogen/agents/experimental/slack/slack.py index 8b6fa7e457..adcb4ee88c 100644 --- a/autogen/agents/experimental/slack/slack.py +++ b/autogen/agents/experimental/slack/slack.py @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: Apache-2.0 -from typing import Any +from typing import Any, Optional from .... import ConversableAgent from ....doc_utils import export_module @@ -23,6 +23,9 @@ class SlackAgent(ConversableAgent): def __init__( self, + name: str, + system_message: Optional[str] = None, + *, bot_token: str, channel_id: str, has_writing_instructions: bool = True, @@ -31,12 +34,13 @@ def __init__( """Initialize the SlackAgent. Args: - llm_config (dict[str, Any]): The LLM configuration. + name (str): name of the agent. + system_message (str or list): system message for the ChatCompletion inference. bot_token (str): Bot User OAuth Token starting with "xoxb-". channel_id (str): Channel ID where messages will be sent. has_writing_instructions (bool): Whether to add writing instructions to the system message. Defaults to True. """ - system_message = kwargs.pop("system_message", self.DEFAULT_SYSTEM_MESSAGE) + slack_system_message = system_message or self.DEFAULT_SYSTEM_MESSAGE self._send_tool = SlackSendTool(bot_token=bot_token, channel_id=channel_id) self._retrieve_tool = SlackRetrieveTool(bot_token=bot_token, channel_id=channel_id) @@ -58,12 +62,9 @@ def __init__( "6. Can use or for notifications" ) - if isinstance(system_message, str): - system_message = system_message + formatting_instructions - elif isinstance(system_message, list): - system_message = system_message + [formatting_instructions] + slack_system_message = slack_system_message + formatting_instructions - super().__init__(system_message=system_message, **kwargs) + super().__init__(name=name, system_message=slack_system_message, **kwargs) self.register_for_llm()(self._send_tool) self.register_for_llm()(self._retrieve_tool) diff --git a/autogen/agents/experimental/telegram/telegram.py b/autogen/agents/experimental/telegram/telegram.py index a8aba68a0a..e62232a5a2 100644 --- a/autogen/agents/experimental/telegram/telegram.py +++ b/autogen/agents/experimental/telegram/telegram.py @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: Apache-2.0 -from typing import Any +from typing import Any, Optional from .... import ConversableAgent from ....doc_utils import export_module @@ -23,6 +23,9 @@ class TelegramAgent(ConversableAgent): def __init__( self, + name: str, + system_message: Optional[str] = None, + *, api_id: str, api_hash: str, chat_id: str, @@ -39,7 +42,7 @@ def __init__( has_writing_instructions (bool): Whether to add writing instructions to the system message. Defaults to True. """ - system_message = kwargs.pop("system_message", self.DEFAULT_SYSTEM_MESSAGE) + telegram_system_message = system_message or self.DEFAULT_SYSTEM_MESSAGE self._send_tool = TelegramSendTool(api_id=api_id, api_hash=api_hash, chat_id=chat_id) self._retrieve_tool = TelegramRetrieveTool(api_id=api_id, api_hash=api_hash, chat_id=chat_id) @@ -64,12 +67,9 @@ def __init__( "4. Supports @mentions and emoji" ) - if isinstance(system_message, str): - system_message = system_message + formatting_instructions - elif isinstance(system_message, list): - system_message = system_message + [formatting_instructions] + telegram_system_message = telegram_system_message + formatting_instructions - super().__init__(system_message=system_message, **kwargs) + super().__init__(name=name, system_message=telegram_system_message, **kwargs) self.register_for_llm()(self._send_tool) self.register_for_llm()(self._retrieve_tool)