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

Support functions removing in ConversableAgent #1786

Merged
merged 7 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 additions & 3 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2129,15 +2129,18 @@ async def a_generate_init_message(self, **context) -> Union[str, Dict]:
self._process_carryover(context)
return context["message"]

def register_function(self, function_map: Dict[str, Callable]):
def register_function(self, function_map: Dict[str, Union[Callable, None]]):
"""Register functions to the agent.

Args:
function_map: a dictionary mapping function names to functions.
function_map: a dictionary mapping function names to functions. if function_map[name] is None, the function will be removed from the function_map.
"""
for name in function_map.keys():
for name, func in function_map.items():
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)
self._function_map.update(function_map)
self._function_map = {k: v for k, v in self._function_map.items() if v is not None}

def update_function_signature(self, func_sig: Union[str, Dict], is_remove: None):
"""update a function_signature in the LLM configuration for function_call.
Expand Down
10 changes: 10 additions & 0 deletions test/agentchat/test_conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,16 @@ def exec_sh(script: str) -> None:
assert agent.function_map["python"] == exec_python
assert agent.function_map["sh"] == exec_sh

# remove the functions
agent.register_function(
function_map={
"python": None,
}
)

assert set(agent.function_map.keys()) == {"sh"}
assert agent.function_map["sh"] == exec_sh


def test__wrap_function_sync():
CurrencySymbol = Literal["USD", "EUR"]
Expand Down
Loading