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
28.43k stars 4.16k forks source link

[.Net][Bug]: GroupChat #2624

Open xuzeyu91 opened 2 months ago

xuzeyu91 commented 2 months ago

Describe the bug

I often encounter issues when using group chats "Sequence contains no matching element"

Steps to reproduce

   var groupChat = new GroupChat(
       admin: admin,
       members: agentList.ToArray()
   );
   userProxyAgent.SendIntroduction("Our group chat is about to start", groupChat);

   groupChatManager = new GroupChatManager(groupChat);

   var conversationHistory = await userProxyAgent.InitiateChatAsync(
         receiver: groupChatManager,
         message: msg,
         maxRound: 30);

This is my code, I used 2 custom GPTAgents, a UserProxyAgent as my input, and an Admin's GPTAgent This error often occurs when starting a group chat: Sequence contains no matching element It seems to have happened earlier, and I'm not sure what logic is contained inside

Model Used

No response

Expected Behavior

No response

Screenshots and logs

No response

Additional Information

No response

xuzeyu91 commented 2 months ago

I am using the gpt-3.5-turbo-16k model

LittleLittleCloud commented 2 months ago

Sequence contains no matching element usually indicates that when generating the next speaker, admin agent fails to generate a name from one of group agents.

Can you share the complete example somewhere and I'm happy to take a look.

xuzeyu91 commented 2 months ago

https://github.com/xuzeyu91/EasyAgent/blob/main/src/EasyAgent/Pages/Chat/Chat.razor.cs This is my code, and this error often occurs. I am not sure if it is due to an error in my agent settings or some other reason, but it is not necessarily the case

LittleLittleCloud commented 2 months ago

https://github.com/xuzeyu91/EasyAgent/blob/main/src/EasyAgent/Pages/Chat/Chat.razor.cs This is my code, and this error often occurs. I am not sure if it is due to an error in my agent settings or some other reason, but it is not necessarily the case

Thanks, what’s the name of group chat agents, are their name in English or Chinese?

xuzeyu91 commented 2 months ago

The names are in Chinese, respectively 刘备 ,张飞 and 关羽

LittleLittleCloud commented 2 months ago

Maybe try gpt-4 in admin agent? For what I know gpt-3.5 doesn't process Chinese very well.

If you want to stick with gpt-3.5, another trick you can use is to fall back to user agent when admin agent fails to select an agent in the group chat using middleware.

Also, when creating group chat, you don't need to add admin to agentList https://github.com/xuzeyu91/EasyAgent/blob/6f3dd6410f9027ea892602d4d6af41c598299dbf/src/EasyAgent/Pages/Chat/Chat.razor.cs#L139

xuzeyu91 commented 2 months ago

another trick you can use is to fall back to user agent when admin agent fails to select an agent in the group chat using middleware.

How should this be operated? Is there an example, such as the minimum configuration being a user agent

LittleLittleCloud commented 2 months ago

@xuzeyu91 Here's an example, the idea is to use middlewhere to check the reply of an agent, if it's not one of from 张飞, from 关羽 or from 刘备, then return from UserName.

IAgent userAgent;

userAgent
   .RegisterMiddleware(async (messages, options, agent, ct) =>{
      var reply = await agent.GenerateResponse(messages, options, ct);
      var content = reply.GetContent();
      if (content is string text && (text == "from 张飞") || ..... )
      {
         // the next speaker is among the group, return the reply
         return reply; 
      }

      // otherwise, always fall back to user as next speaker
      return new TextMessage(Role.Assistant, "from User", from: agent.Name);
   });
xuzeyu91 commented 2 months ago

Thank you. Also, I would like to inquire that I did not use RoundRobinGroupChat but instead used GroupChat But I feel that they also take turns answering questions for each agent, rather than being truly random. Is this normal?

LittleLittleCloud commented 2 months ago

@xuzeyu91 GroupChat uses admin to dynamically select the next speaker from members. For every conversation round, GroupChat firstly invokes admin to select the next speaker, then invoke the next speaker to generate the next message.

xuzeyu91 commented 2 months ago

But I feel that there is a high probability that each agent will take turns speaking once,The probability of the same agent speaking continuously or a certain agent not speaking is very low

LittleLittleCloud commented 2 months ago

Would you mind sharing a chat conversation

xuzeyu91 commented 1 month ago

My chat is not particularly special. I created three agents and one user agent, and after the user agent initiated a question, the responses of other agents were relatively average. For example, as the boss, the three agents I created were finance, sales, and technology, and they basically followed the pattern of one sentence per person. I feel that LLM did not play a role in allocation in it

LittleLittleCloud commented 1 month ago

@xuzeyu91 One quick way to test out is to specify the name and next goto person.

For example

财务,告诉老板这个月工资发不出了, 然后给我把上个月的条子报了
xuzeyu91 commented 1 month ago

I tried it out, but if you specify a role or name, it's okay