Skip to content

Commit

Permalink
Fix inits to take in name and system_message and allows non-keyword a…
Browse files Browse the repository at this point in the history
…rguments (#1159)
  • Loading branch information
marklysze authored Feb 27, 2025
1 parent 83c12bb commit ff07d13
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
17 changes: 9 additions & 8 deletions autogen/agents/experimental/discord/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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)
17 changes: 9 additions & 8 deletions autogen/agents/experimental/slack/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -58,12 +62,9 @@ def __init__(
"6. Can use <!here> or <!channel> 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)
14 changes: 7 additions & 7 deletions autogen/agents/experimental/telegram/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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)

0 comments on commit ff07d13

Please sign in to comment.