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

fix add functions to agent(#4937) #5070

Open
wants to merge 2 commits into
base: 0.2
Choose a base branch
from
Open
Changes from 1 commit
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
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
Loading