From dd9c3b03b02c994ef34a21169cfec3d307f536b2 Mon Sep 17 00:00:00 2001 From: kevin666aa Date: Thu, 7 Dec 2023 11:46:07 -0500 Subject: [PATCH 1/5] fix groupchat selection --- autogen/agentchat/groupchat.py | 19 +++++++++++++++++++ .../agentchat/test_function_call_groupchat.py | 14 +++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/autogen/agentchat/groupchat.py b/autogen/agentchat/groupchat.py index deaca3036f9..98f495ceb63 100644 --- a/autogen/agentchat/groupchat.py +++ b/autogen/agentchat/groupchat.py @@ -217,6 +217,20 @@ def _mentioned_agents(self, message_content: Union[str, List], agents: List[Agen Returns: Dict: a counter for mentioned agents. """ + # This handles the case when the selector gives a wrong response of making function calls + # take out content, function_calls, tool_calls to put in one string + if isinstance(message_content, dict): + tmp_content = "" + if message_content.get("content"): + tmp_content = message_content["content"] + if message_content.get("function_call"): + tmp_content += message_content["function_call"]["name"] + message_content["function_call"]["arguments"] + if message_content.get("tool_calls"): + for tool_call in message_content["tool_calls"]: + if tool_call.get("type") == "function": + tmp_content += tool_call["function"]["name"] + tool_call["function_call"]["arguments"] + message_content = content_str(message_content) # Cast message content to str + # Cast message content to str message_content = content_str(message_content) @@ -244,6 +258,11 @@ def __init__( system_message: Optional[Union[str, List]] = "Group chat manager.", **kwargs, ): + if kwargs.get("llm_config") and (kwargs["llm_config"].get("functions") or kwargs["llm_config"].get("tools")): + raise ValueError( + "GroupChatManager is not allowed to make function/tool calls. Please remove the 'functions' or 'tools' config in 'llm_config' you passed in." + ) + super().__init__( name=name, max_consecutive_auto_reply=max_consecutive_auto_reply, diff --git a/test/agentchat/test_function_call_groupchat.py b/test/agentchat/test_function_call_groupchat.py index 48414903562..f2a30d734a1 100644 --- a/test/agentchat/test_function_call_groupchat.py +++ b/test/agentchat/test_function_call_groupchat.py @@ -54,7 +54,19 @@ def get_random_number(): llm_config=llm_config, ) groupchat = autogen.GroupChat(agents=[user_proxy, coder], messages=[], max_round=7) - manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config) + + # pass in llm_config with functions + try: + manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config) + except ValueError as e: + print("ValueError is expected: ", e) + else: + raise ValueError("Should raise ValueError because of 'functions' passed to GroupChatManager.") + + # pass in llm_config without functions + llm_config_manager = llm_config.copy() + del llm_config_manager["functions"] + manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config_manager) user_proxy.initiate_chat(manager, message="Let's start the game!") From a136ba34a15ce45aac54257d4d1fb5065c3869dd Mon Sep 17 00:00:00 2001 From: kevin666aa Date: Thu, 7 Dec 2023 13:55:22 -0500 Subject: [PATCH 2/5] update --- autogen/agentchat/groupchat.py | 2 +- test/agentchat/test_function_call_groupchat.py | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/autogen/agentchat/groupchat.py b/autogen/agentchat/groupchat.py index 98f495ceb63..c58a0a78da9 100644 --- a/autogen/agentchat/groupchat.py +++ b/autogen/agentchat/groupchat.py @@ -229,7 +229,7 @@ def _mentioned_agents(self, message_content: Union[str, List], agents: List[Agen for tool_call in message_content["tool_calls"]: if tool_call.get("type") == "function": tmp_content += tool_call["function"]["name"] + tool_call["function_call"]["arguments"] - message_content = content_str(message_content) # Cast message content to str + message_content = tmp_content # Cast message content to str message_content = content_str(message_content) diff --git a/test/agentchat/test_function_call_groupchat.py b/test/agentchat/test_function_call_groupchat.py index f2a30d734a1..c36122d734f 100644 --- a/test/agentchat/test_function_call_groupchat.py +++ b/test/agentchat/test_function_call_groupchat.py @@ -56,12 +56,8 @@ def get_random_number(): groupchat = autogen.GroupChat(agents=[user_proxy, coder], messages=[], max_round=7) # pass in llm_config with functions - try: + with pytest.raises(ValueError, match="Should raise ValueError because of 'functions' passed to GroupChatManager"): manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config) - except ValueError as e: - print("ValueError is expected: ", e) - else: - raise ValueError("Should raise ValueError because of 'functions' passed to GroupChatManager.") # pass in llm_config without functions llm_config_manager = llm_config.copy() From 003f1940cce319cab07fa524ab2b23311a81c4f4 Mon Sep 17 00:00:00 2001 From: kevin666aa Date: Thu, 7 Dec 2023 23:43:21 -0500 Subject: [PATCH 3/5] update notbooks --- notebook/agentchat_groupchat_RAG.ipynb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/notebook/agentchat_groupchat_RAG.ipynb b/notebook/agentchat_groupchat_RAG.ipynb index 9355d8343d4..c68b3181950 100644 --- a/notebook/agentchat_groupchat_RAG.ipynb +++ b/notebook/agentchat_groupchat_RAG.ipynb @@ -292,7 +292,10 @@ " speaker_selection_method=\"random\",\n", " allow_repeat_speaker=False,\n", " )\n", - " manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)\n", + "\n", + " manager_llm_config = llm_config.copy()\n", + " manager_llm_config.pop(\"functions\")\n", + " manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=manager_llm_config)\n", "\n", " # Start chatting with the boss as this is the user proxy agent.\n", " boss.initiate_chat(\n", From c453552eaafdf7d6194262c88eebb1fe719f0085 Mon Sep 17 00:00:00 2001 From: kevin666aa Date: Sat, 9 Dec 2023 18:34:14 -0500 Subject: [PATCH 4/5] update --- test/agentchat/test_function_call_groupchat.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/agentchat/test_function_call_groupchat.py b/test/agentchat/test_function_call_groupchat.py index c36122d734f..d8fdf30d376 100644 --- a/test/agentchat/test_function_call_groupchat.py +++ b/test/agentchat/test_function_call_groupchat.py @@ -56,7 +56,10 @@ def get_random_number(): groupchat = autogen.GroupChat(agents=[user_proxy, coder], messages=[], max_round=7) # pass in llm_config with functions - with pytest.raises(ValueError, match="Should raise ValueError because of 'functions' passed to GroupChatManager"): + with pytest.raises( + ValueError, + match="GroupChatManager is not allowed to make function/tool calls. Please remove the 'functions' or 'tools' config in 'llm_config' you passed in.", + ): manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config) # pass in llm_config without functions From ab97630b4d72da31d46988885a284acc19e66bfa Mon Sep 17 00:00:00 2001 From: kevin666aa Date: Sat, 9 Dec 2023 19:06:55 -0500 Subject: [PATCH 5/5] update --- autogen/agentchat/groupchat.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/autogen/agentchat/groupchat.py b/autogen/agentchat/groupchat.py index 4a12a4ebf3c..c420d7b2204 100644 --- a/autogen/agentchat/groupchat.py +++ b/autogen/agentchat/groupchat.py @@ -259,20 +259,6 @@ def _mentioned_agents(self, message_content: Union[str, List], agents: List[Agen Returns: Dict: a counter for mentioned agents. """ - # This handles the case when the selector gives a wrong response of making function calls - # take out content, function_calls, tool_calls to put in one string - if isinstance(message_content, dict): - tmp_content = "" - if message_content.get("content"): - tmp_content = message_content["content"] - if message_content.get("function_call"): - tmp_content += message_content["function_call"]["name"] + message_content["function_call"]["arguments"] - if message_content.get("tool_calls"): - for tool_call in message_content["tool_calls"]: - if tool_call.get("type") == "function": - tmp_content += tool_call["function"]["name"] + tool_call["function_call"]["arguments"] - message_content = tmp_content - # Cast message content to str message_content = content_str(message_content)