diff --git a/autogen/agentchat/chat.py b/autogen/agentchat/chat.py index b527f8e0bae5..dd489c036254 100644 --- a/autogen/agentchat/chat.py +++ b/autogen/agentchat/chat.py @@ -195,7 +195,9 @@ def initiate_chats(chat_queue: List[Dict[str, Any]]) -> List[ChatResult]: r.summary for i, r in enumerate(finished_chats) if i not in finished_chat_indexes_to_exclude_from_carryover ] - __post_carryover_processing(chat_info) + if not chat_info.get("silent", False): + __post_carryover_processing(chat_info) + sender = chat_info["sender"] chat_res = sender.initiate_chat(**chat_info) finished_chats.append(chat_res) @@ -236,7 +238,10 @@ async def _dependent_chat_future( if isinstance(_chat_carryover, str): _chat_carryover = [_chat_carryover] chat_info["carryover"] = _chat_carryover + [finished_chats[pre_id].summary for pre_id in finished_chats] - __post_carryover_processing(chat_info) + + if not chat_info.get("silent", False): + __post_carryover_processing(chat_info) + sender = chat_info["sender"] chat_res_future = asyncio.create_task(sender.a_initiate_chat(**chat_info)) call_back_with_args = partial(_on_chat_future_done, chat_id=chat_id) diff --git a/autogen/agentchat/contrib/gpt_assistant_agent.py b/autogen/agentchat/contrib/gpt_assistant_agent.py index 0f5de8adcb5c..42056f4ca183 100644 --- a/autogen/agentchat/contrib/gpt_assistant_agent.py +++ b/autogen/agentchat/contrib/gpt_assistant_agent.py @@ -172,7 +172,7 @@ def __init__( # lazily create threads self._openai_threads = {} self._unread_index = defaultdict(int) - self.register_reply(Agent, GPTAssistantAgent._invoke_assistant, position=2) + self.register_reply([Agent, None], GPTAssistantAgent._invoke_assistant, position=2) def _invoke_assistant( self, diff --git a/autogen/agentchat/groupchat.py b/autogen/agentchat/groupchat.py index e9871a20b789..b81ef5fe4cf1 100644 --- a/autogen/agentchat/groupchat.py +++ b/autogen/agentchat/groupchat.py @@ -951,6 +951,7 @@ def __init__( max_consecutive_auto_reply: Optional[int] = sys.maxsize, human_input_mode: Optional[str] = "NEVER", system_message: Optional[Union[str, List]] = "Group chat manager.", + silent: bool = False, **kwargs, ): if ( @@ -974,6 +975,8 @@ def __init__( # Store groupchat self._groupchat = groupchat + self._silent = silent + # Order of register_reply is important. # Allow sync chat if initiated using initiate_chat self.register_reply(Agent, GroupChatManager.run_chat, config=groupchat, reset_config=GroupChat.reset) @@ -1026,6 +1029,7 @@ def run_chat( speaker = sender groupchat = config send_introductions = getattr(groupchat, "send_introductions", False) + silent = getattr(self, "_silent", False) if send_introductions: # Broadcast the intro @@ -1080,7 +1084,7 @@ def run_chat( reply["content"] = self.clear_agents_history(reply, groupchat) # The speaker sends the message without requesting a reply - speaker.send(reply, self, request_reply=False) + speaker.send(reply, self, request_reply=False, silent=silent) message = self.last_message(speaker) if self.client_cache is not None: for a in groupchat.agents: @@ -1101,6 +1105,7 @@ async def a_run_chat( speaker = sender groupchat = config send_introductions = getattr(groupchat, "send_introductions", False) + silent = getattr(self, "_silent", False) if send_introductions: # Broadcast the intro @@ -1145,7 +1150,7 @@ async def a_run_chat( if reply is None: break # The speaker sends the message without requesting a reply - await speaker.a_send(reply, self, request_reply=False) + await speaker.a_send(reply, self, request_reply=False, silent=silent) message = self.last_message(speaker) if self.client_cache is not None: for a in groupchat.agents: diff --git a/autogen/logger/file_logger.py b/autogen/logger/file_logger.py index f85784749586..466ed62c849d 100644 --- a/autogen/logger/file_logger.py +++ b/autogen/logger/file_logger.py @@ -17,6 +17,7 @@ if TYPE_CHECKING: from autogen import Agent, ConversableAgent, OpenAIWrapper + from autogen.oai.gemini import GeminiClient logger = logging.getLogger(__name__) @@ -177,7 +178,9 @@ def log_new_wrapper( except Exception as e: self.logger.error(f"[file_logger] Failed to log event {e}") - def log_new_client(self, client: AzureOpenAI | OpenAI, wrapper: OpenAIWrapper, init_args: Dict[str, Any]) -> None: + def log_new_client( + self, client: AzureOpenAI | OpenAI | GeminiClient, wrapper: OpenAIWrapper, init_args: Dict[str, Any] + ) -> None: """ Log a new client instance. """ diff --git a/autogen/logger/sqlite_logger.py b/autogen/logger/sqlite_logger.py index 6e95a571cd0e..42db83d849d5 100644 --- a/autogen/logger/sqlite_logger.py +++ b/autogen/logger/sqlite_logger.py @@ -18,6 +18,7 @@ if TYPE_CHECKING: from autogen import Agent, ConversableAgent, OpenAIWrapper + from autogen.oai.gemini import GeminiClient logger = logging.getLogger(__name__) lock = threading.Lock() @@ -316,7 +317,7 @@ def log_new_wrapper(self, wrapper: OpenAIWrapper, init_args: Dict[str, Union[LLM self._run_query(query=query, args=args) def log_new_client( - self, client: Union[AzureOpenAI, OpenAI], wrapper: OpenAIWrapper, init_args: Dict[str, Any] + self, client: Union[AzureOpenAI, OpenAI, GeminiClient], wrapper: OpenAIWrapper, init_args: Dict[str, Any] ) -> None: if self.con is None: return diff --git a/autogen/oai/client.py b/autogen/oai/client.py index 3edfa40d4ec0..982d1c0d57fb 100644 --- a/autogen/oai/client.py +++ b/autogen/oai/client.py @@ -435,7 +435,8 @@ def _register_default_client(self, config: Dict[str, Any], openai_config: Dict[s elif api_type is not None and api_type.startswith("google"): if gemini_import_exception: raise ImportError("Please install `google-generativeai` to use Google OpenAI API.") - self._clients.append(GeminiClient(**openai_config)) + client = GeminiClient(**openai_config) + self._clients.append(client) else: client = OpenAI(**openai_config) self._clients.append(OpenAIClient(client)) diff --git a/autogen/runtime_logging.py b/autogen/runtime_logging.py index d848ca3645e1..ffc741482e68 100644 --- a/autogen/runtime_logging.py +++ b/autogen/runtime_logging.py @@ -13,6 +13,7 @@ if TYPE_CHECKING: from autogen import Agent, ConversableAgent, OpenAIWrapper + from autogen.oai.gemini import GeminiClient logger = logging.getLogger(__name__) @@ -94,7 +95,9 @@ def log_new_wrapper(wrapper: OpenAIWrapper, init_args: Dict[str, Union[LLMConfig autogen_logger.log_new_wrapper(wrapper, init_args) -def log_new_client(client: Union[AzureOpenAI, OpenAI], wrapper: OpenAIWrapper, init_args: Dict[str, Any]) -> None: +def log_new_client( + client: Union[AzureOpenAI, OpenAI, GeminiClient], wrapper: OpenAIWrapper, init_args: Dict[str, Any] +) -> None: if autogen_logger is None: logger.error("[runtime logging] log_new_client: autogen logger is None") return diff --git a/test/agentchat/contrib/test_lmm.py b/test/agentchat/contrib/test_lmm.py index 3374f28b6a2a..3228d549548a 100755 --- a/test/agentchat/contrib/test_lmm.py +++ b/test/agentchat/contrib/test_lmm.py @@ -122,6 +122,7 @@ def test_group_chat_with_lmm(): system_message="Ask both image explainer 1 and 2 for their description.", human_input_mode="NEVER", # Options: 'ALWAYS' or 'NEVER' max_consecutive_auto_reply=max_consecutive_auto_reply, + code_execution_config=False, ) # Setting up the group chat