Skip to content

Commit

Permalink
fix add functions to agent(#4937)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidxwwang committed Jan 16, 2025
1 parent 37efa75 commit ea77d45
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions autogen/agentchat/contrib/agent_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand Down Expand Up @@ -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=[
{
Expand All @@ -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()

Expand Down

0 comments on commit ea77d45

Please sign in to comment.