microsoft / autogen

A programming framework for agentic AI. Discord: https://aka.ms/autogen-dc. Roadmap: https://aka.ms/autogen-roadmap
https://microsoft.github.io/autogen/
Creative Commons Attribution 4.0 International
29.87k stars 4.35k forks source link

[Bug]: AttributeError: 'NoneType' object has no attribute 'strip' for GPTAssistantAgent based on existing OpenAI Assistant #3095

Open antonioalegria opened 1 month ago

antonioalegria commented 1 month ago

Describe the bug

When using GPTAssistantAgent for a previously created OpenAI assistant, without passing any instructions, description of system_message, the following error is thrown when initializing the chat:

--------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/username/Developer/projectname/src/projectname/appv2.py", line 263, in <module>
    main()
  File "/Users/username/Developer/projectname/src/projectname/appv2.py", line 259, in main
    result = user_proxy.initiate_chat(group_chat_manager, message=message)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/username/Developer/projectname/.venv/lib/python3.12/site-packages/autogen/agentchat/conversable_agent.py", line 1018, in initiate_chat
    self.send(msg2send, recipient, silent=silent)
  File "/Users/username/Developer/projectname/.venv/lib/python3.12/site-packages/autogen/agentchat/conversable_agent.py", line 655, in send
    recipient.receive(message, self, request_reply, silent)
  File "/Users/username/Developer/projectname/.venv/lib/python3.12/site-packages/autogen/agentchat/conversable_agent.py", line 818, in receive
    reply = self.generate_reply(messages=self.chat_messages[sender], sender=sender)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/username/Developer/projectname/.venv/lib/python3.12/site-packages/autogen/agentchat/conversable_agent.py", line 1972, in generate_reply
    final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"])
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/username/Developer/projectname/.venv/lib/python3.12/site-packages/autogen/agentchat/groupchat.py", line 1047, in run_chat
    speaker = groupchat.select_speaker(speaker, self)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/username/Developer/projectname/.venv/lib/python3.12/site-packages/autogen/agentchat/groupchat.py", line 538, in select_speaker
    return self._auto_select_speaker(last_speaker, selector, messages, agents)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/username/Developer/projectname/.venv/lib/python3.12/site-packages/autogen/agentchat/groupchat.py", line 638, in _auto_select_speaker
    system_message=self.select_speaker_msg(agents),
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/username/Developer/projectname/.venv/lib/python3.12/site-packages/autogen/agentchat/groupchat.py", line 327, in select_speaker_msg
    roles = self._participant_roles(agents)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/username/Developer/projectname/.venv/lib/python3.12/site-packages/autogen/agentchat/groupchat.py", line 885, in _participant_roles
    if agent.description.strip() == "":
       ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'strip'

After debugging it seems the problem is that the instructions from the OpenAI Assistant are only fetched after initializing the description and system_message. When the instructions are fetched and set, the code doesn't check the description and system_message to fill them in with the instructions.

Steps to reproduce


agent1 = GPTAssistantAgent(
    name = "agent",
    llm_config = {
        "config_list": config_list,
    },
    assistant_config={
        "assistant_id": "asst_xxxx"
    }   
)

agent2 = GPTAssistantAgent(
    name = "agent2",
    llm_config = {
        "config_list": config_list,
    },
    assistant_config={
        "assistant_id": "asst_yyyy"
    }   
)

groupchat = autogen.GroupChat(agents=[agent1, agent2], messages=[], max_round=15)
group_chat_manager = autogen.GroupChatManager(groupchat=groupchat, llm_config={"config_list": config_list})
result = user_proxy.initiate_chat(group_chat_manager, message="What is the weather today?") # BOOM!

### Model Used

gpt-4o

### Expected Behavior

No exception thrown because the description would've been filled with the information coming from the OpenAI Assistant.

### Screenshots and logs

_No response_

### Additional Information

Python: 3.12.4
Autogen: 0.2.32
Operating System: macOS 14.5
antonioalegria commented 1 month ago

Workaround. Set the description field myself with the value of the OpenAI instructions:

agent1 = GPTAssistantAgent( name = "agent", llm_config = { "config_list": config_list, }, assistant_config={ "assistant_id": "asst_xxxx" }
) agent1.description = agent1._openai_assistant.instructions # <<< Added this

agent2 = GPTAssistantAgent( name = "agent2", llm_config = { "config_list": config_list, }, assistant_config={ "assistant_id": "asst_yyyy" }
) agent2.description = agent2._openai_assistant.instructions # <<< Added this

giriprasad51 commented 1 month ago

please give some instructions like this

" Create two agents with the required configurations" agent1 = GPTAssistantAgent( instructions = """ As 'weather reporter' your primary role is to information about weather """, name="agent", llm_config={ "config_list": config_list, }, assistant_config={

}

)

agent2 = GPTAssistantAgent( instructions = """ As 'weather reporter' your primary role is to information about weather """, name="agent2", llm_config={ "config_list": config_list, }, assistant_config={

}

)