microsoft / autogen

A programming framework for agentic AI 🤖
https://microsoft.github.io/autogen/
Creative Commons Attribution 4.0 International
30.96k stars 4.52k forks source link

ImportError: cannot import name 'AssistantAgent' from 'autogen' #705

Closed CzzzzzzJ closed 10 months ago

CzzzzzzJ commented 10 months ago

$ python test/twoagent.py Traceback (most recent call last): File "D:\workspace\luan\autogen\test\twoagent.py", line 1, in from autogen import AssistantAgent, UserProxyAgent, config_list_from_json ImportError: cannot import name 'AssistantAgent' from 'autogen' (C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\autogen__init__.py)

Yesterday it worked fine, but today it runs and shows this error.

afourney commented 10 months ago

This can happen if there is a file named autogen.py in your current folder. Can you confirm that you do not have any files or folders named autogen in the directory where you are working?

zepef commented 10 months ago

Same thing Bro:

teachable_agent = atg.TeachableAgent( name="teachableagent", llm_config=llm_config, teach_config={ "reset_db": False, # Use True to force-reset the memo DB, and False to use an existing DB. "path_to_db_dir": "./tmp/interactive/teachable_agent_db" # Can be any path. } )

user = atg.UserProxyAgent("user", human_input_mode="ALWAYS")

GIVES >>>

Traceback (most recent call last): File "f:\Trials\autoloc\app.py", line 17, in teachable_agent = atg.TeachableAgent( AttributeError: module 'autogen' has no attribute 'TeachableAgent'

zepef commented 10 months ago

Maybe a python version issue?

zepef commented 10 months ago

Uninstalling and reinstalling worked for me. I noticed I did not have to specifically mention [teachable] to have it installed.

rickyloynd-microsoft commented 10 months ago

Looks like this is resolved.

yhygta commented 9 months ago

Maybe you have installed "pip install autogen" NOT "pip install pyautogen"

hyp9h commented 9 months ago

I used 'pip install autogen' by mistake,uninstalling autogen and autopep8 worked for me

yaJannik commented 7 months ago

Was running into the same problem. Maybe highlight this in the installation documentation.

afourney commented 7 months ago

I believe I approved a documentation PR yesterday that adds this to the FAQ. Hopefully merged soon (if not already)

teachable-david commented 6 months ago

I uninstalled autogen and autopep8, and upgraded pyautogen, and the error became:

ImportError: cannot import name 'UserProxyAgent' from 'autogen' (unknown location)

teachable-david commented 6 months ago

copied the basic autogen script from this video by @tylerprogramming and am getting this error:

AttributeError: module 'autogen' has no attribute 'config_list_from_json'

tylerprogramming commented 6 months ago

copied the basic autogen script from this video by @tylerprogramming and am getting this error:

AttributeError: module 'autogen' has no attribute 'config_list_from_json'

Hey @teachable-david, I can try to help you! Thanks for watching the video, but I guess the first thing (if you haven't already) is to try to pip uninstall autogen, and then pip install pyautogen

I see you tried above from reading more comments, but since it can't find the library from what it seems, try the below two ways it may work:

If you have already tried that, I don't know exactly why this has worked for me, but remove the import, and then re-type it. Sometimes it then was able to find the library for use.

Also try a brand new project and pip install pyautogen, and see if the IDE recognizes autogen.config_list_from_json

Let me know and I can try to help more

teachable-david commented 6 months ago

Thanks for the reply @tylerprogramming! I followed the pip installation suggestions. I also installed Visual Studio since I'd been working in VS Code and I learned that doesn't allow project creation. I've started a new project in Visual Studio and copied the code into it from your video. I also followed the instructions in the terminal to add a folder location to my path/environment variables. But when I run the autogen script, I still see the error, "no module named autogen."

In this thread it's also suggested that pyautogen is the issue, but I have upgraded it and uninstalled autogen. I have had success with AutoGen in the past without using a Python environment, so I don't expect that to be the issue. However, since I'm currently stumped, I will probably create a venv and start the project again in it. I'll try anything else that you think might help. Thanks again!

Aqq-Ubemm commented 5 months ago

Maybe you have installed "pip install autogen" NOT "pip install pyautogen" i try this kind of method, its solved

WUHAN563 commented 3 months ago

Thanks for the reply @tylerprogramming! I followed the pip installation suggestions. I also installed Visual Studio since I'd been working in VS Code and I learned that doesn't allow project creation. I've started a new project in Visual Studio and copied the code into it from your video. I also followed the instructions in the terminal to add a folder location to my path/environment variables. But when I run the autogen script, I still see the error, "no module named autogen."

In this thread it's also suggested that pyautogen is the issue, but I have upgraded it and uninstalled autogen. I have had success with AutoGen in the past without using a Python environment, so I don't expect that to be the issue. However, since I'm currently stumped, I will probably create a venv and start the project again in it. I'll try anything else that you think might help. Thanks again!

Before creating a new environment, please clean cache for both conda and pip. conda clean --all pip cache purge

nise commented 3 months ago

Tried this in notebook:

!pip cache purge
!pip uninstall pyautogen -y
!pip uninstall autogen -y
!pip install pyautogen

from autogen import ConversableAgent, UserProxyAgent

def main():
    assistant = ConversableAgent("agent", llm_config={"config_list": config_list})
    user_proxy = UserProxyAgent("user", code_execution_config=False)
    assistant.initiate_chat(user_proxy, message="How can I help you today?")
if __name__ == "__main__":
    main()

It still results in: ImportError: cannot import name 'ConversableAgent' from 'autogen' (unknown location)

gops-sukumar commented 5 days ago

By doing all the above, I am able to import other agents like UserProxyAgent, but not TeachableAgent. What could be the issue?

tylerprogramming commented 5 days ago

@gops-sukumar Hey, so just checking and I don't see the TeachableAgent as part of the autogen code. That's why it cannot import it. It's been a while since I've used it, but it seems they either removed it completely.

I think they re-vamped it. Looking through, they have a 'teachability' in the contributions section. What this does, is create a teachable agent in the class, but REALLY it's just a 'conversableagent'. They modify how it behaves.

https://github.com/microsoft/autogen/blob/6c9d9d8cc3a2d394f699ac9436612d55ad4acf13/autogen/agentchat/contrib/capabilities/teachability.py#L58

Example: https://github.com/microsoft/autogen/blob/6c9d9d8cc3a2d394f699ac9436612d55ad4acf13/notebook/agentchat_teachable_oai_assistants.ipynb#L16