A programming framework for agentic AI
[Feature]: Add global silent param for ConversableAgent (#3244)
wenngong354dca80351f
diff --git a/autogen/agentchat/contrib/society_of_mind_agent.py b/autogen/agentchat/contrib/society_of_mind_agent.pyindex 2f6be5088..e76768187 100644--- a/autogen/agentchat/contrib/society_of_mind_agent.py+++ b/autogen/agentchat/contrib/society_of_mind_agent.py@@ -39,6 +39,7 @@ class SocietyOfMindAgent(ConversableAgent):code_execution_config: Union[Dict, Literal[False]] = False,llm_config: Optional[Union[Dict, Literal[False]]] = False,default_auto_reply: Optional[Union[str, Dict, None]] = "",+ **kwargs,):super().__init__(name=name,@@ -50,6 +51,7 @@ class SocietyOfMindAgent(ConversableAgent):code_execution_config=code_execution_config,llm_config=llm_config,default_auto_reply=default_auto_reply,+ **kwargs,)self.update_chat_manager(chat_manager)diff --git a/autogen/agentchat/contrib/web_surfer.py b/autogen/agentchat/contrib/web_surfer.pyindex af07be6d3..f74915a9b 100644--- a/autogen/agentchat/contrib/web_surfer.py+++ b/autogen/agentchat/contrib/web_surfer.py@@ -41,6 +41,7 @@ class WebSurferAgent(ConversableAgent):summarizer_llm_config: Optional[Union[Dict, Literal[False]]] = None,default_auto_reply: Optional[Union[str, Dict, None]] = "",browser_config: Optional[Union[Dict, None]] = None,+ **kwargs,):super().__init__(name=name,@@ -53,6 +54,7 @@ class WebSurferAgent(ConversableAgent):code_execution_config=code_execution_config,llm_config=llm_config,default_auto_reply=default_auto_reply,+ **kwargs,)self._create_summarizer_client(summarizer_llm_config, llm_config)diff --git a/autogen/agentchat/conversable_agent.py b/autogen/agentchat/conversable_agent.pyindex ca1a538e0..a088c4910 100644--- a/autogen/agentchat/conversable_agent.py+++ b/autogen/agentchat/conversable_agent.py@@ -78,6 +78,7 @@ class ConversableAgent(LLMAgent):default_auto_reply: Union[str, Dict] = "",description: Optional[str] = None,chat_messages: Optional[Dict[Agent, List[Dict]]] = None,+ silent: Optional[bool] = None,):"""Args:@@ -126,6 +127,8 @@ class ConversableAgent(LLMAgent):chat_messages (dict or None): the previous chat messages that this agent had in the past with other agents.Can be used to give the agent a memory by providing the chat history. This will allow the agent toresume previous had conversations. Defaults to an empty chat history.+ silent (bool or None): (Experimental) whether to print the message sent. If None, will use the value of+ silent in each function."""# we change code_execution_config below and we have to make sure we don't change the input# in case of UserProxyAgent, without this we could even change the default value {}@@ -147,6 +150,7 @@ class ConversableAgent(LLMAgent):if is_termination_msg is not Noneelse (lambda x: content_str(x.get("content")) == "TERMINATE"))+ self.silent = silent# Take a copy to avoid modifying the given dictif isinstance(llm_config, dict):try:@@ -263,6 +267,10 @@ class ConversableAgent(LLMAgent):)self.client = None if self.llm_config is False else OpenAIWrapper(**self.llm_config)+ @staticmethod+ def _is_silent(agent: Agent, silent: Optional[bool] = False) -> bool:+ return agent.silent if agent.silent is not None else silent+@propertydef name(self) -> str:"""Get the name of the agent."""@@ -606,7 +614,9 @@ class ConversableAgent(LLMAgent):"""Process the message before sending it to the recipient."""hook_list = self.hook_lists["process_message_before_send"]for hook in hook_list:- message = hook(sender=self, message=message, recipient=recipient, silent=silent)+ message = hook(+ sender=self, message=message, recipient=recipient, silent=ConversableAgent._is_silent(self, silent)+ )return messagedef send(@@ -648,7 +658,7 @@ class ConversableAgent(LLMAgent):Raises:ValueError: if the message can't be converted into a valid ChatCompletion message."""- message = self._process_message_before_send(message, recipient, silent)+ message = self._process_message_before_send(message, recipient, ConversableAgent._is_silent(self, silent))# When the agent composes and sends the message, the role of the message is "assistant"# unless it's "function".valid = self._append_oai_message(message, "assistant", recipient)@@ -698,7 +708,7 @@ class ConversableAgent(LLMAgent):Raises:ValueError: if the message can't be converted into a valid ChatCompletion message."""- message = self._process_message_before_send(message, recipient, silent)+ message = self._process_message_before_send(message, recipient, ConversableAgent._is_silent(self, silent))# When the agent composes and sends the message, the role of the message is "assistant"# unless it's "function".valid = self._append_oai_message(message, "assistant", recipient)@@ -780,7 +790,8 @@ class ConversableAgent(LLMAgent):raise ValueError("Received message can't be converted into a valid ChatCompletion message. Either content or function_call must be provided.")- if not silent:++ if not ConversableAgent._is_silent(sender, silent):self._print_received_message(message, sender)def receive(diff --git a/autogen/agentchat/user_proxy_agent.py b/autogen/agentchat/user_proxy_agent.pyindex a80296a83..d50e4d8b8 100644--- a/autogen/agentchat/user_proxy_agent.py+++ b/autogen/agentchat/user_proxy_agent.py@@ -35,6 +35,7 @@ class UserProxyAgent(ConversableAgent):llm_config: Optional[Union[Dict, Literal[False]]] = False,system_message: Optional[Union[str, List]] = "",description: Optional[str] = None,+ **kwargs,):"""Args:@@ -79,6 +80,8 @@ class UserProxyAgent(ConversableAgent):Only used when llm_config is not False. Use it to reprogram the agent.description (str): a short description of the agent. This description is used by other agents(e.g. the GroupChatManager) to decide when to call upon this agent. (Default: system_message)+ **kwargs (dict): Please refer to other kwargs in+ [ConversableAgent](conversable_agent#__init__)."""super().__init__(name=name,@@ -93,6 +96,7 @@ class UserProxyAgent(ConversableAgent):description=(description if description is not None else self.DEFAULT_USER_PROXY_AGENT_DESCRIPTIONS[human_input_mode]),+ **kwargs,)if logging_enabled():diff --git a/test/agentchat/test_tool_calls.py b/test/agentchat/test_tool_calls.pyindex 6a12d2d96..e7d45c591 100755--- a/test/agentchat/test_tool_calls.py+++ b/test/agentchat/test_tool_calls.py@@ -208,6 +208,7 @@ def test_multi_tool_call():def __init__(self, name):self._name = nameself.received = []+ self.silent = False@propertydef name(self):@@ -303,6 +304,7 @@ async def test_async_multi_tool_call():def __init__(self, name):self._name = nameself.received = []+ self.silent = False@propertydef name(self):