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

Autogen tries to call non-existent functions that are the names of agents #781

Open
MikeBirdTech opened this issue Nov 27, 2023 · 7 comments
Labels
function/tool suggestion and execution of function/tool call group chat group-chat-related issues

Comments

@MikeBirdTech
Copy link

MikeBirdTech commented Nov 27, 2023

Autogen is trying to call functions that are the names of agents but don't exist.

No agent can execute the function document_writer

There's no function called document_writer but there's an agent called document_writer

Prompt:
"Who should read this paper: https://arxiv.org/abs/2308.08155"

Functions:

def exec_python(cell):
    ipython = get_ipython()
    result = ipython.run_cell(cell)
    log = str(result.result)
    if result.error_before_exec is not None:
        log += f"\n{result.error_before_exec}"
    if result.error_in_exec is not None:
        log += f"\n{result.error_in_exec}"
    return log


def exec_sh(script):
    return user_proxy.execute_code_blocks([("sh", script)])


# Register functions
user_proxy.register_function(
    function_map={
        "python": exec_python,
        "sh": exec_sh,
    }
)

Agents:

user_proxy = autogen.UserProxyAgent(
    name="User_proxy",
    human_input_mode="ALWAYS",
    max_consecutive_auto_reply=5,
    is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),
    code_execution_config={"work_dir": "coding"},
    llm_config=llm_config,
)

document_writer = autogen.AssistantAgent(
    name="document_writer",
    system_message=document_writer_message,
    llm_config=llm_config,
)

Logs:

***** Suggested function Call: python *****
Arguments: 
{
  "cell": "import requests\nfrom bs4 import BeautifulSoup\n\n# paper url\nurl = 'https://arxiv.org/abs/2308.08155'\n\n# send request\nresponse = requests.get(url)\n\n# create soup\nsoup = BeautifulSoup(response.text, 'html.parser')\n\n# find all 'blockquote' tags - the abstract is in the second one\nabstract = soup.find_all('blockquote')[1].text\n\nabstract"
}
*******************************************

--------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/<USER>/.../groupchat.py", line 136, in <module>
    user_proxy.initiate_chat(
  File "/opt/homebrew/anaconda3/envs/.../lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 531, in initiate_chat
    self.send(self.generate_init_message(**context), recipient, silent=silent)
  File "/opt/homebrew/anaconda3/envs/.../lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 334, in send
    recipient.receive(message, self, request_reply, silent)
  File "/opt/homebrew/anaconda3/envs/.../lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 462, in receive
    reply = self.generate_reply(messages=self.chat_messages[sender], sender=sender)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/envs/.../lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 781, in generate_reply
    final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"])
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/envs/.../lib/python3.11/site-packages/autogen/agentchat/groupchat.py", line 162, in run_chat
    speaker = groupchat.select_speaker(speaker, self)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/envs/.../lib/python3.11/site-packages/autogen/agentchat/groupchat.py", line 78, in select_speaker
    raise ValueError(
ValueError: No agent can execute the function document_writer. Please check the function_map of the agents.
@sonichi sonichi added function/tool suggestion and execution of function/tool call group chat group-chat-related issues labels Nov 27, 2023
@sonichi
Copy link
Contributor

sonichi commented Nov 28, 2023

@kevin666aa are you aware of this issue? There seem to be two problems:

  1. the function is registered in user_proxy but not found
  2. the error message is wrong.

@yiranwu0
Copy link
Collaborator

For 2. this is a mist print in groupchat. I will fix that.

                    raise ValueError(
                        f"No agent can execute the function {self.messages[-1]['name']}. " 
                        "Please check the function_map of the agents."
                    )
# should be self.messages[-1]["function_call"]["name"]

Still looking into the issues

@yiranwu0
Copy link
Collaborator

yiranwu0 commented Nov 28, 2023

@Arrendy I need to know a bit more about this run.
Can you print this after initialize groupchat:

for agent in groupchat.agents:
    print(agent.name, agent._function_map)

after running this code and getting the error?

print(groupchat.messages[-1])
for agent in groupchat.agents:
    print(agent.name, agent._function_map)
    if agent.can_execute_function(groupchat.messages[-1]["function_call"]["name"]):
        print(f'{agent.name} can execute this function', groupchat.messages[-1]["function_call"]["name"])

@yiranwu0 yiranwu0 mentioned this issue Dec 7, 2023
3 tasks
@stefan-beskow-aera
Copy link

I'm also getting this error when using a group chat with multiple agents. Is there anything I can provide that would help diagnose this problem?

@xyin-anl
Copy link

xyin-anl commented Jan 2, 2024

I am encountering the same issue here. The function is registered using llm_config but the function_map is empty and it returns that "No agent can execute the function ...". Let me know what I can provide to debug this issue.

@ekzhu
Copy link
Collaborator

ekzhu commented Jan 3, 2024

Registering in the llm_config only provides the agent with awareness of the function. To allow an agent to execute the function, you also need to manually add it to function_map. The latest version in the main branch also supports decorator syntax for doing this. See https://microsoft.github.io/autogen/docs/reference/agentchat/conversable_agent/#register_for_llm. Make sure you clone the repo for the latest code. The next release to Pypi should cover this functionality.

@thinkall
Copy link
Collaborator

@MikeBirdTech , have you tried with the latest version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
function/tool suggestion and execution of function/tool call group chat group-chat-related issues
Projects
None yet
Development

No branches or pull requests

7 participants