microsoft / autogen

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

[Bug]: 'NoneType' object is not iterable in a group_chat #3375

Open CLEILI opened 3 months ago

CLEILI commented 3 months ago

Describe the bug

When I use the group_chat and call some tools, this problem is raised. However, when I use just two agents to talk and call these tools, it won't raise this problem.

Steps to reproduce

File "......./groupchat_1.py", line 116, in group_chat a=user_proxy.initiate_chat(manager,message=message) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 1019, in initiate_chat self.send(msg2send, recipient, silent=silent) File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 656, in send recipient.receive(message, self, request_reply, silent) File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 819, in receive reply = self.generate_reply(messages=self.chat_messages[sender], sender=sender) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 1973, in generate_reply final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/autogen/agentchat/groupchat.py", line 1052, in run_chat reply = speaker.generate_reply(sender=self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 1973, in generate_reply final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 1341, in generate_oai_reply extracted_response = self._generate_oai_reply_from_client( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/autogen/agentchat/conversable_agent.py", line 1363, in _generate_oai_reply_from_client extracted_response = llm_client.extract_text_or_completion_object(response)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/autogen/oai/client.py", line 1023, in extract_text_or_completion_object return response.message_retrieval_function(response) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/autogen/oai/client.py", line 177, in message_retrieval return [ # type: ignore [return-value] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'NoneType' object is not iterable

Model Used

gpt-4o gpt-40-mini

Expected Behavior

No response

Screenshots and logs

No response

Additional Information

pyautogen:0.2.33 openai:1.16.2 python:3.11.5

CLEILI commented 3 months ago

And this situation appears after six successful tool calls

CLEILI commented 3 months ago
image

I found that the 'response' here return a None ChatCompletion when round to the third role in groupchat.

jonpsy commented 3 months ago

Can I take this up? Or is this restricted only for internal devs?

CLEILI commented 3 months ago

Can I take this up? Or is this restricted only for internal devs?

Yes, the code in the screenshot is from the official pyautogen library 0.2.33

marklysze commented 3 months ago

@CLEILI, would you be able to share any code to reproduce the error?

CLEILI commented 3 months ago

@CLEILI, would you be able to share any code to reproduce the error?

I am sorry that I cant show some real code to you now, but I located the bug at speaker_selection_method parameter in GroupChat, I changed it from auto, random to round_robin and the above problem did not occur again. So I guess the bug is related to the next_role_selection model.