Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise error when function as llm_config passed to GroupChatManager #911

Merged
merged 9 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions autogen/agentchat/groupchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
yiranwu0 marked this conversation as resolved.
Show resolved Hide resolved
yiranwu0 marked this conversation as resolved.
Show resolved Hide resolved
message_content = tmp_content

# Cast message content to str
message_content = content_str(message_content)

Expand Down Expand Up @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion test/agentchat/test_function_call_groupchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ 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
with pytest.raises(ValueError, match="Should raise ValueError because of 'functions' passed to GroupChatManager"):
manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)

# 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!")

Expand Down
Loading