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

add warning if duplicate function is registered #2159

Merged
merged 20 commits into from
May 22, 2024
Merged
Changes from 9 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
7 changes: 7 additions & 0 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2312,6 +2312,8 @@ def register_function(self, function_map: Dict[str, Union[Callable, None]]):
self._assert_valid_name(name)
if func is None and name not in self._function_map.keys():
warnings.warn(f"The function {name} to remove doesn't exist", name)
if name in self._function_map.keys():
jtoy marked this conversation as resolved.
Show resolved Hide resolved
warnings.warn(f"Function '{name}' is being overridden.", UserWarning)
self._function_map.update(function_map)
self._function_map = {k: v for k, v in self._function_map.items() if v is not None}

Expand Down Expand Up @@ -2348,6 +2350,9 @@ def update_function_signature(self, func_sig: Union[str, Dict], is_remove: None)

self._assert_valid_name(func_sig["name"])
if "functions" in self.llm_config.keys():
if any(func["name"] == func_sig["name"] for func in self.llm_config["functions"]):
warnings.warn(f"Function '{func_sig['name']}' is being overridden.", UserWarning)

self.llm_config["functions"] = [
func for func in self.llm_config["functions"] if func.get("name") != func_sig["name"]
] + [func_sig]
Expand Down Expand Up @@ -2387,6 +2392,8 @@ def update_tool_signature(self, tool_sig: Union[str, Dict], is_remove: None):
f"The tool signature must be of the type dict. Received tool signature type {type(tool_sig)}"
)
self._assert_valid_name(tool_sig["function"]["name"])
if any(tool["function"]["name"] == tool_sig["function"]["name"] for tool in self.llm_config["tools"]):
jtoy marked this conversation as resolved.
Show resolved Hide resolved
warnings.warn(f"Function '{tool_sig['function']['name']}' is being overridden.", UserWarning)
if "tools" in self.llm_config.keys():
jtoy marked this conversation as resolved.
Show resolved Hide resolved
self.llm_config["tools"] = [
tool
Expand Down