autogen icon indicating copy to clipboard operation
autogen copied to clipboard

ERROR: method .register_for_exectution has no attribute "name"

Open tyler-suard-parker opened this issue 1 year ago • 9 comments

Describe the bug

I am following the tutorial here: https://microsoft.github.io/autogen/docs/tutorial/tool-use At one point it says I can use the .register_for_execution function, using this syntax: user_proxy.register_for_execution(name="calculator")(calculator) However, when I run that code I get the error: AttributeError: 'method' object has no attribute '_name'

Why are the getting started tutorials not working?

Steps to reproduce

  1. Follow the instructions here: https://microsoft.github.io/autogen/docs/tutorial/tool-use
  2. Use this code:
from autogen import ConversableAgent

user_proxy = ConversableAgent(
    name="User",
    llm_config=False,
    is_termination_msg=lambda msg: msg.get("content") is not None and "TERMINATE" in msg["content"],
    human_input_mode="NEVER",
)

user_proxy.register_for_execution(name="calculator")(calculator)

### Model Used

_No response_

### Expected Behavior

The function should work like it does in the tutorial.

### Screenshots and logs

_No response_

### Additional Information

Autogen version 0.2.24, Windows

tyler-suard-parker avatar Apr 16 '24 05:04 tyler-suard-parker

Describe the bug

I am following the tutorial here: https://microsoft.github.io/autogen/docs/tutorial/tool-use At one point it says I can use the .register_for_execution function, using this syntax: user_proxy.register_for_execution(name="calculator")(calculator) However, when I run that code I get the error: AttributeError: 'method' object has no attribute '_name'

Why are the getting started tutorials not working?

Steps to reproduce

  1. Follow the instructions here: https://microsoft.github.io/autogen/docs/tutorial/tool-use
  2. Use this code:
from autogen import ConversableAgent

user_proxy = ConversableAgent(
    name="User",
    llm_config=False,
    is_termination_msg=lambda msg: msg.get("content") is not None and "TERMINATE" in msg["content"],
    human_input_mode="NEVER",
)

user_proxy.register_for_execution(name="calculator")(calculator)

### Model Used

_No response_

### Expected Behavior

The function should work like it does in the tutorial.

### Screenshots and logs

_No response_

### Additional Information

Autogen version 0.2.24, Windows

@tyler-suard-parker hope you defined an assistant: ConversableAgent Agent, if not please define the agent as mentioned in the tutorial. followed by: assistant.register_for_llm(name="calculator", description="A simple calculator")(calculator)

this should help with setting up the argument _name

Hk669 avatar Apr 16 '24 06:04 Hk669

Did you run the notebook from the first cell? You might have redefined some variables.

ekzhu avatar Apr 16 '24 15:04 ekzhu

similiar problem:

EXECUTING FUNCTION calculator... User (to Assistant): User (to Assistant): ***** Response from calling tool (call_5b8f9e81-5c9d-40cd-9386-3bb62dbba6a8) ***** Error: calculator() got an unexpected keyword argument 'name'

the utilized code was 1:1 copied from https://microsoft.github.io/autogen/docs/tutorial/tool-use

environment: local llama (2 and 3 tested) +autogen+litellm

WebSniper avatar Apr 28 '24 13:04 WebSniper

@tyler-suard-parker The exact code works for me:

from autogen import ConversableAgent

user_proxy = ConversableAgent(
    name="User",
    llm_config=False,
    is_termination_msg=lambda msg: msg.get("content") is not None and "TERMINATE" in msg["content"],
    human_input_mode="NEVER",
)

user_proxy.register_for_execution(name="calculator")(calculator)

@WebSniper Your error is different:

Error: calculator() got an unexpected keyword argument 'name'

from the OP's error:

AttributeError: 'method' object has no attribute '_name'

Your error is the LLM made a mistake in writing the parameters for the calculator tool.

ekzhu avatar Apr 30 '24 17:04 ekzhu

@ekzhu can you provide the versions of python and pyautogen.

ayhamakeed2000 avatar Jun 02 '24 18:06 ayhamakeed2000

I had the same issue and after some research I found that it's a bug in the package. the solution is to override the package and set the attribute '__func__' before accessing the '_name' attribute I made this solution and worked for me.

The solution inspired by this answer on Stackoverflow:

https://stackoverflow.com/questions/55617568/dynamically-changing-a-function-name-throws-attributeerror-method-object#:~:text=def%20__get_global_handler(self%2C%20name)%3A%0A%20%20%20%20handler%20%3D%20self.global_handler%0A%20%20%20%20handler.func.name%20%3D%20name%20%23%20Change%20the%20method%27s%20name%0A%20%20%20%20handler.func.qualname%20%3D%20__class.qualname%20%2B%20%27.%27%20%2B%20name%0A%20%20%20%20return%20handler

ayhamakeed2000 avatar Jun 02 '24 19:06 ayhamakeed2000

I had this issue but it was because I was passing method of a class to the "register_for_execution" decorator. See the below code for my case: self.rule_user_proxy.register_for_execution(name="relevant_rule_finder")(self.find_relevant_rules)

The issue was resolved as soon as I move the find_relevant_rules outside the class definition. In fact, the function has the _name attribute, but a method does not have. that is why you are getting that problem.

redfox-codder avatar Jun 07 '24 03:06 redfox-codder