From ea77d458aa4278599a191cb887208c6ecfdf84e7 Mon Sep 17 00:00:00 2001 From: davidxwwang Date: Thu, 16 Jan 2025 11:46:59 +0800 Subject: [PATCH 1/2] fix add functions to agent(#4937) --- autogen/agentchat/contrib/agent_builder.py | 42 +++++++++++----------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/autogen/agentchat/contrib/agent_builder.py b/autogen/agentchat/contrib/agent_builder.py index 7eaec3eef747..eba0b72c7942 100644 --- a/autogen/agentchat/contrib/agent_builder.py +++ b/autogen/agentchat/contrib/agent_builder.py @@ -182,7 +182,7 @@ class AgentBuilder: {agent_details} Hint: - # Only respond with the name of the agent that is most suited to execute the function and nothing else. + # Only respond with the name of the agent that is most suited to execute the function and nothing else.if there is no agent that is most suited to execute the function, respond with exectly"None" """ UPDATED_AGENT_SYSTEM_MESSAGE = """ @@ -730,7 +730,7 @@ def _build_agents( if list_of_functions: for func in list_of_functions: - resp = ( + perferred_agent_name = ( self.builder_model.create( messages=[ { @@ -747,28 +747,30 @@ def _build_agents( .choices[0] .message.content ) + if perferred_agent_name in self.agent_procs_assign.keys(): + autogen.agentchat.register_function( + func["function"], + caller=self.agent_procs_assign[perferred_agent_name][0], + executor=agent_list[0], + name=func["name"], + description=func["description"], + ) - autogen.agentchat.register_function( - func["function"], - caller=self.agent_procs_assign[resp][0], - executor=agent_list[0], - name=func["name"], - description=func["description"], - ) - - agents_current_system_message = [ - agent["system_message"] for agent in agent_configs if agent["name"] == resp - ][0] + agents_current_system_message = [ + agent["system_message"] for agent in agent_configs if agent["name"] == perferred_agent_name + ][0] - self.agent_procs_assign[resp][0].update_system_message( - self.UPDATED_AGENT_SYSTEM_MESSAGE.format( - agent_system_message=agents_current_system_message, - function_name=func["name"], - function_description=func["description"], + self.agent_procs_assign[perferred_agent_name][0].update_system_message( + self.UPDATED_AGENT_SYSTEM_MESSAGE.format( + agent_system_message=agents_current_system_message, + function_name=func["name"], + function_description=func["description"], + ) ) - ) - print(f"Function {func['name']} is registered to agent {resp}.") + print(f"Function {func['name']} is registered to agent {perferred_agent_name}.") + else: + logger.debug(f"Function {func['name']} is not registered to any agent.") return agent_list, self.cached_configs.copy() From db106b4a00be668168849cccb6dff07ef6eacd7b Mon Sep 17 00:00:00 2001 From: davidxwwang Date: Mon, 20 Jan 2025 11:38:26 +0800 Subject: [PATCH 2/2] fix spelling error in agent_builder.py --- autogen/agentchat/contrib/agent_builder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autogen/agentchat/contrib/agent_builder.py b/autogen/agentchat/contrib/agent_builder.py index eba0b72c7942..406f718ea4c5 100644 --- a/autogen/agentchat/contrib/agent_builder.py +++ b/autogen/agentchat/contrib/agent_builder.py @@ -182,7 +182,7 @@ class AgentBuilder: {agent_details} Hint: - # Only respond with the name of the agent that is most suited to execute the function and nothing else.if there is no agent that is most suited to execute the function, respond with exectly"None" + # Only respond with the name of the agent that is most suited to execute the function and nothing else.if there is no agent that is most suited to execute the function, respond with exactly "None" """ UPDATED_AGENT_SYSTEM_MESSAGE = """